blob: 75aaabc861f5e8182a0ea1ffd62ec408f47c4ddf [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
162 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
163 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
Tomeu Vizoso36fc5792017-02-20 16:25:45 +0100164
165 /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
166 { "ETR", 13896, EDID_QUIRK_FORCE_8BPC },
Dave Airlieacb1d8e2017-10-16 05:26:19 +0100167
Andres Rodriguez30d62d42019-05-02 15:31:57 -0400168 /* Valve Index Headset */
169 { "VLV", 0x91a8, EDID_QUIRK_NON_DESKTOP },
170 { "VLV", 0x91b0, EDID_QUIRK_NON_DESKTOP },
171 { "VLV", 0x91b1, EDID_QUIRK_NON_DESKTOP },
172 { "VLV", 0x91b2, EDID_QUIRK_NON_DESKTOP },
173 { "VLV", 0x91b3, EDID_QUIRK_NON_DESKTOP },
174 { "VLV", 0x91b4, EDID_QUIRK_NON_DESKTOP },
175 { "VLV", 0x91b5, EDID_QUIRK_NON_DESKTOP },
176 { "VLV", 0x91b6, EDID_QUIRK_NON_DESKTOP },
177 { "VLV", 0x91b7, EDID_QUIRK_NON_DESKTOP },
178 { "VLV", 0x91b8, EDID_QUIRK_NON_DESKTOP },
179 { "VLV", 0x91b9, EDID_QUIRK_NON_DESKTOP },
180 { "VLV", 0x91ba, EDID_QUIRK_NON_DESKTOP },
181 { "VLV", 0x91bb, EDID_QUIRK_NON_DESKTOP },
182 { "VLV", 0x91bc, EDID_QUIRK_NON_DESKTOP },
183 { "VLV", 0x91bd, EDID_QUIRK_NON_DESKTOP },
184 { "VLV", 0x91be, EDID_QUIRK_NON_DESKTOP },
185 { "VLV", 0x91bf, EDID_QUIRK_NON_DESKTOP },
186
Lubosz Sarnecki69313172018-05-29 13:52:15 +0200187 /* HTC Vive and Vive Pro VR Headsets */
Dave Airlieacb1d8e2017-10-16 05:26:19 +0100188 { "HVR", 0xaa01, EDID_QUIRK_NON_DESKTOP },
Lubosz Sarnecki69313172018-05-29 13:52:15 +0200189 { "HVR", 0xaa02, EDID_QUIRK_NON_DESKTOP },
Philipp Zabelb3b12ea2018-02-19 18:59:36 +0100190
191 /* Oculus Rift DK1, DK2, and CV1 VR Headsets */
192 { "OVR", 0x0001, EDID_QUIRK_NON_DESKTOP },
193 { "OVR", 0x0003, EDID_QUIRK_NON_DESKTOP },
194 { "OVR", 0x0004, EDID_QUIRK_NON_DESKTOP },
Philipp Zabel90eda8f2018-02-19 18:59:37 +0100195
196 /* Windows Mixed Reality Headsets */
197 { "ACR", 0x7fce, EDID_QUIRK_NON_DESKTOP },
198 { "HPN", 0x3515, EDID_QUIRK_NON_DESKTOP },
199 { "LEN", 0x0408, EDID_QUIRK_NON_DESKTOP },
200 { "LEN", 0xb800, EDID_QUIRK_NON_DESKTOP },
201 { "FUJ", 0x1970, EDID_QUIRK_NON_DESKTOP },
202 { "DEL", 0x7fce, EDID_QUIRK_NON_DESKTOP },
203 { "SEC", 0x144a, EDID_QUIRK_NON_DESKTOP },
204 { "AUS", 0xc102, EDID_QUIRK_NON_DESKTOP },
Philipp Zabelccffc9e2018-02-19 18:59:38 +0100205
206 /* Sony PlayStation VR Headset */
207 { "SNY", 0x0704, EDID_QUIRK_NON_DESKTOP },
Ryan Pavlik29054232018-12-03 10:46:44 -0600208
209 /* Sensics VR Headsets */
210 { "SEN", 0x1019, EDID_QUIRK_NON_DESKTOP },
211
212 /* OSVR HDK and HDK2 VR Headsets */
213 { "SVR", 0x1019, EDID_QUIRK_NON_DESKTOP },
Dave Airlief453ba02008-11-07 14:05:41 -0800214};
215
Thierry Redinga6b21832012-11-23 15:01:42 +0100216/*
217 * Autogenerated from the DMT spec.
218 * This table is copied from xfree86/modes/xf86EdidModes.c.
219 */
220static const struct drm_display_mode drm_dmt_modes[] = {
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300221 /* 0x01 - 640x350@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100222 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
223 736, 832, 0, 350, 382, 385, 445, 0,
224 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300225 /* 0x02 - 640x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100226 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
227 736, 832, 0, 400, 401, 404, 445, 0,
228 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300229 /* 0x03 - 720x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100230 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
231 828, 936, 0, 400, 401, 404, 446, 0,
232 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300233 /* 0x04 - 640x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100234 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300235 752, 800, 0, 480, 490, 492, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100236 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300237 /* 0x05 - 640x480@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100238 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
239 704, 832, 0, 480, 489, 492, 520, 0,
240 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300241 /* 0x06 - 640x480@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100242 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
243 720, 840, 0, 480, 481, 484, 500, 0,
244 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300245 /* 0x07 - 640x480@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100246 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
247 752, 832, 0, 480, 481, 484, 509, 0,
248 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300249 /* 0x08 - 800x600@56Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100250 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
251 896, 1024, 0, 600, 601, 603, 625, 0,
252 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300253 /* 0x09 - 800x600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100254 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
255 968, 1056, 0, 600, 601, 605, 628, 0,
256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300257 /* 0x0a - 800x600@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100258 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
259 976, 1040, 0, 600, 637, 643, 666, 0,
260 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300261 /* 0x0b - 800x600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100262 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
263 896, 1056, 0, 600, 601, 604, 625, 0,
264 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300265 /* 0x0c - 800x600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100266 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
267 896, 1048, 0, 600, 601, 604, 631, 0,
268 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300269 /* 0x0d - 800x600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100270 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
271 880, 960, 0, 600, 603, 607, 636, 0,
272 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300273 /* 0x0e - 848x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100274 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
275 976, 1088, 0, 480, 486, 494, 517, 0,
276 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300277 /* 0x0f - 1024x768@43Hz, interlace */
Thierry Redinga6b21832012-11-23 15:01:42 +0100278 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
Paul Parsons735b1002016-04-04 20:36:34 +0100279 1208, 1264, 0, 768, 768, 776, 817, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100280 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300281 DRM_MODE_FLAG_INTERLACE) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300282 /* 0x10 - 1024x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100283 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
284 1184, 1344, 0, 768, 771, 777, 806, 0,
285 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300286 /* 0x11 - 1024x768@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100287 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
288 1184, 1328, 0, 768, 771, 777, 806, 0,
289 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300290 /* 0x12 - 1024x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100291 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
292 1136, 1312, 0, 768, 769, 772, 800, 0,
293 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300294 /* 0x13 - 1024x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100295 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
296 1168, 1376, 0, 768, 769, 772, 808, 0,
297 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300298 /* 0x14 - 1024x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100299 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
300 1104, 1184, 0, 768, 771, 775, 813, 0,
301 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300302 /* 0x15 - 1152x864@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100303 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
304 1344, 1600, 0, 864, 865, 868, 900, 0,
305 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300306 /* 0x55 - 1280x720@60Hz */
307 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
308 1430, 1650, 0, 720, 725, 730, 750, 0,
309 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300310 /* 0x16 - 1280x768@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100311 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
312 1360, 1440, 0, 768, 771, 778, 790, 0,
313 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300314 /* 0x17 - 1280x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100315 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
316 1472, 1664, 0, 768, 771, 778, 798, 0,
317 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300318 /* 0x18 - 1280x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100319 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
320 1488, 1696, 0, 768, 771, 778, 805, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300321 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300322 /* 0x19 - 1280x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100323 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
324 1496, 1712, 0, 768, 771, 778, 809, 0,
325 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300326 /* 0x1a - 1280x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100327 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
328 1360, 1440, 0, 768, 771, 778, 813, 0,
329 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300330 /* 0x1b - 1280x800@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100331 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
332 1360, 1440, 0, 800, 803, 809, 823, 0,
333 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300334 /* 0x1c - 1280x800@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100335 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
336 1480, 1680, 0, 800, 803, 809, 831, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300337 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300338 /* 0x1d - 1280x800@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100339 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
340 1488, 1696, 0, 800, 803, 809, 838, 0,
341 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300342 /* 0x1e - 1280x800@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100343 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
344 1496, 1712, 0, 800, 803, 809, 843, 0,
345 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300346 /* 0x1f - 1280x800@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100347 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
348 1360, 1440, 0, 800, 803, 809, 847, 0,
349 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300350 /* 0x20 - 1280x960@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100351 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
352 1488, 1800, 0, 960, 961, 964, 1000, 0,
353 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300354 /* 0x21 - 1280x960@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100355 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
356 1504, 1728, 0, 960, 961, 964, 1011, 0,
357 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300358 /* 0x22 - 1280x960@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100359 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
360 1360, 1440, 0, 960, 963, 967, 1017, 0,
361 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300362 /* 0x23 - 1280x1024@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100363 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
364 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
365 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300366 /* 0x24 - 1280x1024@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100367 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
368 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
369 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300370 /* 0x25 - 1280x1024@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100371 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
372 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
373 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300374 /* 0x26 - 1280x1024@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100375 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
376 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
377 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300378 /* 0x27 - 1360x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100379 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
380 1536, 1792, 0, 768, 771, 777, 795, 0,
381 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300382 /* 0x28 - 1360x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100383 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
384 1440, 1520, 0, 768, 771, 776, 813, 0,
385 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300386 /* 0x51 - 1366x768@60Hz */
387 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
388 1579, 1792, 0, 768, 771, 774, 798, 0,
389 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
390 /* 0x56 - 1366x768@60Hz */
391 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
392 1436, 1500, 0, 768, 769, 772, 800, 0,
393 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300394 /* 0x29 - 1400x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100395 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
396 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
397 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300398 /* 0x2a - 1400x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100399 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
400 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
401 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300402 /* 0x2b - 1400x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100403 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
404 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
405 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300406 /* 0x2c - 1400x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100407 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
408 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
409 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300410 /* 0x2d - 1400x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100411 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
412 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
413 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300414 /* 0x2e - 1440x900@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100415 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
416 1520, 1600, 0, 900, 903, 909, 926, 0,
417 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300418 /* 0x2f - 1440x900@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100419 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
420 1672, 1904, 0, 900, 903, 909, 934, 0,
421 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300422 /* 0x30 - 1440x900@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100423 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
424 1688, 1936, 0, 900, 903, 909, 942, 0,
425 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300426 /* 0x31 - 1440x900@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100427 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
428 1696, 1952, 0, 900, 903, 909, 948, 0,
429 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300430 /* 0x32 - 1440x900@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100431 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
432 1520, 1600, 0, 900, 903, 909, 953, 0,
433 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300434 /* 0x53 - 1600x900@60Hz */
435 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
436 1704, 1800, 0, 900, 901, 904, 1000, 0,
437 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300438 /* 0x33 - 1600x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100439 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
440 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
441 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300442 /* 0x34 - 1600x1200@65Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100443 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
444 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
445 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300446 /* 0x35 - 1600x1200@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100447 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
448 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
449 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300450 /* 0x36 - 1600x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100451 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
452 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
453 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300454 /* 0x37 - 1600x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100455 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
456 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
457 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300458 /* 0x38 - 1600x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100459 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
460 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
461 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300462 /* 0x39 - 1680x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100463 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
464 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
465 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300466 /* 0x3a - 1680x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100467 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
468 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
469 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300470 /* 0x3b - 1680x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100471 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
472 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
473 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300474 /* 0x3c - 1680x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100475 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
476 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
477 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300478 /* 0x3d - 1680x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100479 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
480 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
481 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300482 /* 0x3e - 1792x1344@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100483 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
484 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
485 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300486 /* 0x3f - 1792x1344@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100487 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
488 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
489 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300490 /* 0x40 - 1792x1344@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100491 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
492 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
493 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300494 /* 0x41 - 1856x1392@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100495 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
496 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
497 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300498 /* 0x42 - 1856x1392@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100499 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300500 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100501 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300502 /* 0x43 - 1856x1392@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100503 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
504 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
505 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300506 /* 0x52 - 1920x1080@60Hz */
507 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
508 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
509 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300510 /* 0x44 - 1920x1200@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100511 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
512 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
513 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300514 /* 0x45 - 1920x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100515 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
516 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
517 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300518 /* 0x46 - 1920x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100519 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
520 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
521 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300522 /* 0x47 - 1920x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100523 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
524 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
525 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300526 /* 0x48 - 1920x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100527 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
528 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
529 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300530 /* 0x49 - 1920x1440@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100531 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
532 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
533 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300534 /* 0x4a - 1920x1440@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100535 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
536 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
537 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300538 /* 0x4b - 1920x1440@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100539 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
540 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
541 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300542 /* 0x54 - 2048x1152@60Hz */
543 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
544 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
545 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300546 /* 0x4c - 2560x1600@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100547 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
548 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
549 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300550 /* 0x4d - 2560x1600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100551 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
552 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
553 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300554 /* 0x4e - 2560x1600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100555 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
556 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
557 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300558 /* 0x4f - 2560x1600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100559 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
560 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
561 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300562 /* 0x50 - 2560x1600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100563 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
564 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
565 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300566 /* 0x57 - 4096x2160@60Hz RB */
567 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
568 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
569 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
570 /* 0x58 - 4096x2160@59.94Hz RB */
571 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
572 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
573 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Thierry Redinga6b21832012-11-23 15:01:42 +0100574};
575
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300576/*
577 * These more or less come from the DMT spec. The 720x400 modes are
578 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
579 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
580 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
581 * mode.
582 *
583 * The DMT modes have been fact-checked; the rest are mild guesses.
584 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100585static const struct drm_display_mode edid_est_modes[] = {
586 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
587 968, 1056, 0, 600, 601, 605, 628, 0,
588 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
589 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
590 896, 1024, 0, 600, 601, 603, 625, 0,
591 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
592 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
593 720, 840, 0, 480, 481, 484, 500, 0,
594 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
595 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
Paul Parsons87707cf2016-04-02 11:08:06 +0100596 704, 832, 0, 480, 489, 492, 520, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100597 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
598 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
599 768, 864, 0, 480, 483, 486, 525, 0,
600 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100601 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Thierry Redinga6b21832012-11-23 15:01:42 +0100602 752, 800, 0, 480, 490, 492, 525, 0,
603 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
604 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
605 846, 900, 0, 400, 421, 423, 449, 0,
606 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
607 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
608 846, 900, 0, 400, 412, 414, 449, 0,
609 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
610 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
611 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
612 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100613 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
Thierry Redinga6b21832012-11-23 15:01:42 +0100614 1136, 1312, 0, 768, 769, 772, 800, 0,
615 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
616 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
617 1184, 1328, 0, 768, 771, 777, 806, 0,
618 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
619 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
620 1184, 1344, 0, 768, 771, 777, 806, 0,
621 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
622 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
623 1208, 1264, 0, 768, 768, 776, 817, 0,
624 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
625 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
626 928, 1152, 0, 624, 625, 628, 667, 0,
627 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
628 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
629 896, 1056, 0, 600, 601, 604, 625, 0,
630 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
631 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
632 976, 1040, 0, 600, 637, 643, 666, 0,
633 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
634 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
635 1344, 1600, 0, 864, 865, 868, 900, 0,
636 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
637};
638
639struct minimode {
640 short w;
641 short h;
642 short r;
643 short rb;
644};
645
646static const struct minimode est3_modes[] = {
647 /* byte 6 */
648 { 640, 350, 85, 0 },
649 { 640, 400, 85, 0 },
650 { 720, 400, 85, 0 },
651 { 640, 480, 85, 0 },
652 { 848, 480, 60, 0 },
653 { 800, 600, 85, 0 },
654 { 1024, 768, 85, 0 },
655 { 1152, 864, 75, 0 },
656 /* byte 7 */
657 { 1280, 768, 60, 1 },
658 { 1280, 768, 60, 0 },
659 { 1280, 768, 75, 0 },
660 { 1280, 768, 85, 0 },
661 { 1280, 960, 60, 0 },
662 { 1280, 960, 85, 0 },
663 { 1280, 1024, 60, 0 },
664 { 1280, 1024, 85, 0 },
665 /* byte 8 */
666 { 1360, 768, 60, 0 },
667 { 1440, 900, 60, 1 },
668 { 1440, 900, 60, 0 },
669 { 1440, 900, 75, 0 },
670 { 1440, 900, 85, 0 },
671 { 1400, 1050, 60, 1 },
672 { 1400, 1050, 60, 0 },
673 { 1400, 1050, 75, 0 },
674 /* byte 9 */
675 { 1400, 1050, 85, 0 },
676 { 1680, 1050, 60, 1 },
677 { 1680, 1050, 60, 0 },
678 { 1680, 1050, 75, 0 },
679 { 1680, 1050, 85, 0 },
680 { 1600, 1200, 60, 0 },
681 { 1600, 1200, 65, 0 },
682 { 1600, 1200, 70, 0 },
683 /* byte 10 */
684 { 1600, 1200, 75, 0 },
685 { 1600, 1200, 85, 0 },
686 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300687 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100688 { 1856, 1392, 60, 0 },
689 { 1856, 1392, 75, 0 },
690 { 1920, 1200, 60, 1 },
691 { 1920, 1200, 60, 0 },
692 /* byte 11 */
693 { 1920, 1200, 75, 0 },
694 { 1920, 1200, 85, 0 },
695 { 1920, 1440, 60, 0 },
696 { 1920, 1440, 75, 0 },
697};
698
699static const struct minimode extra_modes[] = {
700 { 1024, 576, 60, 0 },
701 { 1366, 768, 60, 0 },
702 { 1600, 900, 60, 0 },
703 { 1680, 945, 60, 0 },
704 { 1920, 1080, 60, 0 },
705 { 2048, 1152, 60, 0 },
706 { 2048, 1536, 60, 0 },
707};
708
709/*
710 * Probably taken from CEA-861 spec.
711 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
Jani Nikulad9278b42016-01-08 13:21:51 +0200712 *
713 * Index using the VIC.
Thierry Redinga6b21832012-11-23 15:01:42 +0100714 */
715static const struct drm_display_mode edid_cea_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +0200716 /* 0 - dummy, VICs start at 1 */
717 { },
Ville Syrjälä78691962018-05-24 22:20:35 +0300718 /* 1 - 640x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100719 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
720 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300721 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530722 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300723 /* 2 - 720x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100724 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
725 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300726 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530727 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300728 /* 3 - 720x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100729 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
730 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300731 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530732 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300733 /* 4 - 1280x720@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100734 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
735 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300736 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530737 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300738 /* 5 - 1920x1080i@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100739 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
740 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
741 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300742 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530743 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300744 /* 6 - 720(1440)x480i@60Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700745 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
746 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100747 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300748 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530749 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300750 /* 7 - 720(1440)x480i@60Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700751 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
752 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100753 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300754 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530755 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300756 /* 8 - 720(1440)x240@60Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700757 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
758 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100759 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300760 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530761 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300762 /* 9 - 720(1440)x240@60Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700763 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
764 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100765 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300766 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530767 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300768 /* 10 - 2880x480i@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100769 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
770 3204, 3432, 0, 480, 488, 494, 525, 0,
771 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300772 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530773 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300774 /* 11 - 2880x480i@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100775 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
776 3204, 3432, 0, 480, 488, 494, 525, 0,
777 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300778 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530779 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300780 /* 12 - 2880x240@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100781 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
782 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300783 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530784 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300785 /* 13 - 2880x240@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100786 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
787 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300788 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530789 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300790 /* 14 - 1440x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100791 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
792 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300793 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530794 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300795 /* 15 - 1440x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100796 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
797 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300798 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530799 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300800 /* 16 - 1920x1080@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100801 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
802 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300803 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530804 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300805 /* 17 - 720x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100806 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
807 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300808 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530809 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300810 /* 18 - 720x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100811 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
812 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300813 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530814 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300815 /* 19 - 1280x720@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100816 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
817 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300818 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530819 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300820 /* 20 - 1920x1080i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100821 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
822 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
823 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300824 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530825 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300826 /* 21 - 720(1440)x576i@50Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700827 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
828 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100829 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300830 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530831 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300832 /* 22 - 720(1440)x576i@50Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700833 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
834 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100835 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300836 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530837 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300838 /* 23 - 720(1440)x288@50Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700839 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
840 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100841 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300842 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530843 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300844 /* 24 - 720(1440)x288@50Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700845 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
846 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100847 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300848 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530849 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300850 /* 25 - 2880x576i@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100851 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
852 3180, 3456, 0, 576, 580, 586, 625, 0,
853 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300854 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530855 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300856 /* 26 - 2880x576i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100857 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
858 3180, 3456, 0, 576, 580, 586, 625, 0,
859 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300860 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530861 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300862 /* 27 - 2880x288@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100863 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
864 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300865 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530866 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300867 /* 28 - 2880x288@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100868 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
869 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300870 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530871 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300872 /* 29 - 1440x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100873 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
874 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300875 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530876 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300877 /* 30 - 1440x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100878 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
879 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300880 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530881 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300882 /* 31 - 1920x1080@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100883 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
884 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300885 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530886 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300887 /* 32 - 1920x1080@24Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100888 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
889 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300890 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530891 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300892 /* 33 - 1920x1080@25Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100893 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
894 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300895 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530896 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300897 /* 34 - 1920x1080@30Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100898 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
899 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300900 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530901 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300902 /* 35 - 2880x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100903 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
904 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300905 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530906 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300907 /* 36 - 2880x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100908 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
909 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300910 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530911 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300912 /* 37 - 2880x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100913 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
914 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300915 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530916 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300917 /* 38 - 2880x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100918 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
919 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300920 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530921 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300922 /* 39 - 1920x1080i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100923 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
924 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
925 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300926 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530927 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300928 /* 40 - 1920x1080i@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100929 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
930 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
931 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300932 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530933 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300934 /* 41 - 1280x720@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100935 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
936 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300937 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530938 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300939 /* 42 - 720x576@100Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100940 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
941 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300942 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530943 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300944 /* 43 - 720x576@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100945 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
946 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300947 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530948 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300949 /* 44 - 720(1440)x576i@100Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700950 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
951 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100952 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300953 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530954 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300955 /* 45 - 720(1440)x576i@100Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700956 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
957 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100958 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300959 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530960 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300961 /* 46 - 1920x1080i@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100962 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
963 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
964 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300965 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530966 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300967 /* 47 - 1280x720@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100968 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
969 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300970 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530971 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300972 /* 48 - 720x480@120Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100973 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
974 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300975 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530976 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300977 /* 49 - 720x480@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100978 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
979 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300980 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530981 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300982 /* 50 - 720(1440)x480i@120Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700983 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
984 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100985 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300986 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530987 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300988 /* 51 - 720(1440)x480i@120Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700989 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
990 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100991 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300992 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530993 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300994 /* 52 - 720x576@200Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100995 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
996 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300997 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530998 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300999 /* 53 - 720x576@200Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001000 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
1001 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001002 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301003 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001004 /* 54 - 720(1440)x576i@200Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001005 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1006 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001007 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001008 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301009 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001010 /* 55 - 720(1440)x576i@200Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001011 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1012 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001013 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001014 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301015 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001016 /* 56 - 720x480@240Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001017 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1018 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001019 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301020 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001021 /* 57 - 720x480@240Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001022 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1023 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001024 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301025 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001026 /* 58 - 720(1440)x480i@240Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001027 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1028 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001029 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001030 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301031 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001032 /* 59 - 720(1440)x480i@240Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001033 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1034 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001035 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001036 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301037 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001038 /* 60 - 1280x720@24Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001039 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1040 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001041 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301042 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001043 /* 61 - 1280x720@25Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001044 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1045 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001046 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301047 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001048 /* 62 - 1280x720@30Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001049 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1050 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001051 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301052 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001053 /* 63 - 1920x1080@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001054 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1055 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001056 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä78691962018-05-24 22:20:35 +03001057 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1058 /* 64 - 1920x1080@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001059 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -07001060 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001061 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä78691962018-05-24 22:20:35 +03001062 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1063 /* 65 - 1280x720@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301064 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1065 3080, 3300, 0, 720, 725, 730, 750, 0,
1066 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1067 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001068 /* 66 - 1280x720@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301069 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1070 3740, 3960, 0, 720, 725, 730, 750, 0,
1071 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1072 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001073 /* 67 - 1280x720@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301074 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1075 3080, 3300, 0, 720, 725, 730, 750, 0,
1076 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1077 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001078 /* 68 - 1280x720@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301079 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1080 1760, 1980, 0, 720, 725, 730, 750, 0,
1081 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1082 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001083 /* 69 - 1280x720@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301084 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1085 1430, 1650, 0, 720, 725, 730, 750, 0,
1086 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1087 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001088 /* 70 - 1280x720@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301089 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1090 1760, 1980, 0, 720, 725, 730, 750, 0,
1091 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1092 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001093 /* 71 - 1280x720@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301094 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1095 1430, 1650, 0, 720, 725, 730, 750, 0,
1096 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1097 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001098 /* 72 - 1920x1080@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301099 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1100 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1101 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1102 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001103 /* 73 - 1920x1080@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301104 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1105 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1106 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1107 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001108 /* 74 - 1920x1080@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301109 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1110 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1111 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1112 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001113 /* 75 - 1920x1080@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301114 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1115 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1116 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1117 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001118 /* 76 - 1920x1080@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301119 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1120 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1121 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1122 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001123 /* 77 - 1920x1080@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301124 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1125 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1126 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1127 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001128 /* 78 - 1920x1080@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301129 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1130 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1131 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1132 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001133 /* 79 - 1680x720@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301134 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1135 3080, 3300, 0, 720, 725, 730, 750, 0,
1136 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1137 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001138 /* 80 - 1680x720@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301139 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1140 2948, 3168, 0, 720, 725, 730, 750, 0,
1141 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1142 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001143 /* 81 - 1680x720@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301144 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1145 2420, 2640, 0, 720, 725, 730, 750, 0,
1146 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1147 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001148 /* 82 - 1680x720@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301149 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1150 1980, 2200, 0, 720, 725, 730, 750, 0,
1151 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1152 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001153 /* 83 - 1680x720@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301154 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1155 1980, 2200, 0, 720, 725, 730, 750, 0,
1156 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1157 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001158 /* 84 - 1680x720@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301159 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1160 1780, 2000, 0, 720, 725, 730, 825, 0,
1161 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1162 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001163 /* 85 - 1680x720@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301164 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1165 1780, 2000, 0, 720, 725, 730, 825, 0,
1166 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1167 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001168 /* 86 - 2560x1080@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301169 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1170 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1171 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1172 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001173 /* 87 - 2560x1080@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301174 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1175 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1176 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1177 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001178 /* 88 - 2560x1080@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301179 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1180 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1181 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1182 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001183 /* 89 - 2560x1080@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301184 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1185 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1186 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1187 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001188 /* 90 - 2560x1080@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301189 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1190 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1191 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1192 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001193 /* 91 - 2560x1080@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301194 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1195 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1196 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1197 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001198 /* 92 - 2560x1080@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301199 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1200 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1201 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1202 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001203 /* 93 - 3840x2160@24Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301204 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1205 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1206 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1207 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001208 /* 94 - 3840x2160@25Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301209 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1210 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1211 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1212 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001213 /* 95 - 3840x2160@30Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301214 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1215 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1216 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1217 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001218 /* 96 - 3840x2160@50Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301219 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1220 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1221 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1222 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001223 /* 97 - 3840x2160@60Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301224 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1225 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1226 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1227 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001228 /* 98 - 4096x2160@24Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301229 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1230 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1231 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1232 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001233 /* 99 - 4096x2160@25Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301234 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1235 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1236 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1237 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001238 /* 100 - 4096x2160@30Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301239 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1240 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1241 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1242 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001243 /* 101 - 4096x2160@50Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301244 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1245 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1246 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1247 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001248 /* 102 - 4096x2160@60Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301249 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1250 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1251 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1252 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001253 /* 103 - 3840x2160@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301254 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1255 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1257 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001258 /* 104 - 3840x2160@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301259 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1260 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1261 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1262 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001263 /* 105 - 3840x2160@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301264 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1265 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1266 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1267 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001268 /* 106 - 3840x2160@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301269 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1270 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1271 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1272 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001273 /* 107 - 3840x2160@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301274 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1275 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1276 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1277 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001278 /* 108 - 1280x720@48Hz 16:9 */
1279 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
1280 2280, 2500, 0, 720, 725, 730, 750, 0,
1281 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1282 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1283 /* 109 - 1280x720@48Hz 64:27 */
1284 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
1285 2280, 2500, 0, 720, 725, 730, 750, 0,
1286 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1287 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1288 /* 110 - 1680x720@48Hz 64:27 */
1289 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 2490,
1290 2530, 2750, 0, 720, 725, 730, 750, 0,
1291 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1292 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1293 /* 111 - 1920x1080@48Hz 16:9 */
1294 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
1295 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1296 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1297 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1298 /* 112 - 1920x1080@48Hz 64:27 */
1299 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
1300 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1301 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1302 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1303 /* 113 - 2560x1080@48Hz 64:27 */
1304 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 3558,
1305 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1306 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1307 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1308 /* 114 - 3840x2160@48Hz 16:9 */
1309 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
1310 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1311 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1312 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1313 /* 115 - 4096x2160@48Hz 256:135 */
1314 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5116,
1315 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1316 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1317 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1318 /* 116 - 3840x2160@48Hz 64:27 */
1319 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
1320 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1321 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1322 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1323 /* 117 - 3840x2160@100Hz 16:9 */
1324 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
1325 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1326 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1327 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1328 /* 118 - 3840x2160@120Hz 16:9 */
1329 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
1330 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1331 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1332 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1333 /* 119 - 3840x2160@100Hz 64:27 */
1334 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
1335 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1336 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1337 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1338 /* 120 - 3840x2160@120Hz 64:27 */
1339 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
1340 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1341 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1342 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1343 /* 121 - 5120x2160@24Hz 64:27 */
1344 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 7116,
1345 7204, 7500, 0, 2160, 2168, 2178, 2200, 0,
1346 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1347 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1348 /* 122 - 5120x2160@25Hz 64:27 */
1349 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 6816,
1350 6904, 7200, 0, 2160, 2168, 2178, 2200, 0,
1351 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1352 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1353 /* 123 - 5120x2160@30Hz 64:27 */
1354 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 5784,
1355 5872, 6000, 0, 2160, 2168, 2178, 2200, 0,
1356 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1357 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1358 /* 124 - 5120x2160@48Hz 64:27 */
1359 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5866,
1360 5954, 6250, 0, 2160, 2168, 2178, 2475, 0,
1361 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1362 .vrefresh = 48, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1363 /* 125 - 5120x2160@50Hz 64:27 */
1364 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 6216,
1365 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
1366 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1367 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1368 /* 126 - 5120x2160@60Hz 64:27 */
1369 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5284,
1370 5372, 5500, 0, 2160, 2168, 2178, 2250, 0,
1371 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1372 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1373 /* 127 - 5120x2160@100Hz 64:27 */
1374 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 1485000, 5120, 6216,
1375 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
1376 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1377 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001378};
1379
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001380/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001381 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001382 */
1383static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001384 /* 0 - dummy, VICs start at 1 */
1385 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001386 /* 1 - 3840x2160@30Hz */
1387 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1388 3840, 4016, 4104, 4400, 0,
1389 2160, 2168, 2178, 2250, 0,
1390 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1391 .vrefresh = 30, },
1392 /* 2 - 3840x2160@25Hz */
1393 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1394 3840, 4896, 4984, 5280, 0,
1395 2160, 2168, 2178, 2250, 0,
1396 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1397 .vrefresh = 25, },
1398 /* 3 - 3840x2160@24Hz */
1399 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1400 3840, 5116, 5204, 5500, 0,
1401 2160, 2168, 2178, 2250, 0,
1402 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1403 .vrefresh = 24, },
1404 /* 4 - 4096x2160@24Hz (SMPTE) */
1405 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1406 4096, 5116, 5204, 5500, 0,
1407 2160, 2168, 2178, 2250, 0,
1408 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1409 .vrefresh = 24, },
1410};
1411
Adam Jackson61e57a82010-03-29 21:43:18 +00001412/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001413
Adam Jackson083ae052009-09-23 17:30:45 -04001414static const u8 edid_header[] = {
1415 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1416};
Dave Airlief453ba02008-11-07 14:05:41 -08001417
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001418/**
1419 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1420 * @raw_edid: pointer to raw base EDID block
1421 *
1422 * Sanity check the header of the base EDID block.
1423 *
1424 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001425 */
1426int drm_edid_header_is_valid(const u8 *raw_edid)
1427{
1428 int i, score = 0;
1429
1430 for (i = 0; i < sizeof(edid_header); i++)
1431 if (raw_edid[i] == edid_header[i])
1432 score++;
1433
1434 return score;
1435}
1436EXPORT_SYMBOL(drm_edid_header_is_valid);
1437
Adam Jackson47819ba2012-05-30 16:42:39 -04001438static int edid_fixup __read_mostly = 6;
1439module_param_named(edid_fixup, edid_fixup, int, 0400);
1440MODULE_PARM_DESC(edid_fixup,
1441 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001442
Dave Airlie40d9b042014-10-20 16:29:33 +10001443static void drm_get_displayid(struct drm_connector *connector,
1444 struct edid *edid);
Andres Rodrigueze28ad542019-06-19 14:09:01 -04001445static int validate_displayid(u8 *displayid, int length, int idx);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001446
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001447static int drm_edid_block_checksum(const u8 *raw_edid)
1448{
1449 int i;
1450 u8 csum = 0;
1451 for (i = 0; i < EDID_LENGTH; i++)
1452 csum += raw_edid[i];
1453
1454 return csum;
1455}
1456
Stefan Brünsd6885d62014-11-30 19:57:41 +01001457static bool drm_edid_is_zero(const u8 *in_edid, int length)
1458{
1459 if (memchr_inv(in_edid, 0, length))
1460 return false;
1461
1462 return true;
1463}
1464
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001465/**
1466 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1467 * @raw_edid: pointer to raw EDID block
1468 * @block: type of block to validate (0 for base, extension otherwise)
1469 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001470 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001471 *
1472 * Validate a base or extension EDID block and optionally dump bad blocks to
1473 * the console.
1474 *
1475 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001476 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001477bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1478 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001479{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001480 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001481 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001482
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001483 if (WARN_ON(!raw_edid))
1484 return false;
1485
Adam Jackson47819ba2012-05-30 16:42:39 -04001486 if (edid_fixup > 8 || edid_fixup < 0)
1487 edid_fixup = 6;
1488
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001489 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001490 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001491 if (score == 8) {
1492 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001493 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001494 } else if (score >= edid_fixup) {
1495 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1496 * The corrupt flag needs to be set here otherwise, the
1497 * fix-up code here will correct the problem, the
1498 * checksum is correct and the test fails
1499 */
1500 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001501 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001502 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1503 memcpy(raw_edid, edid_header, sizeof(edid_header));
1504 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001505 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001506 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001507 goto bad;
1508 }
1509 }
Dave Airlief453ba02008-11-07 14:05:41 -08001510
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001511 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001512 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001513 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001514 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001515
Adam Jackson4a638b42010-05-25 16:33:09 -04001516 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001517 if (raw_edid[0] == CEA_EXT) {
1518 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1519 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1520 } else {
1521 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001522 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001523
Adam Jackson4a638b42010-05-25 16:33:09 -04001524 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001525 }
Dave Airlief453ba02008-11-07 14:05:41 -08001526 }
1527
Adam Jackson61e57a82010-03-29 21:43:18 +00001528 /* per-block-type checks */
1529 switch (raw_edid[0]) {
1530 case 0: /* base */
1531 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001532 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001533 goto bad;
1534 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001535
Adam Jackson61e57a82010-03-29 21:43:18 +00001536 if (edid->revision > 4)
1537 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1538 break;
1539
1540 default:
1541 break;
1542 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001543
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001544 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001545
1546bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001547 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001548 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001549 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001550 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001551 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001552 print_hex_dump(KERN_NOTICE,
1553 " \t", DUMP_PREFIX_NONE, 16, 1,
1554 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001555 }
Dave Airlief453ba02008-11-07 14:05:41 -08001556 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001557 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001558}
Carsten Emdeda0df922012-03-18 22:37:33 +01001559EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001560
1561/**
1562 * drm_edid_is_valid - sanity check EDID data
1563 * @edid: EDID data
1564 *
1565 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001566 *
1567 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001568 */
1569bool drm_edid_is_valid(struct edid *edid)
1570{
1571 int i;
1572 u8 *raw = (u8 *)edid;
1573
1574 if (!edid)
1575 return false;
1576
1577 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001578 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001579 return false;
1580
1581 return true;
1582}
Alex Deucher3c537882010-02-05 04:21:19 -05001583EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001584
Adam Jackson61e57a82010-03-29 21:43:18 +00001585#define DDC_SEGMENT_ADDR 0x30
1586/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001587 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001588 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001589 * @buf: EDID data buffer to be filled
1590 * @block: 128 byte EDID block to start fetching from
1591 * @len: EDID data buffer length to fetch
1592 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001593 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001594 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001595 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001596 */
1597static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001598drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001599{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001600 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001601 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001602 unsigned char segment = block >> 1;
1603 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001604 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001605
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001606 /*
1607 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001608 * adapter reports EAGAIN. However, we find that bit-banging transfers
1609 * are susceptible to errors under a heavily loaded machine and
1610 * generate spurious NAKs and timeouts. Retrying the transfer
1611 * of the individual block a few times seems to overcome this.
1612 */
1613 do {
1614 struct i2c_msg msgs[] = {
1615 {
Shirish Scd004b32012-08-30 07:04:06 +00001616 .addr = DDC_SEGMENT_ADDR,
1617 .flags = 0,
1618 .len = 1,
1619 .buf = &segment,
1620 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001621 .addr = DDC_ADDR,
1622 .flags = 0,
1623 .len = 1,
1624 .buf = &start,
1625 }, {
1626 .addr = DDC_ADDR,
1627 .flags = I2C_M_RD,
1628 .len = len,
1629 .buf = buf,
1630 }
1631 };
Shirish Scd004b32012-08-30 07:04:06 +00001632
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001633 /*
1634 * Avoid sending the segment addr to not upset non-compliant
1635 * DDC monitors.
1636 */
Shirish Scd004b32012-08-30 07:04:06 +00001637 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1638
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001639 if (ret == -ENXIO) {
1640 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1641 adapter->name);
1642 break;
1643 }
Shirish Scd004b32012-08-30 07:04:06 +00001644 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001645
Shirish Scd004b32012-08-30 07:04:06 +00001646 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001647}
1648
Chris Wilson14544d02016-10-24 12:38:21 +01001649static void connector_bad_edid(struct drm_connector *connector,
1650 u8 *edid, int num_blocks)
1651{
1652 int i;
1653
Jani Nikulaf0a8f532019-10-01 17:06:14 +03001654 if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS))
Chris Wilson14544d02016-10-24 12:38:21 +01001655 return;
1656
1657 dev_warn(connector->dev->dev,
1658 "%s: EDID is invalid:\n",
1659 connector->name);
1660 for (i = 0; i < num_blocks; i++) {
1661 u8 *block = edid + i * EDID_LENGTH;
1662 char prefix[20];
1663
1664 if (drm_edid_is_zero(block, EDID_LENGTH))
1665 sprintf(prefix, "\t[%02x] ZERO ", i);
1666 else if (!drm_edid_block_valid(block, i, false, NULL))
1667 sprintf(prefix, "\t[%02x] BAD ", i);
1668 else
1669 sprintf(prefix, "\t[%02x] GOOD ", i);
1670
1671 print_hex_dump(KERN_WARNING,
1672 prefix, DUMP_PREFIX_NONE, 16, 1,
1673 block, EDID_LENGTH, false);
1674 }
1675}
1676
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001677/* Get override or firmware EDID */
1678static struct edid *drm_get_override_edid(struct drm_connector *connector)
1679{
1680 struct edid *override = NULL;
1681
1682 if (connector->override_edid)
1683 override = drm_edid_duplicate(connector->edid_blob_ptr->data);
1684
1685 if (!override)
1686 override = drm_load_edid_firmware(connector);
1687
1688 return IS_ERR(override) ? NULL : override;
1689}
1690
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001691/**
Jani Nikula48eaeb72019-06-10 12:30:54 +03001692 * drm_add_override_edid_modes - add modes from override/firmware EDID
1693 * @connector: connector we're probing
1694 *
1695 * Add modes from the override/firmware EDID, if available. Only to be used from
1696 * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe
1697 * failed during drm_get_edid() and caused the override/firmware EDID to be
1698 * skipped.
1699 *
1700 * Return: The number of modes added or 0 if we couldn't find any.
1701 */
1702int drm_add_override_edid_modes(struct drm_connector *connector)
1703{
1704 struct edid *override;
1705 int num_modes = 0;
1706
1707 override = drm_get_override_edid(connector);
1708 if (override) {
1709 drm_connector_update_edid_property(connector, override);
1710 num_modes = drm_add_edid_modes(connector, override);
1711 kfree(override);
1712
1713 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] adding %d modes via fallback override/firmware EDID\n",
1714 connector->base.id, connector->name, num_modes);
1715 }
1716
1717 return num_modes;
1718}
1719EXPORT_SYMBOL(drm_add_override_edid_modes);
1720
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001721/**
1722 * drm_do_get_edid - get EDID data using a custom EDID block read function
1723 * @connector: connector we're probing
1724 * @get_edid_block: EDID block read function
1725 * @data: private data passed to the block read function
1726 *
1727 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1728 * exposes a different interface to read EDID blocks this function can be used
1729 * to get EDID data using a custom block read function.
1730 *
1731 * As in the general case the DDC bus is accessible by the kernel at the I2C
1732 * level, drivers must make all reasonable efforts to expose it as an I2C
1733 * adapter and use drm_get_edid() instead of abusing this function.
1734 *
Jani Nikula53fd40a2017-09-12 11:19:26 +03001735 * The EDID may be overridden using debugfs override_edid or firmare EDID
1736 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1737 * order. Having either of them bypasses actual EDID reads.
1738 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001739 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1740 */
1741struct edid *drm_do_get_edid(struct drm_connector *connector,
1742 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1743 size_t len),
1744 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001745{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001746 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001747 u8 *edid, *new;
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001748 struct edid *override;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001749
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001750 override = drm_get_override_edid(connector);
1751 if (override)
Jani Nikula53fd40a2017-09-12 11:19:26 +03001752 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001753
Chris Wilsonf14f3682016-10-17 09:35:12 +01001754 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001755 return NULL;
1756
1757 /* base block fetch */
1758 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001759 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001760 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001761 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001762 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001763 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001764 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001765 connector->null_edid_counter++;
1766 goto carp;
1767 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001768 }
1769 if (i == 4)
1770 goto carp;
1771
1772 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001773 valid_extensions = edid[0x7e];
1774 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001775 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001776
Chris Wilson14544d02016-10-24 12:38:21 +01001777 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001778 if (!new)
1779 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001780 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001781
Chris Wilsonf14f3682016-10-17 09:35:12 +01001782 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001783 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001784
Adam Jackson61e57a82010-03-29 21:43:18 +00001785 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001786 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001787 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001788 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001789 break;
1790 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001791
Chris Wilson14544d02016-10-24 12:38:21 +01001792 if (i == 4)
1793 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001794 }
1795
Chris Wilsonf14f3682016-10-17 09:35:12 +01001796 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001797 u8 *base;
1798
1799 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1800
Chris Wilsonf14f3682016-10-17 09:35:12 +01001801 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1802 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001803
Kees Cook6da2ec52018-06-12 13:55:00 -07001804 new = kmalloc_array(valid_extensions + 1, EDID_LENGTH,
1805 GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001806 if (!new)
1807 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001808
1809 base = new;
1810 for (i = 0; i <= edid[0x7e]; i++) {
1811 u8 *block = edid + i * EDID_LENGTH;
1812
1813 if (!drm_edid_block_valid(block, i, false, NULL))
1814 continue;
1815
1816 memcpy(base, block, EDID_LENGTH);
1817 base += EDID_LENGTH;
1818 }
1819
1820 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001821 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001822 }
1823
Chris Wilsonf14f3682016-10-17 09:35:12 +01001824 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001825
1826carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001827 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001828out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001829 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001830 return NULL;
1831}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001832EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001833
1834/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001835 * drm_probe_ddc() - probe DDC presence
1836 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001837 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001838 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001839 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001840bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001841drm_probe_ddc(struct i2c_adapter *adapter)
1842{
1843 unsigned char out;
1844
1845 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1846}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001847EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001848
1849/**
1850 * drm_get_edid - get EDID data, if available
1851 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001852 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001853 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001854 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001855 * attach it to the connector.
1856 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001857 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001858 */
1859struct edid *drm_get_edid(struct drm_connector *connector,
1860 struct i2c_adapter *adapter)
1861{
Dave Airlie40d9b042014-10-20 16:29:33 +10001862 struct edid *edid;
1863
Jani Nikula15f080f2017-02-17 17:20:53 +02001864 if (connector->force == DRM_FORCE_OFF)
1865 return NULL;
1866
1867 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001868 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001869
Dave Airlie40d9b042014-10-20 16:29:33 +10001870 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1871 if (edid)
1872 drm_get_displayid(connector, edid);
1873 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001874}
1875EXPORT_SYMBOL(drm_get_edid);
1876
Jani Nikula51f8da52013-09-27 15:08:27 +03001877/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001878 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1879 * @connector: connector we're probing
1880 * @adapter: I2C adapter to use for DDC
1881 *
1882 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1883 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1884 * switch DDC to the GPU which is retrieving EDID.
1885 *
1886 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1887 */
1888struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1889 struct i2c_adapter *adapter)
1890{
1891 struct pci_dev *pdev = connector->dev->pdev;
1892 struct edid *edid;
1893
1894 vga_switcheroo_lock_ddc(pdev);
1895 edid = drm_get_edid(connector, adapter);
1896 vga_switcheroo_unlock_ddc(pdev);
1897
1898 return edid;
1899}
1900EXPORT_SYMBOL(drm_get_edid_switcheroo);
1901
1902/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001903 * drm_edid_duplicate - duplicate an EDID and the extensions
1904 * @edid: EDID to duplicate
1905 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001906 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001907 */
1908struct edid *drm_edid_duplicate(const struct edid *edid)
1909{
1910 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1911}
1912EXPORT_SYMBOL(drm_edid_duplicate);
1913
Adam Jackson61e57a82010-03-29 21:43:18 +00001914/*** EDID parsing ***/
1915
Dave Airlief453ba02008-11-07 14:05:41 -08001916/**
1917 * edid_vendor - match a string against EDID's obfuscated vendor field
1918 * @edid: EDID to match
1919 * @vendor: vendor string
1920 *
1921 * Returns true if @vendor is in @edid, false otherwise
1922 */
Keith Packard170178f2017-12-13 00:44:26 -08001923static bool edid_vendor(const struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001924{
1925 char edid_vendor[3];
1926
1927 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1928 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1929 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001930 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001931
1932 return !strncmp(edid_vendor, vendor, 3);
1933}
1934
1935/**
1936 * edid_get_quirks - return quirk flags for a given EDID
1937 * @edid: EDID to process
1938 *
1939 * This tells subsequent routines what fixes they need to apply.
1940 */
Keith Packard170178f2017-12-13 00:44:26 -08001941static u32 edid_get_quirks(const struct edid *edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001942{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001943 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001944 int i;
1945
1946 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1947 quirk = &edid_quirk_list[i];
1948
1949 if (edid_vendor(edid, quirk->vendor) &&
1950 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1951 return quirk->quirks;
1952 }
1953
1954 return 0;
1955}
1956
1957#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001958#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001959
Dave Airlief453ba02008-11-07 14:05:41 -08001960/**
1961 * edid_fixup_preferred - set preferred modes based on quirk list
1962 * @connector: has mode list to fix up
1963 * @quirks: quirks list
1964 *
1965 * Walk the mode list for @connector, clearing the preferred status
1966 * on existing modes and setting it anew for the right mode ala @quirks.
1967 */
1968static void edid_fixup_preferred(struct drm_connector *connector,
1969 u32 quirks)
1970{
1971 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001972 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001973 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001974
1975 if (list_empty(&connector->probed_modes))
1976 return;
1977
1978 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1979 target_refresh = 60;
1980 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1981 target_refresh = 75;
1982
1983 preferred_mode = list_first_entry(&connector->probed_modes,
1984 struct drm_display_mode, head);
1985
1986 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1987 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1988
1989 if (cur_mode == preferred_mode)
1990 continue;
1991
1992 /* Largest mode is preferred */
1993 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1994 preferred_mode = cur_mode;
1995
Alex Deucher339d2022013-08-15 11:42:14 -04001996 cur_vrefresh = cur_mode->vrefresh ?
1997 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1998 preferred_vrefresh = preferred_mode->vrefresh ?
1999 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08002000 /* At a given size, try to get closest to target refresh */
2001 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04002002 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
2003 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08002004 preferred_mode = cur_mode;
2005 }
2006 }
2007
2008 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
2009}
2010
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002011static bool
2012mode_is_rb(const struct drm_display_mode *mode)
2013{
2014 return (mode->htotal - mode->hdisplay == 160) &&
2015 (mode->hsync_end - mode->hdisplay == 80) &&
2016 (mode->hsync_end - mode->hsync_start == 32) &&
2017 (mode->vsync_start - mode->vdisplay == 3);
2018}
2019
Adam Jackson33c75312012-04-13 16:33:29 -04002020/*
2021 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
2022 * @dev: Device to duplicate against
2023 * @hsize: Mode width
2024 * @vsize: Mode height
2025 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002026 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04002027 *
2028 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002029 *
2030 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04002031 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002032struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002033 int hsize, int vsize, int fresh,
2034 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08002035{
Adam Jackson07a5e632009-12-03 17:44:38 -05002036 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08002037
Thierry Redinga6b21832012-11-23 15:01:42 +01002038 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002039 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002040 if (hsize != ptr->hdisplay)
2041 continue;
2042 if (vsize != ptr->vdisplay)
2043 continue;
2044 if (fresh != drm_mode_vrefresh(ptr))
2045 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002046 if (rb != mode_is_rb(ptr))
2047 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002048
2049 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08002050 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002051
2052 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002053}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002054EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04002055
Adam Jacksond1ff6402010-03-29 21:43:26 +00002056typedef void detailed_cb(struct detailed_timing *timing, void *closure);
2057
2058static void
Adam Jackson4d76a222010-08-03 14:38:17 -04002059cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
2060{
2061 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01002062 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04002063 u8 *det_base = ext + d;
2064
Christian Schmidt4966b2a2011-12-19 20:03:43 +01002065 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04002066 for (i = 0; i < n; i++)
2067 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2068}
2069
2070static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002071vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
2072{
2073 unsigned int i, n = min((int)ext[0x02], 6);
2074 u8 *det_base = ext + 5;
2075
2076 if (ext[0x01] != 1)
2077 return; /* unknown version */
2078
2079 for (i = 0; i < n; i++)
2080 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2081}
2082
2083static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00002084drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
2085{
2086 int i;
2087 struct edid *edid = (struct edid *)raw_edid;
2088
2089 if (edid == NULL)
2090 return;
2091
2092 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
2093 cb(&(edid->detailed_timings[i]), closure);
2094
Adam Jackson4d76a222010-08-03 14:38:17 -04002095 for (i = 1; i <= raw_edid[0x7e]; i++) {
2096 u8 *ext = raw_edid + (i * EDID_LENGTH);
2097 switch (*ext) {
2098 case CEA_EXT:
2099 cea_for_each_detailed_block(ext, cb, closure);
2100 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002101 case VTB_EXT:
2102 vtb_for_each_detailed_block(ext, cb, closure);
2103 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04002104 default:
2105 break;
2106 }
2107 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00002108}
2109
2110static void
2111is_rb(struct detailed_timing *t, void *data)
2112{
2113 u8 *r = (u8 *)t;
2114 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
2115 if (r[15] & 0x10)
2116 *(bool *)data = true;
2117}
2118
2119/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
2120static bool
2121drm_monitor_supports_rb(struct edid *edid)
2122{
2123 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02002124 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00002125 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
2126 return ret;
2127 }
2128
2129 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
2130}
2131
Adam Jackson7a374352010-03-29 21:43:30 +00002132static void
2133find_gtf2(struct detailed_timing *t, void *data)
2134{
2135 u8 *r = (u8 *)t;
2136 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
2137 *(u8 **)data = r;
2138}
2139
2140/* Secondary GTF curve kicks in above some break frequency */
2141static int
2142drm_gtf2_hbreak(struct edid *edid)
2143{
2144 u8 *r = NULL;
2145 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2146 return r ? (r[12] * 2) : 0;
2147}
2148
2149static int
2150drm_gtf2_2c(struct edid *edid)
2151{
2152 u8 *r = NULL;
2153 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2154 return r ? r[13] : 0;
2155}
2156
2157static int
2158drm_gtf2_m(struct edid *edid)
2159{
2160 u8 *r = NULL;
2161 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2162 return r ? (r[15] << 8) + r[14] : 0;
2163}
2164
2165static int
2166drm_gtf2_k(struct edid *edid)
2167{
2168 u8 *r = NULL;
2169 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2170 return r ? r[16] : 0;
2171}
2172
2173static int
2174drm_gtf2_2j(struct edid *edid)
2175{
2176 u8 *r = NULL;
2177 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2178 return r ? r[17] : 0;
2179}
2180
2181/**
2182 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
2183 * @edid: EDID block to scan
2184 */
2185static int standard_timing_level(struct edid *edid)
2186{
2187 if (edid->revision >= 2) {
2188 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
2189 return LEVEL_CVT;
2190 if (drm_gtf2_hbreak(edid))
2191 return LEVEL_GTF2;
Lee Shawn Cbfef04a2019-10-07 21:51:27 +08002192 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
2193 return LEVEL_GTF;
Adam Jackson7a374352010-03-29 21:43:30 +00002194 }
2195 return LEVEL_DMT;
2196}
2197
Adam Jackson23425ca2009-09-23 17:30:58 -04002198/*
2199 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2200 * monitors fill with ascii space (0x20) instead.
2201 */
2202static int
2203bad_std_timing(u8 a, u8 b)
2204{
2205 return (a == 0x00 && b == 0x00) ||
2206 (a == 0x01 && b == 0x01) ||
2207 (a == 0x20 && b == 0x20);
2208}
2209
Dave Airlief453ba02008-11-07 14:05:41 -08002210/**
2211 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002212 * @connector: connector of for the EDID block
2213 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002214 * @t: standard timing params
2215 *
2216 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002217 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002218 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002219static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002220drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002221 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002222{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002223 struct drm_device *dev = connector->dev;
2224 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002225 int hsize, vsize;
2226 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002227 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2228 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002229 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2230 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002231 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002232
Adam Jackson23425ca2009-09-23 17:30:58 -04002233 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2234 return NULL;
2235
Zhao Yakui5c612592009-06-22 13:17:10 +08002236 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2237 hsize = t->hsize * 8 + 248;
2238 /* vrefresh_rate = vfreq + 60 */
2239 vrefresh_rate = vfreq + 60;
2240 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002241 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002242 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002243 vsize = hsize;
2244 else
2245 vsize = (hsize * 10) / 16;
2246 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002247 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002248 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002249 vsize = (hsize * 4) / 5;
2250 else
2251 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002252
2253 /* HDTV hack, part 1 */
2254 if (vrefresh_rate == 60 &&
2255 ((hsize == 1360 && vsize == 765) ||
2256 (hsize == 1368 && vsize == 769))) {
2257 hsize = 1366;
2258 vsize = 768;
2259 }
2260
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002261 /*
2262 * If this connector already has a mode for this size and refresh
2263 * rate (because it came from detailed or CVT info), use that
2264 * instead. This way we don't have to guess at interlace or
2265 * reduced blanking.
2266 */
Adam Jackson522032d2010-04-09 16:52:49 +00002267 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002268 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2269 drm_mode_vrefresh(m) == vrefresh_rate)
2270 return NULL;
2271
Adam Jacksona0910c82010-03-29 21:43:28 +00002272 /* HDTV hack, part 2 */
2273 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2274 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002275 false);
Joe Moriartya5ef6562018-02-12 14:51:43 -05002276 if (!mode)
2277 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002278 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002279 mode->hsync_start = mode->hsync_start - 1;
2280 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002281 return mode;
2282 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002283
Zhao Yakui559ee212009-09-03 09:33:47 +08002284 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002285 if (drm_monitor_supports_rb(edid)) {
2286 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2287 true);
2288 if (mode)
2289 return mode;
2290 }
2291 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002292 if (mode)
2293 return mode;
2294
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002295 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002296 switch (timing_level) {
2297 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002298 break;
2299 case LEVEL_GTF:
2300 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2301 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002302 case LEVEL_GTF2:
2303 /*
2304 * This is potentially wrong if there's ever a monitor with
2305 * more than one ranges section, each claiming a different
2306 * secondary GTF curve. Please don't do that.
2307 */
2308 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002309 if (!mode)
2310 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002311 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002312 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002313 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2314 vrefresh_rate, 0, 0,
2315 drm_gtf2_m(edid),
2316 drm_gtf2_2c(edid),
2317 drm_gtf2_k(edid),
2318 drm_gtf2_2j(edid));
2319 }
2320 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002321 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002322 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2323 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002324 break;
2325 }
Dave Airlief453ba02008-11-07 14:05:41 -08002326 return mode;
2327}
2328
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002329/*
2330 * EDID is delightfully ambiguous about how interlaced modes are to be
2331 * encoded. Our internal representation is of frame height, but some
2332 * HDTV detailed timings are encoded as field height.
2333 *
2334 * The format list here is from CEA, in frame size. Technically we
2335 * should be checking refresh rate too. Whatever.
2336 */
2337static void
2338drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2339 struct detailed_pixel_timing *pt)
2340{
2341 int i;
2342 static const struct {
2343 int w, h;
2344 } cea_interlaced[] = {
2345 { 1920, 1080 },
2346 { 720, 480 },
2347 { 1440, 480 },
2348 { 2880, 480 },
2349 { 720, 576 },
2350 { 1440, 576 },
2351 { 2880, 576 },
2352 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002353
2354 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2355 return;
2356
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002357 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002358 if ((mode->hdisplay == cea_interlaced[i].w) &&
2359 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2360 mode->vdisplay *= 2;
2361 mode->vsync_start *= 2;
2362 mode->vsync_end *= 2;
2363 mode->vtotal *= 2;
2364 mode->vtotal |= 1;
2365 }
2366 }
2367
2368 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2369}
2370
Dave Airlief453ba02008-11-07 14:05:41 -08002371/**
2372 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2373 * @dev: DRM device (needed to create new mode)
2374 * @edid: EDID block
2375 * @timing: EDID detailed timing info
2376 * @quirks: quirks to apply
2377 *
2378 * An EDID detailed timing block contains enough info for us to create and
2379 * return a new struct drm_display_mode.
2380 */
2381static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2382 struct edid *edid,
2383 struct detailed_timing *timing,
2384 u32 quirks)
2385{
2386 struct drm_display_mode *mode;
2387 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002388 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2389 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2390 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2391 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002392 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2393 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 +01002394 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 +02002395 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 -08002396
Adam Jacksonfc438962009-06-04 10:20:34 +10002397 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002398 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002399 return NULL;
2400
Michel Dänzer0454bea2009-06-15 16:56:07 +02002401 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002402 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002403 return NULL;
2404 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002405 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002406 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002407 }
2408
Zhao Yakuifcb45612009-10-14 09:11:25 +08002409 /* it is incorrect if hsync/vsync width is zero */
2410 if (!hsync_pulse_width || !vsync_pulse_width) {
2411 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2412 "Wrong Hsync/Vsync pulse width\n");
2413 return NULL;
2414 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002415
2416 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2417 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2418 if (!mode)
2419 return NULL;
2420
2421 goto set_size;
2422 }
2423
Dave Airlief453ba02008-11-07 14:05:41 -08002424 mode = drm_mode_create(dev);
2425 if (!mode)
2426 return NULL;
2427
Dave Airlief453ba02008-11-07 14:05:41 -08002428 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002429 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002430
Michel Dänzer0454bea2009-06-15 16:56:07 +02002431 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002432
Michel Dänzer0454bea2009-06-15 16:56:07 +02002433 mode->hdisplay = hactive;
2434 mode->hsync_start = mode->hdisplay + hsync_offset;
2435 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2436 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002437
Michel Dänzer0454bea2009-06-15 16:56:07 +02002438 mode->vdisplay = vactive;
2439 mode->vsync_start = mode->vdisplay + vsync_offset;
2440 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2441 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002442
Jesse Barnes7064fef2009-11-05 10:12:54 -08002443 /* Some EDIDs have bogus h/vtotal values */
2444 if (mode->hsync_end > mode->htotal)
2445 mode->htotal = mode->hsync_end + 1;
2446 if (mode->vsync_end > mode->vtotal)
2447 mode->vtotal = mode->vsync_end + 1;
2448
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002449 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002450
2451 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002452 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002453 }
2454
Michel Dänzer0454bea2009-06-15 16:56:07 +02002455 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2456 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2457 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2458 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002459
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002460set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002461 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2462 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002463
2464 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2465 mode->width_mm *= 10;
2466 mode->height_mm *= 10;
2467 }
2468
2469 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2470 mode->width_mm = edid->width_cm * 10;
2471 mode->height_mm = edid->height_cm * 10;
2472 }
2473
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002474 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002475 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002476 drm_mode_set_name(mode);
2477
Dave Airlief453ba02008-11-07 14:05:41 -08002478 return mode;
2479}
2480
Adam Jackson07a5e632009-12-03 17:44:38 -05002481static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002482mode_in_hsync_range(const struct drm_display_mode *mode,
2483 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002484{
2485 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002486
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002487 hmin = t[7];
2488 if (edid->revision >= 4)
2489 hmin += ((t[4] & 0x04) ? 255 : 0);
2490 hmax = t[8];
2491 if (edid->revision >= 4)
2492 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002493 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002494
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002495 return (hsync <= hmax && hsync >= hmin);
2496}
2497
2498static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002499mode_in_vsync_range(const struct drm_display_mode *mode,
2500 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002501{
2502 int vsync, vmin, vmax;
2503
2504 vmin = t[5];
2505 if (edid->revision >= 4)
2506 vmin += ((t[4] & 0x01) ? 255 : 0);
2507 vmax = t[6];
2508 if (edid->revision >= 4)
2509 vmax += ((t[4] & 0x02) ? 255 : 0);
2510 vsync = drm_mode_vrefresh(mode);
2511
2512 return (vsync <= vmax && vsync >= vmin);
2513}
2514
2515static u32
2516range_pixel_clock(struct edid *edid, u8 *t)
2517{
2518 /* unspecified */
2519 if (t[9] == 0 || t[9] == 255)
2520 return 0;
2521
2522 /* 1.4 with CVT support gives us real precision, yay */
2523 if (edid->revision >= 4 && t[10] == 0x04)
2524 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2525
2526 /* 1.3 is pathetic, so fuzz up a bit */
2527 return t[9] * 10000 + 5001;
2528}
2529
Adam Jackson07a5e632009-12-03 17:44:38 -05002530static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002531mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002532 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002533{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002534 u32 max_clock;
2535 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002536
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002537 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002538 return false;
2539
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002540 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002541 return false;
2542
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002543 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002544 if (mode->clock > max_clock)
2545 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002546
2547 /* 1.4 max horizontal check */
2548 if (edid->revision >= 4 && t[10] == 0x04)
2549 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2550 return false;
2551
2552 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2553 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002554
2555 return true;
2556}
2557
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002558static bool valid_inferred_mode(const struct drm_connector *connector,
2559 const struct drm_display_mode *mode)
2560{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002561 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002562 bool ok = false;
2563
2564 list_for_each_entry(m, &connector->probed_modes, head) {
2565 if (mode->hdisplay == m->hdisplay &&
2566 mode->vdisplay == m->vdisplay &&
2567 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2568 return false; /* duplicated */
2569 if (mode->hdisplay <= m->hdisplay &&
2570 mode->vdisplay <= m->vdisplay)
2571 ok = true;
2572 }
2573 return ok;
2574}
2575
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002576static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002577drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002578 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002579{
2580 int i, modes = 0;
2581 struct drm_display_mode *newmode;
2582 struct drm_device *dev = connector->dev;
2583
Thierry Redinga6b21832012-11-23 15:01:42 +01002584 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002585 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2586 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002587 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2588 if (newmode) {
2589 drm_mode_probed_add(connector, newmode);
2590 modes++;
2591 }
2592 }
2593 }
2594
2595 return modes;
2596}
2597
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002598/* fix up 1366x768 mode from 1368x768;
2599 * GFT/CVT can't express 1366 width which isn't dividable by 8
2600 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002601void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002602{
2603 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2604 mode->hdisplay = 1366;
2605 mode->hsync_start--;
2606 mode->hsync_end--;
2607 drm_mode_set_name(mode);
2608 }
2609}
2610
Adam Jacksonb309bd32012-04-13 16:33:40 -04002611static int
2612drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2613 struct detailed_timing *timing)
2614{
2615 int i, modes = 0;
2616 struct drm_display_mode *newmode;
2617 struct drm_device *dev = connector->dev;
2618
Thierry Redinga6b21832012-11-23 15:01:42 +01002619 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002620 const struct minimode *m = &extra_modes[i];
2621 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002622 if (!newmode)
2623 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002624
Takashi Iwai969218f2017-01-17 17:43:29 +01002625 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002626 if (!mode_in_range(newmode, edid, timing) ||
2627 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002628 drm_mode_destroy(dev, newmode);
2629 continue;
2630 }
2631
2632 drm_mode_probed_add(connector, newmode);
2633 modes++;
2634 }
2635
2636 return modes;
2637}
2638
2639static int
2640drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2641 struct detailed_timing *timing)
2642{
2643 int i, modes = 0;
2644 struct drm_display_mode *newmode;
2645 struct drm_device *dev = connector->dev;
2646 bool rb = drm_monitor_supports_rb(edid);
2647
Thierry Redinga6b21832012-11-23 15:01:42 +01002648 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002649 const struct minimode *m = &extra_modes[i];
2650 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002651 if (!newmode)
2652 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002653
Takashi Iwai969218f2017-01-17 17:43:29 +01002654 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002655 if (!mode_in_range(newmode, edid, timing) ||
2656 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002657 drm_mode_destroy(dev, newmode);
2658 continue;
2659 }
2660
2661 drm_mode_probed_add(connector, newmode);
2662 modes++;
2663 }
2664
2665 return modes;
2666}
2667
Adam Jackson13931572010-08-03 14:38:19 -04002668static void
2669do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002670{
Adam Jackson13931572010-08-03 14:38:19 -04002671 struct detailed_mode_closure *closure = c;
2672 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002673 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002674
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002675 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2676 return;
2677
2678 closure->modes += drm_dmt_modes_for_range(closure->connector,
2679 closure->edid,
2680 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002681
2682 if (!version_greater(closure->edid, 1, 1))
2683 return; /* GTF not defined yet */
2684
2685 switch (range->flags) {
2686 case 0x02: /* secondary gtf, XXX could do more */
2687 case 0x00: /* default gtf */
2688 closure->modes += drm_gtf_modes_for_range(closure->connector,
2689 closure->edid,
2690 timing);
2691 break;
2692 case 0x04: /* cvt, only in 1.4+ */
2693 if (!version_greater(closure->edid, 1, 3))
2694 break;
2695
2696 closure->modes += drm_cvt_modes_for_range(closure->connector,
2697 closure->edid,
2698 timing);
2699 break;
2700 case 0x01: /* just the ranges, no formula */
2701 default:
2702 break;
2703 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002704}
2705
Adam Jackson13931572010-08-03 14:38:19 -04002706static int
2707add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2708{
2709 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002710 .connector = connector,
2711 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002712 };
2713
2714 if (version_greater(edid, 1, 0))
2715 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2716 &closure);
2717
2718 return closure.modes;
2719}
2720
Adam Jackson2255be12010-03-29 21:43:22 +00002721static int
2722drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2723{
2724 int i, j, m, modes = 0;
2725 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002726 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002727
2728 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002729 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002730 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002731 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002732 break;
2733 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002734 mode = drm_mode_find_dmt(connector->dev,
2735 est3_modes[m].w,
2736 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002737 est3_modes[m].r,
2738 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002739 if (mode) {
2740 drm_mode_probed_add(connector, mode);
2741 modes++;
2742 }
2743 }
2744 }
2745 }
2746
2747 return modes;
2748}
2749
Adam Jackson13931572010-08-03 14:38:19 -04002750static void
2751do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002752{
Adam Jackson13931572010-08-03 14:38:19 -04002753 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002754 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002755
2756 if (data->type == EDID_DETAIL_EST_TIMINGS)
2757 closure->modes += drm_est3_modes(closure->connector, timing);
2758}
2759
2760/**
2761 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002762 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002763 * @edid: EDID block to scan
2764 *
2765 * Each EDID block contains a bitmap of the supported "established modes" list
2766 * (defined above). Tease them out and add them to the global modes list.
2767 */
2768static int
2769add_established_modes(struct drm_connector *connector, struct edid *edid)
2770{
Adam Jackson9cf00972009-12-03 17:44:36 -05002771 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002772 unsigned long est_bits = edid->established_timings.t1 |
2773 (edid->established_timings.t2 << 8) |
2774 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2775 int i, modes = 0;
2776 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002777 .connector = connector,
2778 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002779 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002780
Adam Jackson13931572010-08-03 14:38:19 -04002781 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2782 if (est_bits & (1<<i)) {
2783 struct drm_display_mode *newmode;
2784 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2785 if (newmode) {
2786 drm_mode_probed_add(connector, newmode);
2787 modes++;
2788 }
2789 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002790 }
2791
Adam Jackson13931572010-08-03 14:38:19 -04002792 if (version_greater(edid, 1, 0))
2793 drm_for_each_detailed_block((u8 *)edid,
2794 do_established_modes, &closure);
2795
2796 return modes + closure.modes;
2797}
2798
2799static void
2800do_standard_modes(struct detailed_timing *timing, void *c)
2801{
2802 struct detailed_mode_closure *closure = c;
2803 struct detailed_non_pixel *data = &timing->data.other_data;
2804 struct drm_connector *connector = closure->connector;
2805 struct edid *edid = closure->edid;
2806
2807 if (data->type == EDID_DETAIL_STD_MODES) {
2808 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002809 for (i = 0; i < 6; i++) {
2810 struct std_timing *std;
2811 struct drm_display_mode *newmode;
2812
2813 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002814 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002815 if (newmode) {
2816 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002817 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002818 }
2819 }
Adam Jackson13931572010-08-03 14:38:19 -04002820 }
2821}
2822
2823/**
2824 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002825 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002826 * @edid: EDID block to scan
2827 *
2828 * Standard modes can be calculated using the appropriate standard (DMT,
2829 * GTF or CVT. Grab them from @edid and add them to the list.
2830 */
2831static int
2832add_standard_modes(struct drm_connector *connector, struct edid *edid)
2833{
2834 int i, modes = 0;
2835 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002836 .connector = connector,
2837 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002838 };
2839
2840 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2841 struct drm_display_mode *newmode;
2842
2843 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002844 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002845 if (newmode) {
2846 drm_mode_probed_add(connector, newmode);
2847 modes++;
2848 }
2849 }
2850
2851 if (version_greater(edid, 1, 0))
2852 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2853 &closure);
2854
2855 /* XXX should also look for standard codes in VTB blocks */
2856
2857 return modes + closure.modes;
2858}
2859
Dave Airlief453ba02008-11-07 14:05:41 -08002860static int drm_cvt_modes(struct drm_connector *connector,
2861 struct detailed_timing *timing)
2862{
2863 int i, j, modes = 0;
2864 struct drm_display_mode *newmode;
2865 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002866 struct cvt_timing *cvt;
2867 const int rates[] = { 60, 85, 75, 60, 50 };
2868 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002869
2870 for (i = 0; i < 4; i++) {
2871 int uninitialized_var(width), height;
2872 cvt = &(timing->data.other_data.data.cvt[i]);
2873
2874 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002875 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002876
2877 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002878 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002879 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002880 width = height * 4 / 3;
2881 break;
2882 case 0x04:
2883 width = height * 16 / 9;
2884 break;
2885 case 0x08:
2886 width = height * 16 / 10;
2887 break;
2888 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002889 width = height * 15 / 9;
2890 break;
2891 }
2892
2893 for (j = 1; j < 5; j++) {
2894 if (cvt->code[2] & (1 << j)) {
2895 newmode = drm_cvt_mode(dev, width, height,
2896 rates[j], j == 0,
2897 false, false);
2898 if (newmode) {
2899 drm_mode_probed_add(connector, newmode);
2900 modes++;
2901 }
2902 }
2903 }
2904 }
2905
2906 return modes;
2907}
2908
Adam Jackson13931572010-08-03 14:38:19 -04002909static void
2910do_cvt_mode(struct detailed_timing *timing, void *c)
2911{
2912 struct detailed_mode_closure *closure = c;
2913 struct detailed_non_pixel *data = &timing->data.other_data;
2914
2915 if (data->type == EDID_DETAIL_CVT_3BYTE)
2916 closure->modes += drm_cvt_modes(closure->connector, timing);
2917}
Adam Jackson9cf00972009-12-03 17:44:36 -05002918
2919static int
Adam Jackson13931572010-08-03 14:38:19 -04002920add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2921{
2922 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002923 .connector = connector,
2924 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002925 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002926
Adam Jackson13931572010-08-03 14:38:19 -04002927 if (version_greater(edid, 1, 2))
2928 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002929
Adam Jackson13931572010-08-03 14:38:19 -04002930 /* XXX should also look for CVT codes in VTB blocks */
2931
2932 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002933}
2934
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002935static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2936
Adam Jackson13931572010-08-03 14:38:19 -04002937static void
2938do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002939{
Adam Jackson13931572010-08-03 14:38:19 -04002940 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002941 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002942
2943 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002944 newmode = drm_mode_detailed(closure->connector->dev,
2945 closure->edid, timing,
2946 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002947 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002948 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002949
Adam Jackson13931572010-08-03 14:38:19 -04002950 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002951 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2952
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002953 /*
2954 * Detailed modes are limited to 10kHz pixel clock resolution,
2955 * so fix up anything that looks like CEA/HDMI mode, but the clock
2956 * is just slightly off.
2957 */
2958 fixup_detailed_cea_mode_clock(newmode);
2959
Adam Jackson13931572010-08-03 14:38:19 -04002960 drm_mode_probed_add(closure->connector, newmode);
2961 closure->modes++;
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002962 closure->preferred = false;
Zhao Yakui882f0212009-08-26 18:20:49 +08002963 }
Ma Ling167f3a02009-03-20 14:09:48 +08002964}
2965
Adam Jackson13931572010-08-03 14:38:19 -04002966/*
2967 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002968 * @connector: attached connector
2969 * @edid: EDID block to scan
2970 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002971 */
Adam Jackson13931572010-08-03 14:38:19 -04002972static int
2973add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2974 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002975{
Adam Jackson13931572010-08-03 14:38:19 -04002976 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002977 .connector = connector,
2978 .edid = edid,
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002979 .preferred = true,
Julia Lawalld456ea22014-08-23 18:09:56 +02002980 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002981 };
Dave Airlief453ba02008-11-07 14:05:41 -08002982
Adam Jackson13931572010-08-03 14:38:19 -04002983 if (closure.preferred && !version_greater(edid, 1, 3))
2984 closure.preferred =
2985 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002986
Adam Jackson13931572010-08-03 14:38:19 -04002987 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002988
Adam Jackson13931572010-08-03 14:38:19 -04002989 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002990}
Dave Airlief453ba02008-11-07 14:05:41 -08002991
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002992#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002993#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002994#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002995#define SPEAKER_BLOCK 0x04
Uma Shankare85959d2019-05-16 19:40:08 +05302996#define HDR_STATIC_METADATA_BLOCK 0x6
Shashank Sharma87563fc2017-07-13 21:03:10 +05302997#define USE_EXTENDED_TAG 0x07
2998#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05302999#define EXT_VIDEO_DATA_BLOCK_420 0x0E
3000#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003001#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003002#define EDID_CEA_YCRCB444 (1 << 5)
3003#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003004#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003005
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01003006/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003007 * Search EDID for CEA extension block.
3008 */
Keith Packard170178f2017-12-13 00:44:26 -08003009static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003010{
3011 u8 *edid_ext = NULL;
3012 int i;
3013
3014 /* No EDID or EDID extensions */
3015 if (edid == NULL || edid->extensions == 0)
3016 return NULL;
3017
3018 /* Find CEA extension */
3019 for (i = 0; i < edid->extensions; i++) {
3020 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10003021 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003022 break;
3023 }
3024
3025 if (i == edid->extensions)
3026 return NULL;
3027
3028 return edid_ext;
3029}
3030
Dave Airlie40d9b042014-10-20 16:29:33 +10003031
Keith Packard170178f2017-12-13 00:44:26 -08003032static u8 *drm_find_displayid_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10003033{
3034 return drm_find_edid_extension(edid, DISPLAYID_EXT);
3035}
3036
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003037static u8 *drm_find_cea_extension(const struct edid *edid)
3038{
3039 int ret;
3040 int idx = 1;
3041 int length = EDID_LENGTH;
3042 struct displayid_block *block;
3043 u8 *cea;
3044 u8 *displayid;
3045
3046 /* Look for a top level CEA extension block */
3047 cea = drm_find_edid_extension(edid, CEA_EXT);
3048 if (cea)
3049 return cea;
3050
3051 /* CEA blocks can also be found embedded in a DisplayID block */
3052 displayid = drm_find_displayid_extension(edid);
3053 if (!displayid)
3054 return NULL;
3055
3056 ret = validate_displayid(displayid, length, idx);
3057 if (ret)
3058 return NULL;
3059
3060 idx += sizeof(struct displayid_hdr);
3061 for_each_displayid_db(displayid, block, idx, length) {
3062 if (block->tag == DATA_BLOCK_CTA) {
3063 cea = (u8 *)block;
3064 break;
3065 }
3066 }
3067
3068 return cea;
3069}
3070
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003071/*
3072 * Calculate the alternate clock for the CEA mode
3073 * (60Hz vs. 59.94Hz etc.)
3074 */
3075static unsigned int
3076cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
3077{
3078 unsigned int clock = cea_mode->clock;
3079
3080 if (cea_mode->vrefresh % 6 != 0)
3081 return clock;
3082
3083 /*
3084 * edid_cea_modes contains the 59.94Hz
3085 * variant for 240 and 480 line modes,
3086 * and the 60Hz variant otherwise.
3087 */
3088 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03003089 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003090 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03003091 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003092
3093 return clock;
3094}
3095
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003096static bool
3097cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
3098{
3099 /*
3100 * For certain VICs the spec allows the vertical
3101 * front porch to vary by one or two lines.
3102 *
3103 * cea_modes[] stores the variant with the shortest
3104 * vertical front porch. We can adjust the mode to
3105 * get the other variants by simply increasing the
3106 * vertical front porch length.
3107 */
3108 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
3109 edid_cea_modes[9].vtotal != 262 ||
3110 edid_cea_modes[12].vtotal != 262 ||
3111 edid_cea_modes[13].vtotal != 262 ||
3112 edid_cea_modes[23].vtotal != 312 ||
3113 edid_cea_modes[24].vtotal != 312 ||
3114 edid_cea_modes[27].vtotal != 312 ||
3115 edid_cea_modes[28].vtotal != 312);
3116
3117 if (((vic == 8 || vic == 9 ||
3118 vic == 12 || vic == 13) && mode->vtotal < 263) ||
3119 ((vic == 23 || vic == 24 ||
3120 vic == 27 || vic == 28) && mode->vtotal < 314)) {
3121 mode->vsync_start++;
3122 mode->vsync_end++;
3123 mode->vtotal++;
3124
3125 return true;
3126 }
3127
3128 return false;
3129}
3130
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003131static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
3132 unsigned int clock_tolerance)
3133{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303134 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003135 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003136
3137 if (!to_match->clock)
3138 return 0;
3139
Ville Syrjälä357768c2018-05-08 16:39:38 +05303140 if (to_match->picture_aspect_ratio)
3141 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3142
Jani Nikulad9278b42016-01-08 13:21:51 +02003143 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003144 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003145 unsigned int clock1, clock2;
3146
3147 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003148 clock1 = cea_mode.clock;
3149 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003150
3151 if (abs(to_match->clock - clock1) > clock_tolerance &&
3152 abs(to_match->clock - clock2) > clock_tolerance)
3153 continue;
3154
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003155 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303156 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003157 return vic;
3158 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003159 }
3160
3161 return 0;
3162}
3163
Thierry Reding18316c82012-12-20 15:41:44 +01003164/**
3165 * drm_match_cea_mode - look for a CEA mode matching given mode
3166 * @to_match: display mode
3167 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003168 * 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 +01003169 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00003170 */
Thierry Reding18316c82012-12-20 15:41:44 +01003171u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00003172{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303173 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003174 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00003175
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003176 if (!to_match->clock)
3177 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00003178
Ville Syrjälä357768c2018-05-08 16:39:38 +05303179 if (to_match->picture_aspect_ratio)
3180 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3181
Jani Nikulad9278b42016-01-08 13:21:51 +02003182 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003183 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003184 unsigned int clock1, clock2;
3185
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003186 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003187 clock1 = cea_mode.clock;
3188 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003189
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003190 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
3191 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
3192 continue;
3193
3194 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303195 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003196 return vic;
3197 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00003198 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003199
Stephane Marchesina4799032012-11-09 16:21:05 +00003200 return 0;
3201}
3202EXPORT_SYMBOL(drm_match_cea_mode);
3203
Jani Nikulad9278b42016-01-08 13:21:51 +02003204static bool drm_valid_cea_vic(u8 vic)
3205{
3206 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
3207}
3208
Ville Syrjälä28c03a442019-10-04 17:19:11 +03003209static enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303210{
Jani Nikulad9278b42016-01-08 13:21:51 +02003211 return edid_cea_modes[video_code].picture_aspect_ratio;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303212}
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303213
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003214/*
3215 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
3216 * specific block).
3217 *
3218 * It's almost like cea_mode_alternate_clock(), we just need to add an
3219 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
3220 * one.
3221 */
3222static unsigned int
3223hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3224{
3225 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
3226 return hdmi_mode->clock;
3227
3228 return cea_mode_alternate_clock(hdmi_mode);
3229}
3230
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003231static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3232 unsigned int clock_tolerance)
3233{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303234 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003235 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003236
3237 if (!to_match->clock)
3238 return 0;
3239
Jani Nikulad9278b42016-01-08 13:21:51 +02003240 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3241 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003242 unsigned int clock1, clock2;
3243
3244 /* Make sure to also match alternate clocks */
3245 clock1 = hdmi_mode->clock;
3246 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3247
3248 if (abs(to_match->clock - clock1) > clock_tolerance &&
3249 abs(to_match->clock - clock2) > clock_tolerance)
3250 continue;
3251
Ville Syrjälä357768c2018-05-08 16:39:38 +05303252 if (drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003253 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003254 }
3255
3256 return 0;
3257}
3258
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003259/*
3260 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3261 * @to_match: display mode
3262 *
3263 * An HDMI mode is one defined in the HDMI vendor specific block.
3264 *
3265 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3266 */
3267static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3268{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303269 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003270 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003271
3272 if (!to_match->clock)
3273 return 0;
3274
Jani Nikulad9278b42016-01-08 13:21:51 +02003275 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3276 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003277 unsigned int clock1, clock2;
3278
3279 /* Make sure to also match alternate clocks */
3280 clock1 = hdmi_mode->clock;
3281 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3282
3283 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3284 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Ville Syrjälä357768c2018-05-08 16:39:38 +05303285 drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003286 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003287 }
3288 return 0;
3289}
3290
Jani Nikulad9278b42016-01-08 13:21:51 +02003291static bool drm_valid_hdmi_vic(u8 vic)
3292{
3293 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3294}
3295
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003296static int
3297add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3298{
3299 struct drm_device *dev = connector->dev;
3300 struct drm_display_mode *mode, *tmp;
3301 LIST_HEAD(list);
3302 int modes = 0;
3303
3304 /* Don't add CEA modes if the CEA extension block is missing */
3305 if (!drm_find_cea_extension(edid))
3306 return 0;
3307
3308 /*
3309 * Go through all probed modes and create a new mode
3310 * with the alternate clock for certain CEA modes.
3311 */
3312 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003313 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003314 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003315 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003316 unsigned int clock1, clock2;
3317
Jani Nikulad9278b42016-01-08 13:21:51 +02003318 if (drm_valid_cea_vic(vic)) {
3319 cea_mode = &edid_cea_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003320 clock2 = cea_mode_alternate_clock(cea_mode);
3321 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003322 vic = drm_match_hdmi_mode(mode);
3323 if (drm_valid_hdmi_vic(vic)) {
3324 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003325 clock2 = hdmi_mode_alternate_clock(cea_mode);
3326 }
3327 }
3328
3329 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003330 continue;
3331
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003332 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003333
3334 if (clock1 == clock2)
3335 continue;
3336
3337 if (mode->clock != clock1 && mode->clock != clock2)
3338 continue;
3339
3340 newmode = drm_mode_duplicate(dev, cea_mode);
3341 if (!newmode)
3342 continue;
3343
Damien Lespiau27130212013-09-25 16:45:28 +01003344 /* Carry over the stereo flags */
3345 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3346
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003347 /*
3348 * The current mode could be either variant. Make
3349 * sure to pick the "other" clock for the new mode.
3350 */
3351 if (mode->clock != clock1)
3352 newmode->clock = clock1;
3353 else
3354 newmode->clock = clock2;
3355
3356 list_add_tail(&newmode->head, &list);
3357 }
3358
3359 list_for_each_entry_safe(mode, tmp, &list, head) {
3360 list_del(&mode->head);
3361 drm_mode_probed_add(connector, mode);
3362 modes++;
3363 }
3364
3365 return modes;
3366}
Stephane Marchesina4799032012-11-09 16:21:05 +00003367
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303368static u8 svd_to_vic(u8 svd)
3369{
3370 /* 0-6 bit vic, 7th bit native mode indicator */
3371 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3372 return svd & 127;
3373
3374 return svd;
3375}
3376
Thomas Woodaff04ac2013-11-29 15:33:27 +00003377static struct drm_display_mode *
3378drm_display_mode_from_vic_index(struct drm_connector *connector,
3379 const u8 *video_db, u8 video_len,
3380 u8 video_index)
3381{
3382 struct drm_device *dev = connector->dev;
3383 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003384 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003385
3386 if (video_db == NULL || video_index >= video_len)
3387 return NULL;
3388
3389 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303390 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003391 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003392 return NULL;
3393
Jani Nikulad9278b42016-01-08 13:21:51 +02003394 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00003395 if (!newmode)
3396 return NULL;
3397
Thomas Woodaff04ac2013-11-29 15:33:27 +00003398 newmode->vrefresh = 0;
3399
3400 return newmode;
3401}
3402
Shashank Sharma832d4f22017-07-14 16:03:46 +05303403/*
3404 * do_y420vdb_modes - Parse YCBCR 420 only modes
3405 * @connector: connector corresponding to the HDMI sink
3406 * @svds: start of the data block of CEA YCBCR 420 VDB
3407 * @len: length of the CEA YCBCR 420 VDB
3408 *
3409 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3410 * which contains modes which can be supported in YCBCR 420
3411 * output format only.
3412 */
3413static int do_y420vdb_modes(struct drm_connector *connector,
3414 const u8 *svds, u8 svds_len)
3415{
3416 int modes = 0, i;
3417 struct drm_device *dev = connector->dev;
3418 struct drm_display_info *info = &connector->display_info;
3419 struct drm_hdmi_info *hdmi = &info->hdmi;
3420
3421 for (i = 0; i < svds_len; i++) {
3422 u8 vic = svd_to_vic(svds[i]);
3423 struct drm_display_mode *newmode;
3424
3425 if (!drm_valid_cea_vic(vic))
3426 continue;
3427
3428 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3429 if (!newmode)
3430 break;
3431 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3432 drm_mode_probed_add(connector, newmode);
3433 modes++;
3434 }
3435
3436 if (modes > 0)
3437 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3438 return modes;
3439}
3440
3441/*
3442 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3443 * @connector: connector corresponding to the HDMI sink
3444 * @vic: CEA vic for the video mode to be added in the map
3445 *
3446 * Makes an entry for a videomode in the YCBCR 420 bitmap
3447 */
3448static void
3449drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3450{
3451 u8 vic = svd_to_vic(svd);
3452 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3453
3454 if (!drm_valid_cea_vic(vic))
3455 return;
3456
3457 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3458}
3459
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003460static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003461do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003462{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003463 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303464 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003465
Thomas Woodaff04ac2013-11-29 15:33:27 +00003466 for (i = 0; i < len; i++) {
3467 struct drm_display_mode *mode;
3468 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3469 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303470 /*
3471 * YCBCR420 capability block contains a bitmap which
3472 * gives the index of CEA modes from CEA VDB, which
3473 * can support YCBCR 420 sampling output also (apart
3474 * from RGB/YCBCR444 etc).
3475 * For example, if the bit 0 in bitmap is set,
3476 * first mode in VDB can support YCBCR420 output too.
3477 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3478 */
3479 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3480 drm_add_cmdb_modes(connector, db[i]);
3481
Thomas Woodaff04ac2013-11-29 15:33:27 +00003482 drm_mode_probed_add(connector, mode);
3483 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003484 }
3485 }
3486
3487 return modes;
3488}
3489
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003490struct stereo_mandatory_mode {
3491 int width, height, vrefresh;
3492 unsigned int flags;
3493};
3494
3495static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003496 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3497 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003498 { 1920, 1080, 50,
3499 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3500 { 1920, 1080, 60,
3501 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003502 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3503 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3504 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3505 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003506};
3507
3508static bool
3509stereo_match_mandatory(const struct drm_display_mode *mode,
3510 const struct stereo_mandatory_mode *stereo_mode)
3511{
3512 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3513
3514 return mode->hdisplay == stereo_mode->width &&
3515 mode->vdisplay == stereo_mode->height &&
3516 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3517 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3518}
3519
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003520static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3521{
3522 struct drm_device *dev = connector->dev;
3523 const struct drm_display_mode *mode;
3524 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003525 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003526
3527 INIT_LIST_HEAD(&stereo_modes);
3528
3529 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003530 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3531 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003532 struct drm_display_mode *new_mode;
3533
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003534 if (!stereo_match_mandatory(mode,
3535 &stereo_mandatory_modes[i]))
3536 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003537
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003538 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003539 new_mode = drm_mode_duplicate(dev, mode);
3540 if (!new_mode)
3541 continue;
3542
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003543 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003544 list_add_tail(&new_mode->head, &stereo_modes);
3545 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003546 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003547 }
3548
3549 list_splice_tail(&stereo_modes, &connector->probed_modes);
3550
3551 return modes;
3552}
3553
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003554static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3555{
3556 struct drm_device *dev = connector->dev;
3557 struct drm_display_mode *newmode;
3558
Jani Nikulad9278b42016-01-08 13:21:51 +02003559 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003560 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3561 return 0;
3562 }
3563
3564 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3565 if (!newmode)
3566 return 0;
3567
3568 drm_mode_probed_add(connector, newmode);
3569
3570 return 1;
3571}
3572
Thomas Woodfbf46022013-10-16 15:58:50 +01003573static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3574 const u8 *video_db, u8 video_len, u8 video_index)
3575{
Thomas Woodfbf46022013-10-16 15:58:50 +01003576 struct drm_display_mode *newmode;
3577 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003578
3579 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003580 newmode = drm_display_mode_from_vic_index(connector, video_db,
3581 video_len,
3582 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003583 if (newmode) {
3584 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3585 drm_mode_probed_add(connector, newmode);
3586 modes++;
3587 }
3588 }
3589 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003590 newmode = drm_display_mode_from_vic_index(connector, video_db,
3591 video_len,
3592 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003593 if (newmode) {
3594 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3595 drm_mode_probed_add(connector, newmode);
3596 modes++;
3597 }
3598 }
3599 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003600 newmode = drm_display_mode_from_vic_index(connector, video_db,
3601 video_len,
3602 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003603 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003604 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003605 drm_mode_probed_add(connector, newmode);
3606 modes++;
3607 }
3608 }
3609
3610 return modes;
3611}
3612
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003613/*
3614 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3615 * @connector: connector corresponding to the HDMI sink
3616 * @db: start of the CEA vendor specific block
3617 * @len: length of the CEA block payload, ie. one can access up to db[len]
3618 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003619 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3620 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003621 */
3622static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003623do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3624 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003625{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003626 struct drm_display_info *info = &connector->display_info;
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003627 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003628 u8 vic_len, hdmi_3d_len = 0;
3629 u16 mask;
3630 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003631
3632 if (len < 8)
3633 goto out;
3634
3635 /* no HDMI_Video_Present */
3636 if (!(db[8] & (1 << 5)))
3637 goto out;
3638
3639 /* Latency_Fields_Present */
3640 if (db[8] & (1 << 7))
3641 offset += 2;
3642
3643 /* I_Latency_Fields_Present */
3644 if (db[8] & (1 << 6))
3645 offset += 2;
3646
3647 /* the declared length is not long enough for the 2 first bytes
3648 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003649 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003650 goto out;
3651
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003652 /* 3D_Present */
3653 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003654 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003655 modes += add_hdmi_mandatory_stereo_modes(connector);
3656
Thomas Woodfbf46022013-10-16 15:58:50 +01003657 /* 3D_Multi_present */
3658 multi_present = (db[8 + offset] & 0x60) >> 5;
3659 }
3660
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003661 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003662 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003663 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003664
3665 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003666 u8 vic;
3667
3668 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003669 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003670 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003671 offset += 1 + vic_len;
3672
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003673 if (multi_present == 1)
3674 multi_len = 2;
3675 else if (multi_present == 2)
3676 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003677 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003678 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003679
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003680 if (len < (8 + offset + hdmi_3d_len - 1))
3681 goto out;
3682
3683 if (hdmi_3d_len < multi_len)
3684 goto out;
3685
3686 if (multi_present == 1 || multi_present == 2) {
3687 /* 3D_Structure_ALL */
3688 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3689
3690 /* check if 3D_MASK is present */
3691 if (multi_present == 2)
3692 mask = (db[10 + offset] << 8) | db[11 + offset];
3693 else
3694 mask = 0xffff;
3695
3696 for (i = 0; i < 16; i++) {
3697 if (mask & (1 << i))
3698 modes += add_3d_struct_modes(connector,
3699 structure_all,
3700 video_db,
3701 video_len, i);
3702 }
3703 }
3704
3705 offset += multi_len;
3706
3707 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3708 int vic_index;
3709 struct drm_display_mode *newmode = NULL;
3710 unsigned int newflag = 0;
3711 bool detail_present;
3712
3713 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3714
3715 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3716 break;
3717
3718 /* 2D_VIC_order_X */
3719 vic_index = db[8 + offset + i] >> 4;
3720
3721 /* 3D_Structure_X */
3722 switch (db[8 + offset + i] & 0x0f) {
3723 case 0:
3724 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3725 break;
3726 case 6:
3727 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3728 break;
3729 case 8:
3730 /* 3D_Detail_X */
3731 if ((db[9 + offset + i] >> 4) == 1)
3732 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3733 break;
3734 }
3735
3736 if (newflag != 0) {
3737 newmode = drm_display_mode_from_vic_index(connector,
3738 video_db,
3739 video_len,
3740 vic_index);
3741
3742 if (newmode) {
3743 newmode->flags |= newflag;
3744 drm_mode_probed_add(connector, newmode);
3745 modes++;
3746 }
3747 }
3748
3749 if (detail_present)
3750 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003751 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003752
3753out:
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003754 if (modes > 0)
3755 info->has_hdmi_infoframe = true;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003756 return modes;
3757}
3758
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003759static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003760cea_db_payload_len(const u8 *db)
3761{
3762 return db[0] & 0x1f;
3763}
3764
3765static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05303766cea_db_extended_tag(const u8 *db)
3767{
3768 return db[1];
3769}
3770
3771static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003772cea_db_tag(const u8 *db)
3773{
3774 return db[0] >> 5;
3775}
3776
3777static int
3778cea_revision(const u8 *cea)
3779{
3780 return cea[1];
3781}
3782
3783static int
3784cea_db_offsets(const u8 *cea, int *start, int *end)
3785{
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003786 /* DisplayID CTA extension blocks and top-level CEA EDID
3787 * block header definitions differ in the following bytes:
3788 * 1) Byte 2 of the header specifies length differently,
3789 * 2) Byte 3 is only present in the CEA top level block.
3790 *
3791 * The different definitions for byte 2 follow.
3792 *
3793 * DisplayID CTA extension block defines byte 2 as:
3794 * Number of payload bytes
3795 *
3796 * CEA EDID block defines byte 2 as:
3797 * Byte number (decimal) within this block where the 18-byte
3798 * DTDs begin. If no non-DTD data is present in this extension
3799 * block, the value should be set to 04h (the byte after next).
3800 * If set to 00h, there are no DTDs present in this block and
3801 * no non-DTD data.
3802 */
3803 if (cea[0] == DATA_BLOCK_CTA) {
3804 *start = 3;
3805 *end = *start + cea[2];
3806 } else if (cea[0] == CEA_EXT) {
3807 /* Data block offset in CEA extension block */
3808 *start = 4;
3809 *end = cea[2];
3810 if (*end == 0)
3811 *end = 127;
3812 if (*end < 4 || *end > 127)
3813 return -ERANGE;
3814 } else {
Daniel Vetterc7581a42019-09-04 16:39:42 +02003815 return -EOPNOTSUPP;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003816 }
3817
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003818 return 0;
3819}
3820
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003821static bool cea_db_is_hdmi_vsdb(const u8 *db)
3822{
3823 int hdmi_id;
3824
3825 if (cea_db_tag(db) != VENDOR_BLOCK)
3826 return false;
3827
3828 if (cea_db_payload_len(db) < 5)
3829 return false;
3830
3831 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3832
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003833 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003834}
3835
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303836static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3837{
3838 unsigned int oui;
3839
3840 if (cea_db_tag(db) != VENDOR_BLOCK)
3841 return false;
3842
3843 if (cea_db_payload_len(db) < 7)
3844 return false;
3845
3846 oui = db[3] << 16 | db[2] << 8 | db[1];
3847
3848 return oui == HDMI_FORUM_IEEE_OUI;
3849}
3850
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02003851static bool cea_db_is_vcdb(const u8 *db)
3852{
3853 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3854 return false;
3855
3856 if (cea_db_payload_len(db) != 2)
3857 return false;
3858
3859 if (cea_db_extended_tag(db) != EXT_VIDEO_CAPABILITY_BLOCK)
3860 return false;
3861
3862 return true;
3863}
3864
Shashank Sharma832d4f22017-07-14 16:03:46 +05303865static bool cea_db_is_y420cmdb(const u8 *db)
3866{
3867 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3868 return false;
3869
3870 if (!cea_db_payload_len(db))
3871 return false;
3872
3873 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3874 return false;
3875
3876 return true;
3877}
3878
3879static bool cea_db_is_y420vdb(const u8 *db)
3880{
3881 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3882 return false;
3883
3884 if (!cea_db_payload_len(db))
3885 return false;
3886
3887 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3888 return false;
3889
3890 return true;
3891}
3892
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003893#define for_each_cea_db(cea, i, start, end) \
3894 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3895
Shashank Sharma832d4f22017-07-14 16:03:46 +05303896static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3897 const u8 *db)
3898{
3899 struct drm_display_info *info = &connector->display_info;
3900 struct drm_hdmi_info *hdmi = &info->hdmi;
3901 u8 map_len = cea_db_payload_len(db) - 1;
3902 u8 count;
3903 u64 map = 0;
3904
3905 if (map_len == 0) {
3906 /* All CEA modes support ycbcr420 sampling also.*/
3907 hdmi->y420_cmdb_map = U64_MAX;
3908 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3909 return;
3910 }
3911
3912 /*
3913 * This map indicates which of the existing CEA block modes
3914 * from VDB can support YCBCR420 output too. So if bit=0 is
3915 * set, first mode from VDB can support YCBCR420 output too.
3916 * We will parse and keep this map, before parsing VDB itself
3917 * to avoid going through the same block again and again.
3918 *
3919 * Spec is not clear about max possible size of this block.
3920 * Clamping max bitmap block size at 8 bytes. Every byte can
3921 * address 8 CEA modes, in this way this map can address
3922 * 8*8 = first 64 SVDs.
3923 */
3924 if (WARN_ON_ONCE(map_len > 8))
3925 map_len = 8;
3926
3927 for (count = 0; count < map_len; count++)
3928 map |= (u64)db[2 + count] << (8 * count);
3929
3930 if (map)
3931 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3932
3933 hdmi->y420_cmdb_map = map;
3934}
3935
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003936static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003937add_cea_modes(struct drm_connector *connector, struct edid *edid)
3938{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003939 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003940 const u8 *db, *hdmi = NULL, *video = NULL;
3941 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003942 int modes = 0;
3943
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003944 if (cea && cea_revision(cea) >= 3) {
3945 int i, start, end;
3946
3947 if (cea_db_offsets(cea, &start, &end))
3948 return 0;
3949
3950 for_each_cea_db(cea, i, start, end) {
3951 db = &cea[i];
3952 dbl = cea_db_payload_len(db);
3953
Thomas Woodfbf46022013-10-16 15:58:50 +01003954 if (cea_db_tag(db) == VIDEO_BLOCK) {
3955 video = db + 1;
3956 video_len = dbl;
3957 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05303958 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003959 hdmi = db;
3960 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303961 } else if (cea_db_is_y420vdb(db)) {
3962 const u8 *vdb420 = &db[2];
3963
3964 /* Add 4:2:0(only) modes present in EDID */
3965 modes += do_y420vdb_modes(connector,
3966 vdb420,
3967 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003968 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003969 }
3970 }
3971
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003972 /*
3973 * We parse the HDMI VSDB after having added the cea modes as we will
3974 * be patching their flags when the sink supports stereo 3D.
3975 */
3976 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003977 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3978 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003979
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003980 return modes;
3981}
3982
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003983static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3984{
3985 const struct drm_display_mode *cea_mode;
3986 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02003987 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003988 const char *type;
3989
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003990 /*
3991 * allow 5kHz clock difference either way to account for
3992 * the 10kHz clock resolution limit of detailed timings.
3993 */
Jani Nikulad9278b42016-01-08 13:21:51 +02003994 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
3995 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003996 type = "CEA";
Jani Nikulad9278b42016-01-08 13:21:51 +02003997 cea_mode = &edid_cea_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003998 clock1 = cea_mode->clock;
3999 clock2 = cea_mode_alternate_clock(cea_mode);
4000 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02004001 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
4002 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004003 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02004004 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004005 clock1 = cea_mode->clock;
4006 clock2 = hdmi_mode_alternate_clock(cea_mode);
4007 } else {
4008 return;
4009 }
4010 }
4011
4012 /* pick whichever is closest */
4013 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
4014 clock = clock1;
4015 else
4016 clock = clock2;
4017
4018 if (mode->clock == clock)
4019 return;
4020
4021 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02004022 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004023 mode->clock = clock;
4024}
4025
Uma Shankare85959d2019-05-16 19:40:08 +05304026static bool cea_db_is_hdmi_hdr_metadata_block(const u8 *db)
4027{
4028 if (cea_db_tag(db) != USE_EXTENDED_TAG)
4029 return false;
4030
4031 if (db[1] != HDR_STATIC_METADATA_BLOCK)
4032 return false;
4033
4034 if (cea_db_payload_len(db) < 3)
4035 return false;
4036
4037 return true;
4038}
4039
4040static uint8_t eotf_supported(const u8 *edid_ext)
4041{
4042 return edid_ext[2] &
4043 (BIT(HDMI_EOTF_TRADITIONAL_GAMMA_SDR) |
4044 BIT(HDMI_EOTF_TRADITIONAL_GAMMA_HDR) |
Ville Syrjäläb5e3eed2019-05-16 19:40:12 +05304045 BIT(HDMI_EOTF_SMPTE_ST2084) |
4046 BIT(HDMI_EOTF_BT_2100_HLG));
Uma Shankare85959d2019-05-16 19:40:08 +05304047}
4048
4049static uint8_t hdr_metadata_type(const u8 *edid_ext)
4050{
4051 return edid_ext[3] &
4052 BIT(HDMI_STATIC_METADATA_TYPE1);
4053}
4054
4055static void
4056drm_parse_hdr_metadata_block(struct drm_connector *connector, const u8 *db)
4057{
4058 u16 len;
4059
4060 len = cea_db_payload_len(db);
4061
4062 connector->hdr_sink_metadata.hdmi_type1.eotf =
4063 eotf_supported(db);
4064 connector->hdr_sink_metadata.hdmi_type1.metadata_type =
4065 hdr_metadata_type(db);
4066
4067 if (len >= 4)
4068 connector->hdr_sink_metadata.hdmi_type1.max_cll = db[4];
4069 if (len >= 5)
4070 connector->hdr_sink_metadata.hdmi_type1.max_fall = db[5];
4071 if (len >= 6)
4072 connector->hdr_sink_metadata.hdmi_type1.min_cll = db[6];
4073}
4074
Wu Fengguang76adaa342011-09-05 14:23:20 +08004075static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004076drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004077{
Ville Syrjälä85040722012-08-16 14:55:05 +00004078 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004079
Jani Nikulaf7da77852017-11-01 16:20:57 +02004080 if (len >= 6 && (db[6] & (1 << 7)))
4081 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
Ville Syrjälä85040722012-08-16 14:55:05 +00004082 if (len >= 8) {
4083 connector->latency_present[0] = db[8] >> 7;
4084 connector->latency_present[1] = (db[8] >> 6) & 1;
4085 }
4086 if (len >= 9)
4087 connector->video_latency[0] = db[9];
4088 if (len >= 10)
4089 connector->audio_latency[0] = db[10];
4090 if (len >= 11)
4091 connector->video_latency[1] = db[11];
4092 if (len >= 12)
4093 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004094
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004095 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
4096 "video latency %d %d, "
4097 "audio latency %d %d\n",
4098 connector->latency_present[0],
4099 connector->latency_present[1],
4100 connector->video_latency[0],
4101 connector->video_latency[1],
4102 connector->audio_latency[0],
4103 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004104}
4105
4106static void
4107monitor_name(struct detailed_timing *t, void *data)
4108{
4109 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
4110 *(u8 **)data = t->data.other_data.data.str.str;
4111}
4112
Jim Bride59f7c0f2016-04-14 10:18:35 -07004113static int get_monitor_name(struct edid *edid, char name[13])
4114{
4115 char *edid_name = NULL;
4116 int mnl;
4117
4118 if (!edid || !name)
4119 return 0;
4120
4121 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
4122 for (mnl = 0; edid_name && mnl < 13; mnl++) {
4123 if (edid_name[mnl] == 0x0a)
4124 break;
4125
4126 name[mnl] = edid_name[mnl];
4127 }
4128
4129 return mnl;
4130}
4131
4132/**
4133 * drm_edid_get_monitor_name - fetch the monitor name from the edid
4134 * @edid: monitor EDID information
4135 * @name: pointer to a character array to hold the name of the monitor
4136 * @bufsize: The size of the name buffer (should be at least 14 chars.)
4137 *
4138 */
4139void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
4140{
4141 int name_length;
4142 char buf[13];
4143
4144 if (bufsize <= 0)
4145 return;
4146
4147 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
4148 memcpy(name, buf, name_length);
4149 name[name_length] = '\0';
4150}
4151EXPORT_SYMBOL(drm_edid_get_monitor_name);
4152
Jani Nikula42750d32017-11-01 16:21:00 +02004153static void clear_eld(struct drm_connector *connector)
4154{
4155 memset(connector->eld, 0, sizeof(connector->eld));
4156
4157 connector->latency_present[0] = false;
4158 connector->latency_present[1] = false;
4159 connector->video_latency[0] = 0;
4160 connector->audio_latency[0] = 0;
4161 connector->video_latency[1] = 0;
4162 connector->audio_latency[1] = 0;
4163}
4164
Jani Nikula79436a12017-11-01 16:21:03 +02004165/*
Wu Fengguang76adaa342011-09-05 14:23:20 +08004166 * drm_edid_to_eld - build ELD from EDID
4167 * @connector: connector corresponding to the HDMI/DP sink
4168 * @edid: EDID to parse
4169 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004170 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
Jani Nikula1d1c3662017-11-01 16:20:58 +02004171 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004172 */
Jani Nikula79436a12017-11-01 16:21:03 +02004173static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004174{
4175 uint8_t *eld = connector->eld;
4176 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004177 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02004178 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004179 int mnl;
4180 int dbl;
4181
Jani Nikula42750d32017-11-01 16:21:00 +02004182 clear_eld(connector);
Ville Syrjälä85c91582016-09-28 16:51:34 +03004183
Jani Nikulae9bd0b82017-02-17 17:20:52 +02004184 if (!edid)
4185 return;
4186
Wu Fengguang76adaa342011-09-05 14:23:20 +08004187 cea = drm_find_cea_extension(edid);
4188 if (!cea) {
4189 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
4190 return;
4191 }
4192
Jani Nikulaf7da77852017-11-01 16:20:57 +02004193 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
4194 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
Jim Bride59f7c0f2016-04-14 10:18:35 -07004195
Jani Nikulaf7da77852017-11-01 16:20:57 +02004196 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
4197 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004198
Jani Nikulaf7da77852017-11-01 16:20:57 +02004199 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004200
Jani Nikulaf7da77852017-11-01 16:20:57 +02004201 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
4202 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
4203 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
4204 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004205
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004206 if (cea_revision(cea) >= 3) {
4207 int i, start, end;
4208
4209 if (cea_db_offsets(cea, &start, &end)) {
4210 start = 0;
4211 end = 0;
4212 }
4213
4214 for_each_cea_db(cea, i, start, end) {
4215 db = &cea[i];
4216 dbl = cea_db_payload_len(db);
4217
4218 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02004219 int sad_count;
4220
Christian Schmidta0ab7342011-12-19 20:03:38 +01004221 case AUDIO_BLOCK:
4222 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02004223 sad_count = min(dbl / 3, 15 - total_sad_count);
4224 if (sad_count >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004225 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
Ville Syrjälä7c018782016-03-09 22:07:46 +02004226 &db[1], sad_count * 3);
4227 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01004228 break;
4229 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004230 /* Speaker Allocation Data Block */
4231 if (dbl >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004232 eld[DRM_ELD_SPEAKER] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01004233 break;
4234 case VENDOR_BLOCK:
4235 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004236 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004237 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01004238 break;
4239 default:
4240 break;
4241 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08004242 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004243 }
Jani Nikulaf7da77852017-11-01 16:20:57 +02004244 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004245
Jani Nikula1d1c3662017-11-01 16:20:58 +02004246 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4247 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4248 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
4249 else
4250 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004251
Jani Nikula938fd8a2014-10-28 16:20:48 +02004252 eld[DRM_ELD_BASELINE_ELD_LEN] =
4253 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
4254
4255 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02004256 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004257}
Wu Fengguang76adaa342011-09-05 14:23:20 +08004258
4259/**
Rafał Miłeckife214162013-04-19 19:01:25 +02004260 * drm_edid_to_sad - extracts SADs from EDID
4261 * @edid: EDID to parse
4262 * @sads: pointer that will be set to the extracted SADs
4263 *
4264 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02004265 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004266 * Note: The returned pointer needs to be freed using kfree().
4267 *
4268 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02004269 */
4270int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
4271{
4272 int count = 0;
4273 int i, start, end, dbl;
4274 u8 *cea;
4275
4276 cea = drm_find_cea_extension(edid);
4277 if (!cea) {
4278 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4279 return -ENOENT;
4280 }
4281
4282 if (cea_revision(cea) < 3) {
4283 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Daniel Vetterc7581a42019-09-04 16:39:42 +02004284 return -EOPNOTSUPP;
Rafał Miłeckife214162013-04-19 19:01:25 +02004285 }
4286
4287 if (cea_db_offsets(cea, &start, &end)) {
4288 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4289 return -EPROTO;
4290 }
4291
4292 for_each_cea_db(cea, i, start, end) {
4293 u8 *db = &cea[i];
4294
4295 if (cea_db_tag(db) == AUDIO_BLOCK) {
4296 int j;
4297 dbl = cea_db_payload_len(db);
4298
4299 count = dbl / 3; /* SAD is 3B */
4300 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
4301 if (!*sads)
4302 return -ENOMEM;
4303 for (j = 0; j < count; j++) {
4304 u8 *sad = &db[1 + j * 3];
4305
4306 (*sads)[j].format = (sad[0] & 0x78) >> 3;
4307 (*sads)[j].channels = sad[0] & 0x7;
4308 (*sads)[j].freq = sad[1] & 0x7F;
4309 (*sads)[j].byte2 = sad[2];
4310 }
4311 break;
4312 }
4313 }
4314
4315 return count;
4316}
4317EXPORT_SYMBOL(drm_edid_to_sad);
4318
4319/**
Alex Deucherd105f472013-07-25 15:55:32 -04004320 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4321 * @edid: EDID to parse
4322 * @sadb: pointer to the speaker block
4323 *
4324 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04004325 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004326 * Note: The returned pointer needs to be freed using kfree().
4327 *
4328 * Return: The number of found Speaker Allocation Blocks or negative number on
4329 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004330 */
4331int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4332{
4333 int count = 0;
4334 int i, start, end, dbl;
4335 const u8 *cea;
4336
4337 cea = drm_find_cea_extension(edid);
4338 if (!cea) {
4339 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4340 return -ENOENT;
4341 }
4342
4343 if (cea_revision(cea) < 3) {
4344 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Daniel Vetterc7581a42019-09-04 16:39:42 +02004345 return -EOPNOTSUPP;
Alex Deucherd105f472013-07-25 15:55:32 -04004346 }
4347
4348 if (cea_db_offsets(cea, &start, &end)) {
4349 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4350 return -EPROTO;
4351 }
4352
4353 for_each_cea_db(cea, i, start, end) {
4354 const u8 *db = &cea[i];
4355
4356 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4357 dbl = cea_db_payload_len(db);
4358
4359 /* Speaker Allocation Data Block */
4360 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004361 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004362 if (!*sadb)
4363 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004364 count = dbl;
4365 break;
4366 }
4367 }
4368 }
4369
4370 return count;
4371}
4372EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4373
4374/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004375 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004376 * @connector: connector associated with the HDMI/DP sink
4377 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004378 *
4379 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4380 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004381 */
4382int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004383 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004384{
4385 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4386 int a, v;
4387
4388 if (!connector->latency_present[0])
4389 return 0;
4390 if (!connector->latency_present[1])
4391 i = 0;
4392
4393 a = connector->audio_latency[i];
4394 v = connector->video_latency[i];
4395
4396 /*
4397 * HDMI/DP sink doesn't support audio or video?
4398 */
4399 if (a == 255 || v == 255)
4400 return 0;
4401
4402 /*
4403 * Convert raw EDID values to millisecond.
4404 * Treat unknown latency as 0ms.
4405 */
4406 if (a)
4407 a = min(2 * (a - 1), 500);
4408 if (v)
4409 v = min(2 * (v - 1), 500);
4410
4411 return max(v - a, 0);
4412}
4413EXPORT_SYMBOL(drm_av_sync_delay);
4414
4415/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004416 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004417 * @edid: monitor EDID information
4418 *
4419 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004420 *
4421 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004422 */
4423bool drm_detect_hdmi_monitor(struct edid *edid)
4424{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004425 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004426 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004427 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004428
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004429 edid_ext = drm_find_cea_extension(edid);
4430 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004431 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004432
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004433 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004434 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004435
4436 /*
4437 * Because HDMI identifier is in Vendor Specific Block,
4438 * search it from all data blocks of CEA extension.
4439 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004440 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004441 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4442 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004443 }
4444
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004445 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004446}
4447EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4448
Dave Airlief453ba02008-11-07 14:05:41 -08004449/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004450 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004451 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004452 *
4453 * Monitor should have CEA extension block.
4454 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4455 * audio' only. If there is any audio extension block and supported
4456 * audio format, assume at least 'basic audio' support, even if 'basic
4457 * audio' is not defined in EDID.
4458 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004459 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004460 */
4461bool drm_detect_monitor_audio(struct edid *edid)
4462{
4463 u8 *edid_ext;
4464 int i, j;
4465 bool has_audio = false;
4466 int start_offset, end_offset;
4467
4468 edid_ext = drm_find_cea_extension(edid);
4469 if (!edid_ext)
4470 goto end;
4471
4472 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4473
4474 if (has_audio) {
4475 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4476 goto end;
4477 }
4478
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004479 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4480 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004481
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004482 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4483 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004484 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004485 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004486 DRM_DEBUG_KMS("CEA audio format %d\n",
4487 (edid_ext[i + j] >> 3) & 0xf);
4488 goto end;
4489 }
4490 }
4491end:
4492 return has_audio;
4493}
4494EXPORT_SYMBOL(drm_detect_monitor_audio);
4495
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004496
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004497/**
4498 * drm_default_rgb_quant_range - default RGB quantization range
4499 * @mode: display mode
4500 *
4501 * Determine the default RGB quantization range for the mode,
4502 * as specified in CEA-861.
4503 *
4504 * Return: The default RGB quantization range for the mode
4505 */
4506enum hdmi_quantization_range
4507drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4508{
4509 /* All CEA modes other than VIC 1 use limited quantization range. */
4510 return drm_match_cea_mode(mode) > 1 ?
4511 HDMI_QUANTIZATION_RANGE_LIMITED :
4512 HDMI_QUANTIZATION_RANGE_FULL;
4513}
4514EXPORT_SYMBOL(drm_default_rgb_quant_range);
4515
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004516static void drm_parse_vcdb(struct drm_connector *connector, const u8 *db)
4517{
4518 struct drm_display_info *info = &connector->display_info;
4519
4520 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", db[2]);
4521
4522 if (db[2] & EDID_CEA_VCDB_QS)
4523 info->rgb_quant_range_selectable = true;
4524}
4525
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304526static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4527 const u8 *db)
4528{
4529 u8 dc_mask;
4530 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4531
4532 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
Clint Taylor9068e022018-10-05 14:52:15 -07004533 hdmi->y420_dc_modes = dc_mask;
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304534}
4535
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304536static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4537 const u8 *hf_vsdb)
4538{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304539 struct drm_display_info *display = &connector->display_info;
4540 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304541
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004542 display->has_hdmi_infoframe = true;
4543
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304544 if (hf_vsdb[6] & 0x80) {
4545 hdmi->scdc.supported = true;
4546 if (hf_vsdb[6] & 0x40)
4547 hdmi->scdc.read_request = true;
4548 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304549
4550 /*
4551 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4552 * And as per the spec, three factors confirm this:
4553 * * Availability of a HF-VSDB block in EDID (check)
4554 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4555 * * SCDC support available (let's check)
4556 * Lets check it out.
4557 */
4558
4559 if (hf_vsdb[5]) {
4560 /* max clock is 5000 KHz times block value */
4561 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4562 struct drm_scdc *scdc = &hdmi->scdc;
4563
4564 if (max_tmds_clock > 340000) {
4565 display->max_tmds_clock = max_tmds_clock;
4566 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4567 display->max_tmds_clock);
4568 }
4569
4570 if (scdc->supported) {
4571 scdc->scrambling.supported = true;
4572
4573 /* Few sinks support scrambling for cloks < 340M */
4574 if ((hf_vsdb[6] & 0x8))
4575 scdc->scrambling.low_rates = true;
4576 }
4577 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304578
4579 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304580}
4581
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004582static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4583 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01004584{
Ville Syrjälä18267502016-09-28 16:51:38 +03004585 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004586 unsigned int dc_bpc = 0;
4587
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004588 /* HDMI supports at least 8 bpc */
4589 info->bpc = 8;
4590
4591 if (cea_db_payload_len(hdmi) < 6)
4592 return;
4593
4594 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4595 dc_bpc = 10;
4596 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4597 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4598 connector->name);
4599 }
4600
4601 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4602 dc_bpc = 12;
4603 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4604 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4605 connector->name);
4606 }
4607
4608 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4609 dc_bpc = 16;
4610 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4611 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4612 connector->name);
4613 }
4614
4615 if (dc_bpc == 0) {
4616 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4617 connector->name);
4618 return;
4619 }
4620
4621 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4622 connector->name, dc_bpc);
4623 info->bpc = dc_bpc;
4624
4625 /*
4626 * Deep color support mandates RGB444 support for all video
4627 * modes and forbids YCRCB422 support for all video modes per
4628 * HDMI 1.3 spec.
4629 */
4630 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4631
4632 /* YCRCB444 is optional according to spec. */
4633 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4634 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4635 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4636 connector->name);
4637 }
4638
4639 /*
4640 * Spec says that if any deep color mode is supported at all,
4641 * then deep color 36 bit must be supported.
4642 */
4643 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4644 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4645 connector->name);
4646 }
4647}
4648
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004649static void
4650drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4651{
4652 struct drm_display_info *info = &connector->display_info;
4653 u8 len = cea_db_payload_len(db);
4654
4655 if (len >= 6)
4656 info->dvi_dual = db[6] & 1;
4657 if (len >= 7)
4658 info->max_tmds_clock = db[7] * 5000;
4659
4660 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4661 "max TMDS clock %d kHz\n",
4662 info->dvi_dual,
4663 info->max_tmds_clock);
4664
4665 drm_parse_hdmi_deep_color_info(connector, db);
4666}
4667
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004668static void drm_parse_cea_ext(struct drm_connector *connector,
Keith Packard170178f2017-12-13 00:44:26 -08004669 const struct edid *edid)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004670{
4671 struct drm_display_info *info = &connector->display_info;
4672 const u8 *edid_ext;
4673 int i, start, end;
4674
Mario Kleinerd0c94692014-03-27 19:59:39 +01004675 edid_ext = drm_find_cea_extension(edid);
4676 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004677 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004678
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004679 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004680
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004681 /* The existence of a CEA block should imply RGB support */
4682 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4683 if (edid_ext[3] & EDID_CEA_YCRCB444)
4684 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4685 if (edid_ext[3] & EDID_CEA_YCRCB422)
4686 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004687
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004688 if (cea_db_offsets(edid_ext, &start, &end))
4689 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004690
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004691 for_each_cea_db(edid_ext, i, start, end) {
4692 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004693
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004694 if (cea_db_is_hdmi_vsdb(db))
4695 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304696 if (cea_db_is_hdmi_forum_vsdb(db))
4697 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304698 if (cea_db_is_y420cmdb(db))
4699 drm_parse_y420cmdb_bitmap(connector, db);
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004700 if (cea_db_is_vcdb(db))
4701 drm_parse_vcdb(connector, db);
Uma Shankare85959d2019-05-16 19:40:08 +05304702 if (cea_db_is_hdmi_hdr_metadata_block(db))
4703 drm_parse_hdr_metadata_block(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004704 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01004705}
4706
Keith Packard170178f2017-12-13 00:44:26 -08004707/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
4708 * all of the values which would have been set from EDID
4709 */
4710void
4711drm_reset_display_info(struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07004712{
Ville Syrjälä18267502016-09-28 16:51:38 +03004713 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07004714
Keith Packard170178f2017-12-13 00:44:26 -08004715 info->width_mm = 0;
4716 info->height_mm = 0;
4717
4718 info->bpc = 0;
4719 info->color_formats = 0;
4720 info->cea_rev = 0;
4721 info->max_tmds_clock = 0;
4722 info->dvi_dual = false;
4723 info->has_hdmi_infoframe = false;
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004724 info->rgb_quant_range_selectable = false;
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03004725 memset(&info->hdmi, 0, sizeof(info->hdmi));
Keith Packard170178f2017-12-13 00:44:26 -08004726
4727 info->non_desktop = 0;
4728}
Keith Packard170178f2017-12-13 00:44:26 -08004729
4730u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
4731{
4732 struct drm_display_info *info = &connector->display_info;
4733
4734 u32 quirks = edid_get_quirks(edid);
4735
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03004736 drm_reset_display_info(connector);
4737
Jesse Barnes3b112282011-04-15 12:49:23 -07004738 info->width_mm = edid->width_cm * 10;
4739 info->height_mm = edid->height_cm * 10;
4740
Dave Airlie66660d42017-10-16 05:08:09 +01004741 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4742
Keith Packard170178f2017-12-13 00:44:26 -08004743 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
4744
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004745 if (edid->revision < 3)
Keith Packard170178f2017-12-13 00:44:26 -08004746 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004747
4748 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
Keith Packard170178f2017-12-13 00:44:26 -08004749 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004750
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004751 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004752
Mario Kleiner210a0212016-07-06 12:05:48 +02004753 /*
4754 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4755 *
4756 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4757 * tells us to assume 8 bpc color depth if the EDID doesn't have
4758 * extensions which tell otherwise.
4759 */
Ville Syrjälä3bde4492019-05-29 14:02:04 +03004760 if (info->bpc == 0 && edid->revision == 3 &&
4761 edid->input & DRM_EDID_DIGITAL_DFP_1_X) {
Mario Kleiner210a0212016-07-06 12:05:48 +02004762 info->bpc = 8;
4763 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4764 connector->name, info->bpc);
4765 }
4766
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004767 /* Only defined for 1.4 with digital displays */
4768 if (edid->revision < 4)
Keith Packard170178f2017-12-13 00:44:26 -08004769 return quirks;
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004770
Jesse Barnes3b112282011-04-15 12:49:23 -07004771 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4772 case DRM_EDID_DIGITAL_DEPTH_6:
4773 info->bpc = 6;
4774 break;
4775 case DRM_EDID_DIGITAL_DEPTH_8:
4776 info->bpc = 8;
4777 break;
4778 case DRM_EDID_DIGITAL_DEPTH_10:
4779 info->bpc = 10;
4780 break;
4781 case DRM_EDID_DIGITAL_DEPTH_12:
4782 info->bpc = 12;
4783 break;
4784 case DRM_EDID_DIGITAL_DEPTH_14:
4785 info->bpc = 14;
4786 break;
4787 case DRM_EDID_DIGITAL_DEPTH_16:
4788 info->bpc = 16;
4789 break;
4790 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4791 default:
4792 info->bpc = 0;
4793 break;
4794 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004795
Mario Kleinerd0c94692014-03-27 19:59:39 +01004796 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004797 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004798
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004799 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004800 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4801 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4802 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4803 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Keith Packard170178f2017-12-13 00:44:26 -08004804 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004805}
4806
Dave Airliec97291772016-05-03 15:38:37 +10004807static int validate_displayid(u8 *displayid, int length, int idx)
4808{
4809 int i;
4810 u8 csum = 0;
4811 struct displayid_hdr *base;
4812
4813 base = (struct displayid_hdr *)&displayid[idx];
4814
4815 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4816 base->rev, base->bytes, base->prod_id, base->ext_count);
4817
4818 if (base->bytes + 5 > length - idx)
4819 return -EINVAL;
4820 for (i = idx; i <= base->bytes + 5; i++) {
4821 csum += displayid[i];
4822 }
4823 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004824 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004825 return -EINVAL;
4826 }
4827 return 0;
4828}
4829
Dave Airliea39ed682016-05-02 08:35:05 +10004830static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4831 struct displayid_detailed_timings_1 *timings)
4832{
4833 struct drm_display_mode *mode;
4834 unsigned pixel_clock = (timings->pixel_clock[0] |
4835 (timings->pixel_clock[1] << 8) |
4836 (timings->pixel_clock[2] << 16));
4837 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4838 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4839 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4840 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4841 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4842 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4843 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4844 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4845 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4846 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4847 mode = drm_mode_create(dev);
4848 if (!mode)
4849 return NULL;
4850
4851 mode->clock = pixel_clock * 10;
4852 mode->hdisplay = hactive;
4853 mode->hsync_start = mode->hdisplay + hsync;
4854 mode->hsync_end = mode->hsync_start + hsync_width;
4855 mode->htotal = mode->hdisplay + hblank;
4856
4857 mode->vdisplay = vactive;
4858 mode->vsync_start = mode->vdisplay + vsync;
4859 mode->vsync_end = mode->vsync_start + vsync_width;
4860 mode->vtotal = mode->vdisplay + vblank;
4861
4862 mode->flags = 0;
4863 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4864 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4865 mode->type = DRM_MODE_TYPE_DRIVER;
4866
4867 if (timings->flags & 0x80)
4868 mode->type |= DRM_MODE_TYPE_PREFERRED;
4869 mode->vrefresh = drm_mode_vrefresh(mode);
4870 drm_mode_set_name(mode);
4871
4872 return mode;
4873}
4874
4875static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4876 struct displayid_block *block)
4877{
4878 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4879 int i;
4880 int num_timings;
4881 struct drm_display_mode *newmode;
4882 int num_modes = 0;
4883 /* blocks must be multiple of 20 bytes length */
4884 if (block->num_bytes % 20)
4885 return 0;
4886
4887 num_timings = block->num_bytes / 20;
4888 for (i = 0; i < num_timings; i++) {
4889 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4890
4891 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4892 if (!newmode)
4893 continue;
4894
4895 drm_mode_probed_add(connector, newmode);
4896 num_modes++;
4897 }
4898 return num_modes;
4899}
4900
4901static int add_displayid_detailed_modes(struct drm_connector *connector,
4902 struct edid *edid)
4903{
4904 u8 *displayid;
4905 int ret;
4906 int idx = 1;
4907 int length = EDID_LENGTH;
4908 struct displayid_block *block;
4909 int num_modes = 0;
4910
4911 displayid = drm_find_displayid_extension(edid);
4912 if (!displayid)
4913 return 0;
4914
4915 ret = validate_displayid(displayid, length, idx);
4916 if (ret)
4917 return 0;
4918
4919 idx += sizeof(struct displayid_hdr);
Andres Rodriguez80d42db2019-06-19 14:30:33 -04004920 for_each_displayid_db(displayid, block, idx, length) {
Dave Airliea39ed682016-05-02 08:35:05 +10004921 switch (block->tag) {
4922 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4923 num_modes += add_displayid_detailed_1_modes(connector, block);
4924 break;
4925 }
4926 }
4927 return num_modes;
4928}
4929
Jesse Barnes3b112282011-04-15 12:49:23 -07004930/**
Dave Airlief453ba02008-11-07 14:05:41 -08004931 * drm_add_edid_modes - add modes from EDID data, if available
4932 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004933 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004934 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004935 * Add the specified modes to the connector's mode list. Also fills out the
Jani Nikulac945b8c2017-11-01 16:21:01 +02004936 * &drm_display_info structure and ELD in @connector with any information which
4937 * can be derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004938 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004939 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004940 */
4941int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4942{
4943 int num_modes = 0;
4944 u32 quirks;
4945
4946 if (edid == NULL) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004947 clear_eld(connector);
Dave Airlief453ba02008-11-07 14:05:41 -08004948 return 0;
4949 }
Alex Deucher3c537882010-02-05 04:21:19 -05004950 if (!drm_edid_is_valid(edid)) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004951 clear_eld(connector);
Jordan Crousedcdb1672010-05-27 13:40:25 -06004952 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004953 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004954 return 0;
4955 }
4956
Jani Nikulac945b8c2017-11-01 16:21:01 +02004957 drm_edid_to_eld(connector, edid);
4958
Adam Jacksonc867df72010-03-29 21:43:21 +00004959 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304960 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4961 * To avoid multiple parsing of same block, lets parse that map
4962 * from sink info, before parsing CEA modes.
4963 */
Keith Packard170178f2017-12-13 00:44:26 -08004964 quirks = drm_add_display_info(connector, edid);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304965
4966 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00004967 * EDID spec says modes should be preferred in this order:
4968 * - preferred detailed mode
4969 * - other detailed modes from base block
4970 * - detailed modes from extension blocks
4971 * - CVT 3-byte code modes
4972 * - standard timing codes
4973 * - established timing codes
4974 * - modes inferred from GTF or CVT range information
4975 *
Adam Jackson13931572010-08-03 14:38:19 -04004976 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00004977 *
4978 * XXX order for additional mode types in extension blocks?
4979 */
Adam Jackson13931572010-08-03 14:38:19 -04004980 num_modes += add_detailed_modes(connector, edid, quirks);
4981 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00004982 num_modes += add_standard_modes(connector, edid);
4983 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004984 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03004985 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10004986 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03004987 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
4988 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08004989
4990 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
4991 edid_fixup_preferred(connector, quirks);
4992
Mario Kleinere10aec62016-07-06 12:05:44 +02004993 if (quirks & EDID_QUIRK_FORCE_6BPC)
4994 connector->display_info.bpc = 6;
4995
Rafał Miłecki49d45a312013-12-07 13:22:42 +01004996 if (quirks & EDID_QUIRK_FORCE_8BPC)
4997 connector->display_info.bpc = 8;
4998
Mario Kleinere345da82017-04-21 17:05:08 +02004999 if (quirks & EDID_QUIRK_FORCE_10BPC)
5000 connector->display_info.bpc = 10;
5001
Mario Kleinerbc5b9642014-05-23 21:40:55 +02005002 if (quirks & EDID_QUIRK_FORCE_12BPC)
5003 connector->display_info.bpc = 12;
5004
Dave Airlief453ba02008-11-07 14:05:41 -08005005 return num_modes;
5006}
5007EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005008
5009/**
5010 * drm_add_modes_noedid - add modes for the connectors without EDID
5011 * @connector: connector we're probing
5012 * @hdisplay: the horizontal display limit
5013 * @vdisplay: the vertical display limit
5014 *
5015 * Add the specified modes to the connector's mode list. Only when the
5016 * hdisplay/vdisplay is not beyond the given limit, it will be added.
5017 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005018 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005019 */
5020int drm_add_modes_noedid(struct drm_connector *connector,
5021 int hdisplay, int vdisplay)
5022{
5023 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00005024 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005025 struct drm_device *dev = connector->dev;
5026
Daniel Vetterfbb40b22015-08-10 11:55:37 +02005027 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005028 if (hdisplay < 0)
5029 hdisplay = 0;
5030 if (vdisplay < 0)
5031 vdisplay = 0;
5032
5033 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00005034 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005035 if (hdisplay && vdisplay) {
5036 /*
5037 * Only when two are valid, they will be used to check
5038 * whether the mode should be added to the mode list of
5039 * the connector.
5040 */
5041 if (ptr->hdisplay > hdisplay ||
5042 ptr->vdisplay > vdisplay)
5043 continue;
5044 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05005045 if (drm_mode_vrefresh(ptr) > 61)
5046 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005047 mode = drm_mode_duplicate(dev, ptr);
5048 if (mode) {
5049 drm_mode_probed_add(connector, mode);
5050 num_modes++;
5051 }
5052 }
5053 return num_modes;
5054}
5055EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01005056
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005057/**
5058 * drm_set_preferred_mode - Sets the preferred mode of a connector
5059 * @connector: connector whose mode list should be processed
5060 * @hpref: horizontal resolution of preferred mode
5061 * @vpref: vertical resolution of preferred mode
5062 *
5063 * Marks a mode as preferred if it matches the resolution specified by @hpref
5064 * and @vpref.
5065 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02005066void drm_set_preferred_mode(struct drm_connector *connector,
5067 int hpref, int vpref)
5068{
5069 struct drm_display_mode *mode;
5070
5071 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005072 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01005073 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02005074 mode->type |= DRM_MODE_TYPE_PREFERRED;
5075 }
5076}
5077EXPORT_SYMBOL(drm_set_preferred_mode);
5078
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005079static bool is_hdmi2_sink(struct drm_connector *connector)
5080{
5081 /*
5082 * FIXME: sil-sii8620 doesn't have a connector around when
5083 * we need one, so we have to be prepared for a NULL connector.
5084 */
5085 if (!connector)
5086 return true;
5087
5088 return connector->display_info.hdmi.scdc.supported ||
5089 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCRCB420;
5090}
5091
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305092static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
5093{
5094 return sink_eotf & BIT(output_eotf);
5095}
5096
5097/**
5098 * drm_hdmi_infoframe_set_hdr_metadata() - fill an HDMI DRM infoframe with
5099 * HDR metadata from userspace
5100 * @frame: HDMI DRM infoframe
Sean Paul6ac98822019-05-23 09:54:58 -04005101 * @conn_state: Connector state containing HDR metadata
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305102 *
5103 * Return: 0 on success or a negative error code on failure.
5104 */
5105int
5106drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
5107 const struct drm_connector_state *conn_state)
5108{
5109 struct drm_connector *connector;
5110 struct hdr_output_metadata *hdr_metadata;
5111 int err;
5112
5113 if (!frame || !conn_state)
5114 return -EINVAL;
5115
5116 connector = conn_state->connector;
5117
5118 if (!conn_state->hdr_output_metadata)
5119 return -EINVAL;
5120
5121 hdr_metadata = conn_state->hdr_output_metadata->data;
5122
5123 if (!hdr_metadata || !connector)
5124 return -EINVAL;
5125
5126 /* Sink EOTF is Bit map while infoframe is absolute values */
5127 if (!is_eotf_supported(hdr_metadata->hdmi_metadata_type1.eotf,
5128 connector->hdr_sink_metadata.hdmi_type1.eotf)) {
5129 DRM_DEBUG_KMS("EOTF Not Supported\n");
5130 return -EINVAL;
5131 }
5132
5133 err = hdmi_drm_infoframe_init(frame);
5134 if (err < 0)
5135 return err;
5136
5137 frame->eotf = hdr_metadata->hdmi_metadata_type1.eotf;
5138 frame->metadata_type = hdr_metadata->hdmi_metadata_type1.metadata_type;
5139
5140 BUILD_BUG_ON(sizeof(frame->display_primaries) !=
5141 sizeof(hdr_metadata->hdmi_metadata_type1.display_primaries));
5142 BUILD_BUG_ON(sizeof(frame->white_point) !=
5143 sizeof(hdr_metadata->hdmi_metadata_type1.white_point));
5144
5145 memcpy(&frame->display_primaries,
5146 &hdr_metadata->hdmi_metadata_type1.display_primaries,
5147 sizeof(frame->display_primaries));
5148
5149 memcpy(&frame->white_point,
5150 &hdr_metadata->hdmi_metadata_type1.white_point,
5151 sizeof(frame->white_point));
5152
5153 frame->max_display_mastering_luminance =
5154 hdr_metadata->hdmi_metadata_type1.max_display_mastering_luminance;
5155 frame->min_display_mastering_luminance =
5156 hdr_metadata->hdmi_metadata_type1.min_display_mastering_luminance;
5157 frame->max_fall = hdr_metadata->hdmi_metadata_type1.max_fall;
5158 frame->max_cll = hdr_metadata->hdmi_metadata_type1.max_cll;
5159
5160 return 0;
5161}
5162EXPORT_SYMBOL(drm_hdmi_infoframe_set_hdr_metadata);
5163
Thierry Reding10a85122012-11-21 15:31:35 +01005164/**
5165 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
5166 * data from a DRM display mode
5167 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005168 * @connector: the connector
Thierry Reding10a85122012-11-21 15:31:35 +01005169 * @mode: DRM display mode
5170 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005171 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01005172 */
5173int
5174drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005175 struct drm_connector *connector,
5176 const struct drm_display_mode *mode)
Thierry Reding10a85122012-11-21 15:31:35 +01005177{
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305178 enum hdmi_picture_aspect picture_aspect;
Thierry Reding10a85122012-11-21 15:31:35 +01005179 int err;
5180
5181 if (!frame || !mode)
5182 return -EINVAL;
5183
5184 err = hdmi_avi_infoframe_init(frame);
5185 if (err < 0)
5186 return err;
5187
Damien Lespiaubf02db92013-08-06 20:32:22 +01005188 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
5189 frame->pixel_repeat = 1;
5190
Thierry Reding10a85122012-11-21 15:31:35 +01005191 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01005192
Shashank Sharma0c1f5282017-07-13 21:03:07 +05305193 /*
5194 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
5195 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
5196 * have to make sure we dont break HDMI 1.4 sinks.
5197 */
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005198 if (!is_hdmi2_sink(connector) && frame->video_code > 64)
Shashank Sharma0c1f5282017-07-13 21:03:07 +05305199 frame->video_code = 0;
5200
5201 /*
5202 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
5203 * we should send its VIC in vendor infoframes, else send the
5204 * VIC in AVI infoframes. Lets check if this mode is present in
5205 * HDMI 1.4b 4K modes
5206 */
5207 if (frame->video_code) {
5208 u8 vendor_if_vic = drm_match_hdmi_mode(mode);
5209 bool is_s3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
5210
5211 if (drm_valid_hdmi_vic(vendor_if_vic) && !is_s3d)
5212 frame->video_code = 0;
5213 }
5214
Thierry Reding10a85122012-11-21 15:31:35 +01005215 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305216
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305217 /*
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +03005218 * As some drivers don't support atomic, we can't use connector state.
5219 * So just initialize the frame with default values, just the same way
5220 * as it's done with other properties here.
5221 */
5222 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
5223 frame->itc = 0;
5224
5225 /*
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305226 * Populate picture aspect ratio from either
5227 * user input (if specified) or from the CEA mode list.
5228 */
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305229 picture_aspect = mode->picture_aspect_ratio;
5230 if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
5231 picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305232
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305233 /*
5234 * The infoframe can't convey anything but none, 4:3
5235 * and 16:9, so if the user has asked for anything else
5236 * we can only satisfy it by specifying the right VIC.
5237 */
5238 if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
5239 if (picture_aspect !=
5240 drm_get_cea_aspect_ratio(frame->video_code))
5241 return -EINVAL;
5242 picture_aspect = HDMI_PICTURE_ASPECT_NONE;
5243 }
5244
5245 frame->picture_aspect = picture_aspect;
Thierry Reding10a85122012-11-21 15:31:35 +01005246 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06005247 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01005248
5249 return 0;
5250}
5251EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005252
Uma Shankar0d68b882019-02-19 22:43:00 +05305253/* HDMI Colorspace Spec Definitions */
5254#define FULL_COLORIMETRY_MASK 0x1FF
5255#define NORMAL_COLORIMETRY_MASK 0x3
5256#define EXTENDED_COLORIMETRY_MASK 0x7
5257#define EXTENDED_ACE_COLORIMETRY_MASK 0xF
5258
5259#define C(x) ((x) << 0)
5260#define EC(x) ((x) << 2)
5261#define ACE(x) ((x) << 5)
5262
5263#define HDMI_COLORIMETRY_NO_DATA 0x0
5264#define HDMI_COLORIMETRY_SMPTE_170M_YCC (C(1) | EC(0) | ACE(0))
5265#define HDMI_COLORIMETRY_BT709_YCC (C(2) | EC(0) | ACE(0))
5266#define HDMI_COLORIMETRY_XVYCC_601 (C(3) | EC(0) | ACE(0))
5267#define HDMI_COLORIMETRY_XVYCC_709 (C(3) | EC(1) | ACE(0))
5268#define HDMI_COLORIMETRY_SYCC_601 (C(3) | EC(2) | ACE(0))
5269#define HDMI_COLORIMETRY_OPYCC_601 (C(3) | EC(3) | ACE(0))
5270#define HDMI_COLORIMETRY_OPRGB (C(3) | EC(4) | ACE(0))
5271#define HDMI_COLORIMETRY_BT2020_CYCC (C(3) | EC(5) | ACE(0))
5272#define HDMI_COLORIMETRY_BT2020_RGB (C(3) | EC(6) | ACE(0))
5273#define HDMI_COLORIMETRY_BT2020_YCC (C(3) | EC(6) | ACE(0))
5274#define HDMI_COLORIMETRY_DCI_P3_RGB_D65 (C(3) | EC(7) | ACE(0))
5275#define HDMI_COLORIMETRY_DCI_P3_RGB_THEATER (C(3) | EC(7) | ACE(1))
5276
5277static const u32 hdmi_colorimetry_val[] = {
5278 [DRM_MODE_COLORIMETRY_NO_DATA] = HDMI_COLORIMETRY_NO_DATA,
5279 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = HDMI_COLORIMETRY_SMPTE_170M_YCC,
5280 [DRM_MODE_COLORIMETRY_BT709_YCC] = HDMI_COLORIMETRY_BT709_YCC,
5281 [DRM_MODE_COLORIMETRY_XVYCC_601] = HDMI_COLORIMETRY_XVYCC_601,
5282 [DRM_MODE_COLORIMETRY_XVYCC_709] = HDMI_COLORIMETRY_XVYCC_709,
5283 [DRM_MODE_COLORIMETRY_SYCC_601] = HDMI_COLORIMETRY_SYCC_601,
5284 [DRM_MODE_COLORIMETRY_OPYCC_601] = HDMI_COLORIMETRY_OPYCC_601,
5285 [DRM_MODE_COLORIMETRY_OPRGB] = HDMI_COLORIMETRY_OPRGB,
5286 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = HDMI_COLORIMETRY_BT2020_CYCC,
5287 [DRM_MODE_COLORIMETRY_BT2020_RGB] = HDMI_COLORIMETRY_BT2020_RGB,
5288 [DRM_MODE_COLORIMETRY_BT2020_YCC] = HDMI_COLORIMETRY_BT2020_YCC,
5289};
5290
5291#undef C
5292#undef EC
5293#undef ACE
5294
5295/**
5296 * drm_hdmi_avi_infoframe_colorspace() - fill the HDMI AVI infoframe
5297 * colorspace information
5298 * @frame: HDMI AVI infoframe
5299 * @conn_state: connector state
5300 */
5301void
5302drm_hdmi_avi_infoframe_colorspace(struct hdmi_avi_infoframe *frame,
5303 const struct drm_connector_state *conn_state)
5304{
5305 u32 colorimetry_val;
5306 u32 colorimetry_index = conn_state->colorspace & FULL_COLORIMETRY_MASK;
5307
5308 if (colorimetry_index >= ARRAY_SIZE(hdmi_colorimetry_val))
5309 colorimetry_val = HDMI_COLORIMETRY_NO_DATA;
5310 else
5311 colorimetry_val = hdmi_colorimetry_val[colorimetry_index];
5312
5313 frame->colorimetry = colorimetry_val & NORMAL_COLORIMETRY_MASK;
5314 /*
5315 * ToDo: Extend it for ACE formats as well. Modify the infoframe
5316 * structure and extend it in drivers/video/hdmi
5317 */
5318 frame->extended_colorimetry = (colorimetry_val >> 2) &
5319 EXTENDED_COLORIMETRY_MASK;
5320}
5321EXPORT_SYMBOL(drm_hdmi_avi_infoframe_colorspace);
5322
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005323/**
5324 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
5325 * quantization range information
5326 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005327 * @connector: the connector
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005328 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005329 * @rgb_quant_range: RGB quantization range (Q)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005330 */
5331void
5332drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005333 struct drm_connector *connector,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005334 const struct drm_display_mode *mode,
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005335 enum hdmi_quantization_range rgb_quant_range)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005336{
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005337 const struct drm_display_info *info = &connector->display_info;
5338
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005339 /*
5340 * CEA-861:
5341 * "A Source shall not send a non-zero Q value that does not correspond
5342 * to the default RGB Quantization Range for the transmitted Picture
5343 * unless the Sink indicates support for the Q bit in a Video
5344 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005345 *
5346 * HDMI 2.0 recommends sending non-zero Q when it does match the
5347 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005348 */
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005349 if (info->rgb_quant_range_selectable ||
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005350 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005351 frame->quantization_range = rgb_quant_range;
5352 else
5353 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005354
5355 /*
5356 * CEA-861-F:
5357 * "When transmitting any RGB colorimetry, the Source should set the
5358 * YQ-field to match the RGB Quantization Range being transmitted
5359 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
5360 * set YQ=1) and the Sink shall ignore the YQ-field."
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005361 *
5362 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
5363 * by non-zero YQ when receiving RGB. There doesn't seem to be any
5364 * good way to tell which version of CEA-861 the sink supports, so
5365 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
5366 * on on CEA-861-F.
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005367 */
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005368 if (!is_hdmi2_sink(connector) ||
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005369 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005370 frame->ycc_quantization_range =
5371 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
5372 else
5373 frame->ycc_quantization_range =
5374 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005375}
5376EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
5377
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005378static enum hdmi_3d_structure
5379s3d_structure_from_display_mode(const struct drm_display_mode *mode)
5380{
5381 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
5382
5383 switch (layout) {
5384 case DRM_MODE_FLAG_3D_FRAME_PACKING:
5385 return HDMI_3D_STRUCTURE_FRAME_PACKING;
5386 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
5387 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
5388 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
5389 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
5390 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
5391 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
5392 case DRM_MODE_FLAG_3D_L_DEPTH:
5393 return HDMI_3D_STRUCTURE_L_DEPTH;
5394 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
5395 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
5396 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
5397 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
5398 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
5399 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
5400 default:
5401 return HDMI_3D_STRUCTURE_INVALID;
5402 }
5403}
5404
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005405/**
5406 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
5407 * data from a DRM display mode
5408 * @frame: HDMI vendor infoframe
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005409 * @connector: the connector
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005410 * @mode: DRM display mode
5411 *
5412 * Note that there's is a need to send HDMI vendor infoframes only when using a
5413 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
5414 * function will return -EINVAL, error that can be safely ignored.
5415 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005416 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005417 */
5418int
5419drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005420 struct drm_connector *connector,
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005421 const struct drm_display_mode *mode)
5422{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005423 /*
5424 * FIXME: sil-sii8620 doesn't have a connector around when
5425 * we need one, so we have to be prepared for a NULL connector.
5426 */
5427 bool has_hdmi_infoframe = connector ?
5428 connector->display_info.has_hdmi_infoframe : false;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005429 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005430 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005431 u8 vic;
5432
5433 if (!frame || !mode)
5434 return -EINVAL;
5435
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005436 if (!has_hdmi_infoframe)
5437 return -EINVAL;
5438
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005439 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005440 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
5441
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005442 /*
5443 * Even if it's not absolutely necessary to send the infoframe
5444 * (ie.vic==0 and s3d_struct==0) we will still send it if we
5445 * know that the sink can handle it. This is based on a
5446 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
5447 * have trouble realizing that they shuld switch from 3D to 2D
5448 * mode if the source simply stops sending the infoframe when
5449 * it wants to switch from 3D to 2D.
5450 */
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005451
5452 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005453 return -EINVAL;
5454
5455 err = hdmi_vendor_infoframe_init(frame);
5456 if (err < 0)
5457 return err;
5458
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005459 frame->vic = vic;
5460 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005461
5462 return 0;
5463}
5464EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10005465
Dave Airlie5e546cd2016-05-03 15:31:12 +10005466static int drm_parse_tiled_block(struct drm_connector *connector,
5467 struct displayid_block *block)
5468{
5469 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
5470 u16 w, h;
5471 u8 tile_v_loc, tile_h_loc;
5472 u8 num_v_tile, num_h_tile;
5473 struct drm_tile_group *tg;
5474
5475 w = tile->tile_size[0] | tile->tile_size[1] << 8;
5476 h = tile->tile_size[2] | tile->tile_size[3] << 8;
5477
5478 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
5479 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
5480 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
5481 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
5482
5483 connector->has_tile = true;
5484 if (tile->tile_cap & 0x80)
5485 connector->tile_is_single_monitor = true;
5486
5487 connector->num_h_tile = num_h_tile + 1;
5488 connector->num_v_tile = num_v_tile + 1;
5489 connector->tile_h_loc = tile_h_loc;
5490 connector->tile_v_loc = tile_v_loc;
5491 connector->tile_h_size = w + 1;
5492 connector->tile_v_size = h + 1;
5493
5494 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
5495 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
5496 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
5497 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
5498 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
5499
5500 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
5501 if (!tg) {
5502 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
5503 }
5504 if (!tg)
5505 return -ENOMEM;
5506
5507 if (connector->tile_group != tg) {
5508 /* if we haven't got a pointer,
5509 take the reference, drop ref to old tile group */
5510 if (connector->tile_group) {
5511 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5512 }
5513 connector->tile_group = tg;
5514 } else
5515 /* if same tile group, then release the ref we just took. */
5516 drm_mode_put_tile_group(connector->dev, tg);
5517 return 0;
5518}
5519
Dave Airlie40d9b042014-10-20 16:29:33 +10005520static int drm_parse_display_id(struct drm_connector *connector,
5521 u8 *displayid, int length,
5522 bool is_edid_extension)
5523{
5524 /* if this is an EDID extension the first byte will be 0x70 */
5525 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10005526 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10005527 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005528
5529 if (is_edid_extension)
5530 idx = 1;
5531
Dave Airliec97291772016-05-03 15:38:37 +10005532 ret = validate_displayid(displayid, length, idx);
5533 if (ret)
5534 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005535
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005536 idx += sizeof(struct displayid_hdr);
Andres Rodriguez80d42db2019-06-19 14:30:33 -04005537 for_each_displayid_db(displayid, block, idx, length) {
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005538 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5539 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10005540
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005541 switch (block->tag) {
5542 case DATA_BLOCK_TILED_DISPLAY:
5543 ret = drm_parse_tiled_block(connector, block);
5544 if (ret)
5545 return ret;
5546 break;
Dave Airliea39ed682016-05-02 08:35:05 +10005547 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5548 /* handled in mode gathering code. */
5549 break;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04005550 case DATA_BLOCK_CTA:
5551 /* handled in the cea parser code. */
5552 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005553 default:
5554 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5555 break;
5556 }
Dave Airlie40d9b042014-10-20 16:29:33 +10005557 }
5558 return 0;
5559}
5560
5561static void drm_get_displayid(struct drm_connector *connector,
5562 struct edid *edid)
5563{
5564 void *displayid = NULL;
5565 int ret;
5566 connector->has_tile = false;
5567 displayid = drm_find_displayid_extension(edid);
5568 if (!displayid) {
5569 /* drop reference to any tile group we had */
5570 goto out_drop_ref;
5571 }
5572
5573 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5574 if (ret < 0)
5575 goto out_drop_ref;
5576 if (!connector->has_tile)
5577 goto out_drop_ref;
5578 return;
5579out_drop_ref:
5580 if (connector->tile_group) {
5581 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5582 connector->tile_group = NULL;
5583 }
5584 return;
5585}