blob: 12c783f4d95661a758c1e579ef9e3445d42290e1 [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, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001278};
1279
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001280/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001281 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001282 */
1283static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001284 /* 0 - dummy, VICs start at 1 */
1285 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001286 /* 1 - 3840x2160@30Hz */
1287 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1288 3840, 4016, 4104, 4400, 0,
1289 2160, 2168, 2178, 2250, 0,
1290 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1291 .vrefresh = 30, },
1292 /* 2 - 3840x2160@25Hz */
1293 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1294 3840, 4896, 4984, 5280, 0,
1295 2160, 2168, 2178, 2250, 0,
1296 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1297 .vrefresh = 25, },
1298 /* 3 - 3840x2160@24Hz */
1299 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1300 3840, 5116, 5204, 5500, 0,
1301 2160, 2168, 2178, 2250, 0,
1302 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1303 .vrefresh = 24, },
1304 /* 4 - 4096x2160@24Hz (SMPTE) */
1305 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1306 4096, 5116, 5204, 5500, 0,
1307 2160, 2168, 2178, 2250, 0,
1308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1309 .vrefresh = 24, },
1310};
1311
Adam Jackson61e57a82010-03-29 21:43:18 +00001312/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001313
Adam Jackson083ae052009-09-23 17:30:45 -04001314static const u8 edid_header[] = {
1315 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1316};
Dave Airlief453ba02008-11-07 14:05:41 -08001317
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001318/**
1319 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1320 * @raw_edid: pointer to raw base EDID block
1321 *
1322 * Sanity check the header of the base EDID block.
1323 *
1324 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001325 */
1326int drm_edid_header_is_valid(const u8 *raw_edid)
1327{
1328 int i, score = 0;
1329
1330 for (i = 0; i < sizeof(edid_header); i++)
1331 if (raw_edid[i] == edid_header[i])
1332 score++;
1333
1334 return score;
1335}
1336EXPORT_SYMBOL(drm_edid_header_is_valid);
1337
Adam Jackson47819ba2012-05-30 16:42:39 -04001338static int edid_fixup __read_mostly = 6;
1339module_param_named(edid_fixup, edid_fixup, int, 0400);
1340MODULE_PARM_DESC(edid_fixup,
1341 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001342
Dave Airlie40d9b042014-10-20 16:29:33 +10001343static void drm_get_displayid(struct drm_connector *connector,
1344 struct edid *edid);
Andres Rodrigueze28ad542019-06-19 14:09:01 -04001345static int validate_displayid(u8 *displayid, int length, int idx);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001346
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001347static int drm_edid_block_checksum(const u8 *raw_edid)
1348{
1349 int i;
1350 u8 csum = 0;
1351 for (i = 0; i < EDID_LENGTH; i++)
1352 csum += raw_edid[i];
1353
1354 return csum;
1355}
1356
Stefan Brünsd6885d62014-11-30 19:57:41 +01001357static bool drm_edid_is_zero(const u8 *in_edid, int length)
1358{
1359 if (memchr_inv(in_edid, 0, length))
1360 return false;
1361
1362 return true;
1363}
1364
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001365/**
1366 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1367 * @raw_edid: pointer to raw EDID block
1368 * @block: type of block to validate (0 for base, extension otherwise)
1369 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001370 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001371 *
1372 * Validate a base or extension EDID block and optionally dump bad blocks to
1373 * the console.
1374 *
1375 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001376 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001377bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1378 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001379{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001380 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001381 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001382
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001383 if (WARN_ON(!raw_edid))
1384 return false;
1385
Adam Jackson47819ba2012-05-30 16:42:39 -04001386 if (edid_fixup > 8 || edid_fixup < 0)
1387 edid_fixup = 6;
1388
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001389 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001390 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001391 if (score == 8) {
1392 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001393 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001394 } else if (score >= edid_fixup) {
1395 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1396 * The corrupt flag needs to be set here otherwise, the
1397 * fix-up code here will correct the problem, the
1398 * checksum is correct and the test fails
1399 */
1400 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001401 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001402 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1403 memcpy(raw_edid, edid_header, sizeof(edid_header));
1404 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001405 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001406 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001407 goto bad;
1408 }
1409 }
Dave Airlief453ba02008-11-07 14:05:41 -08001410
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001411 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001412 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001413 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001414 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001415
Adam Jackson4a638b42010-05-25 16:33:09 -04001416 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001417 if (raw_edid[0] == CEA_EXT) {
1418 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1419 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1420 } else {
1421 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001422 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001423
Adam Jackson4a638b42010-05-25 16:33:09 -04001424 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001425 }
Dave Airlief453ba02008-11-07 14:05:41 -08001426 }
1427
Adam Jackson61e57a82010-03-29 21:43:18 +00001428 /* per-block-type checks */
1429 switch (raw_edid[0]) {
1430 case 0: /* base */
1431 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001432 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001433 goto bad;
1434 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001435
Adam Jackson61e57a82010-03-29 21:43:18 +00001436 if (edid->revision > 4)
1437 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1438 break;
1439
1440 default:
1441 break;
1442 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001443
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001444 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001445
1446bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001447 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001448 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001449 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001450 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001451 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001452 print_hex_dump(KERN_NOTICE,
1453 " \t", DUMP_PREFIX_NONE, 16, 1,
1454 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001455 }
Dave Airlief453ba02008-11-07 14:05:41 -08001456 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001457 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001458}
Carsten Emdeda0df922012-03-18 22:37:33 +01001459EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001460
1461/**
1462 * drm_edid_is_valid - sanity check EDID data
1463 * @edid: EDID data
1464 *
1465 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001466 *
1467 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001468 */
1469bool drm_edid_is_valid(struct edid *edid)
1470{
1471 int i;
1472 u8 *raw = (u8 *)edid;
1473
1474 if (!edid)
1475 return false;
1476
1477 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001478 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001479 return false;
1480
1481 return true;
1482}
Alex Deucher3c537882010-02-05 04:21:19 -05001483EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001484
Adam Jackson61e57a82010-03-29 21:43:18 +00001485#define DDC_SEGMENT_ADDR 0x30
1486/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001487 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001488 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001489 * @buf: EDID data buffer to be filled
1490 * @block: 128 byte EDID block to start fetching from
1491 * @len: EDID data buffer length to fetch
1492 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001493 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001494 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001495 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001496 */
1497static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001498drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001499{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001500 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001501 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001502 unsigned char segment = block >> 1;
1503 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001504 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001505
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001506 /*
1507 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001508 * adapter reports EAGAIN. However, we find that bit-banging transfers
1509 * are susceptible to errors under a heavily loaded machine and
1510 * generate spurious NAKs and timeouts. Retrying the transfer
1511 * of the individual block a few times seems to overcome this.
1512 */
1513 do {
1514 struct i2c_msg msgs[] = {
1515 {
Shirish Scd004b32012-08-30 07:04:06 +00001516 .addr = DDC_SEGMENT_ADDR,
1517 .flags = 0,
1518 .len = 1,
1519 .buf = &segment,
1520 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001521 .addr = DDC_ADDR,
1522 .flags = 0,
1523 .len = 1,
1524 .buf = &start,
1525 }, {
1526 .addr = DDC_ADDR,
1527 .flags = I2C_M_RD,
1528 .len = len,
1529 .buf = buf,
1530 }
1531 };
Shirish Scd004b32012-08-30 07:04:06 +00001532
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001533 /*
1534 * Avoid sending the segment addr to not upset non-compliant
1535 * DDC monitors.
1536 */
Shirish Scd004b32012-08-30 07:04:06 +00001537 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1538
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001539 if (ret == -ENXIO) {
1540 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1541 adapter->name);
1542 break;
1543 }
Shirish Scd004b32012-08-30 07:04:06 +00001544 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001545
Shirish Scd004b32012-08-30 07:04:06 +00001546 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001547}
1548
Chris Wilson14544d02016-10-24 12:38:21 +01001549static void connector_bad_edid(struct drm_connector *connector,
1550 u8 *edid, int num_blocks)
1551{
1552 int i;
1553
1554 if (connector->bad_edid_counter++ && !(drm_debug & DRM_UT_KMS))
1555 return;
1556
1557 dev_warn(connector->dev->dev,
1558 "%s: EDID is invalid:\n",
1559 connector->name);
1560 for (i = 0; i < num_blocks; i++) {
1561 u8 *block = edid + i * EDID_LENGTH;
1562 char prefix[20];
1563
1564 if (drm_edid_is_zero(block, EDID_LENGTH))
1565 sprintf(prefix, "\t[%02x] ZERO ", i);
1566 else if (!drm_edid_block_valid(block, i, false, NULL))
1567 sprintf(prefix, "\t[%02x] BAD ", i);
1568 else
1569 sprintf(prefix, "\t[%02x] GOOD ", i);
1570
1571 print_hex_dump(KERN_WARNING,
1572 prefix, DUMP_PREFIX_NONE, 16, 1,
1573 block, EDID_LENGTH, false);
1574 }
1575}
1576
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001577/* Get override or firmware EDID */
1578static struct edid *drm_get_override_edid(struct drm_connector *connector)
1579{
1580 struct edid *override = NULL;
1581
1582 if (connector->override_edid)
1583 override = drm_edid_duplicate(connector->edid_blob_ptr->data);
1584
1585 if (!override)
1586 override = drm_load_edid_firmware(connector);
1587
1588 return IS_ERR(override) ? NULL : override;
1589}
1590
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001591/**
Jani Nikula48eaeb72019-06-10 12:30:54 +03001592 * drm_add_override_edid_modes - add modes from override/firmware EDID
1593 * @connector: connector we're probing
1594 *
1595 * Add modes from the override/firmware EDID, if available. Only to be used from
1596 * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe
1597 * failed during drm_get_edid() and caused the override/firmware EDID to be
1598 * skipped.
1599 *
1600 * Return: The number of modes added or 0 if we couldn't find any.
1601 */
1602int drm_add_override_edid_modes(struct drm_connector *connector)
1603{
1604 struct edid *override;
1605 int num_modes = 0;
1606
1607 override = drm_get_override_edid(connector);
1608 if (override) {
1609 drm_connector_update_edid_property(connector, override);
1610 num_modes = drm_add_edid_modes(connector, override);
1611 kfree(override);
1612
1613 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] adding %d modes via fallback override/firmware EDID\n",
1614 connector->base.id, connector->name, num_modes);
1615 }
1616
1617 return num_modes;
1618}
1619EXPORT_SYMBOL(drm_add_override_edid_modes);
1620
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001621/**
1622 * drm_do_get_edid - get EDID data using a custom EDID block read function
1623 * @connector: connector we're probing
1624 * @get_edid_block: EDID block read function
1625 * @data: private data passed to the block read function
1626 *
1627 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1628 * exposes a different interface to read EDID blocks this function can be used
1629 * to get EDID data using a custom block read function.
1630 *
1631 * As in the general case the DDC bus is accessible by the kernel at the I2C
1632 * level, drivers must make all reasonable efforts to expose it as an I2C
1633 * adapter and use drm_get_edid() instead of abusing this function.
1634 *
Jani Nikula53fd40a2017-09-12 11:19:26 +03001635 * The EDID may be overridden using debugfs override_edid or firmare EDID
1636 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1637 * order. Having either of them bypasses actual EDID reads.
1638 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001639 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1640 */
1641struct edid *drm_do_get_edid(struct drm_connector *connector,
1642 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1643 size_t len),
1644 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001645{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001646 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001647 u8 *edid, *new;
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001648 struct edid *override;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001649
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001650 override = drm_get_override_edid(connector);
1651 if (override)
Jani Nikula53fd40a2017-09-12 11:19:26 +03001652 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001653
Chris Wilsonf14f3682016-10-17 09:35:12 +01001654 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001655 return NULL;
1656
1657 /* base block fetch */
1658 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001659 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001660 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001661 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001662 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001663 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001664 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001665 connector->null_edid_counter++;
1666 goto carp;
1667 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001668 }
1669 if (i == 4)
1670 goto carp;
1671
1672 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001673 valid_extensions = edid[0x7e];
1674 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001675 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001676
Chris Wilson14544d02016-10-24 12:38:21 +01001677 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001678 if (!new)
1679 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001680 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001681
Chris Wilsonf14f3682016-10-17 09:35:12 +01001682 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001683 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001684
Adam Jackson61e57a82010-03-29 21:43:18 +00001685 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001686 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001687 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001688 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001689 break;
1690 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001691
Chris Wilson14544d02016-10-24 12:38:21 +01001692 if (i == 4)
1693 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001694 }
1695
Chris Wilsonf14f3682016-10-17 09:35:12 +01001696 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001697 u8 *base;
1698
1699 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1700
Chris Wilsonf14f3682016-10-17 09:35:12 +01001701 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1702 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001703
Kees Cook6da2ec52018-06-12 13:55:00 -07001704 new = kmalloc_array(valid_extensions + 1, EDID_LENGTH,
1705 GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001706 if (!new)
1707 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001708
1709 base = new;
1710 for (i = 0; i <= edid[0x7e]; i++) {
1711 u8 *block = edid + i * EDID_LENGTH;
1712
1713 if (!drm_edid_block_valid(block, i, false, NULL))
1714 continue;
1715
1716 memcpy(base, block, EDID_LENGTH);
1717 base += EDID_LENGTH;
1718 }
1719
1720 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001721 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001722 }
1723
Chris Wilsonf14f3682016-10-17 09:35:12 +01001724 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001725
1726carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001727 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001728out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001729 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001730 return NULL;
1731}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001732EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001733
1734/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001735 * drm_probe_ddc() - probe DDC presence
1736 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001737 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001738 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001739 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001740bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001741drm_probe_ddc(struct i2c_adapter *adapter)
1742{
1743 unsigned char out;
1744
1745 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1746}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001747EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001748
1749/**
1750 * drm_get_edid - get EDID data, if available
1751 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001752 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001753 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001754 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001755 * attach it to the connector.
1756 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001757 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001758 */
1759struct edid *drm_get_edid(struct drm_connector *connector,
1760 struct i2c_adapter *adapter)
1761{
Dave Airlie40d9b042014-10-20 16:29:33 +10001762 struct edid *edid;
1763
Jani Nikula15f080f2017-02-17 17:20:53 +02001764 if (connector->force == DRM_FORCE_OFF)
1765 return NULL;
1766
1767 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001768 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001769
Dave Airlie40d9b042014-10-20 16:29:33 +10001770 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1771 if (edid)
1772 drm_get_displayid(connector, edid);
1773 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001774}
1775EXPORT_SYMBOL(drm_get_edid);
1776
Jani Nikula51f8da52013-09-27 15:08:27 +03001777/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001778 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1779 * @connector: connector we're probing
1780 * @adapter: I2C adapter to use for DDC
1781 *
1782 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1783 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1784 * switch DDC to the GPU which is retrieving EDID.
1785 *
1786 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1787 */
1788struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1789 struct i2c_adapter *adapter)
1790{
1791 struct pci_dev *pdev = connector->dev->pdev;
1792 struct edid *edid;
1793
1794 vga_switcheroo_lock_ddc(pdev);
1795 edid = drm_get_edid(connector, adapter);
1796 vga_switcheroo_unlock_ddc(pdev);
1797
1798 return edid;
1799}
1800EXPORT_SYMBOL(drm_get_edid_switcheroo);
1801
1802/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001803 * drm_edid_duplicate - duplicate an EDID and the extensions
1804 * @edid: EDID to duplicate
1805 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001806 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001807 */
1808struct edid *drm_edid_duplicate(const struct edid *edid)
1809{
1810 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1811}
1812EXPORT_SYMBOL(drm_edid_duplicate);
1813
Adam Jackson61e57a82010-03-29 21:43:18 +00001814/*** EDID parsing ***/
1815
Dave Airlief453ba02008-11-07 14:05:41 -08001816/**
1817 * edid_vendor - match a string against EDID's obfuscated vendor field
1818 * @edid: EDID to match
1819 * @vendor: vendor string
1820 *
1821 * Returns true if @vendor is in @edid, false otherwise
1822 */
Keith Packard170178f2017-12-13 00:44:26 -08001823static bool edid_vendor(const struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001824{
1825 char edid_vendor[3];
1826
1827 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1828 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1829 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001830 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001831
1832 return !strncmp(edid_vendor, vendor, 3);
1833}
1834
1835/**
1836 * edid_get_quirks - return quirk flags for a given EDID
1837 * @edid: EDID to process
1838 *
1839 * This tells subsequent routines what fixes they need to apply.
1840 */
Keith Packard170178f2017-12-13 00:44:26 -08001841static u32 edid_get_quirks(const struct edid *edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001842{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001843 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001844 int i;
1845
1846 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1847 quirk = &edid_quirk_list[i];
1848
1849 if (edid_vendor(edid, quirk->vendor) &&
1850 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1851 return quirk->quirks;
1852 }
1853
1854 return 0;
1855}
1856
1857#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001858#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001859
Dave Airlief453ba02008-11-07 14:05:41 -08001860/**
1861 * edid_fixup_preferred - set preferred modes based on quirk list
1862 * @connector: has mode list to fix up
1863 * @quirks: quirks list
1864 *
1865 * Walk the mode list for @connector, clearing the preferred status
1866 * on existing modes and setting it anew for the right mode ala @quirks.
1867 */
1868static void edid_fixup_preferred(struct drm_connector *connector,
1869 u32 quirks)
1870{
1871 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001872 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001873 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001874
1875 if (list_empty(&connector->probed_modes))
1876 return;
1877
1878 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1879 target_refresh = 60;
1880 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1881 target_refresh = 75;
1882
1883 preferred_mode = list_first_entry(&connector->probed_modes,
1884 struct drm_display_mode, head);
1885
1886 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1887 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1888
1889 if (cur_mode == preferred_mode)
1890 continue;
1891
1892 /* Largest mode is preferred */
1893 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1894 preferred_mode = cur_mode;
1895
Alex Deucher339d2022013-08-15 11:42:14 -04001896 cur_vrefresh = cur_mode->vrefresh ?
1897 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1898 preferred_vrefresh = preferred_mode->vrefresh ?
1899 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08001900 /* At a given size, try to get closest to target refresh */
1901 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04001902 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1903 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08001904 preferred_mode = cur_mode;
1905 }
1906 }
1907
1908 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1909}
1910
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001911static bool
1912mode_is_rb(const struct drm_display_mode *mode)
1913{
1914 return (mode->htotal - mode->hdisplay == 160) &&
1915 (mode->hsync_end - mode->hdisplay == 80) &&
1916 (mode->hsync_end - mode->hsync_start == 32) &&
1917 (mode->vsync_start - mode->vdisplay == 3);
1918}
1919
Adam Jackson33c75312012-04-13 16:33:29 -04001920/*
1921 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1922 * @dev: Device to duplicate against
1923 * @hsize: Mode width
1924 * @vsize: Mode height
1925 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001926 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04001927 *
1928 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001929 *
1930 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04001931 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001932struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001933 int hsize, int vsize, int fresh,
1934 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08001935{
Adam Jackson07a5e632009-12-03 17:44:38 -05001936 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08001937
Thierry Redinga6b21832012-11-23 15:01:42 +01001938 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001939 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001940 if (hsize != ptr->hdisplay)
1941 continue;
1942 if (vsize != ptr->vdisplay)
1943 continue;
1944 if (fresh != drm_mode_vrefresh(ptr))
1945 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001946 if (rb != mode_is_rb(ptr))
1947 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001948
1949 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08001950 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001951
1952 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08001953}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001954EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04001955
Adam Jacksond1ff6402010-03-29 21:43:26 +00001956typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1957
1958static void
Adam Jackson4d76a222010-08-03 14:38:17 -04001959cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1960{
1961 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001962 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04001963 u8 *det_base = ext + d;
1964
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001965 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04001966 for (i = 0; i < n; i++)
1967 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1968}
1969
1970static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001971vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1972{
1973 unsigned int i, n = min((int)ext[0x02], 6);
1974 u8 *det_base = ext + 5;
1975
1976 if (ext[0x01] != 1)
1977 return; /* unknown version */
1978
1979 for (i = 0; i < n; i++)
1980 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1981}
1982
1983static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00001984drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1985{
1986 int i;
1987 struct edid *edid = (struct edid *)raw_edid;
1988
1989 if (edid == NULL)
1990 return;
1991
1992 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1993 cb(&(edid->detailed_timings[i]), closure);
1994
Adam Jackson4d76a222010-08-03 14:38:17 -04001995 for (i = 1; i <= raw_edid[0x7e]; i++) {
1996 u8 *ext = raw_edid + (i * EDID_LENGTH);
1997 switch (*ext) {
1998 case CEA_EXT:
1999 cea_for_each_detailed_block(ext, cb, closure);
2000 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002001 case VTB_EXT:
2002 vtb_for_each_detailed_block(ext, cb, closure);
2003 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04002004 default:
2005 break;
2006 }
2007 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00002008}
2009
2010static void
2011is_rb(struct detailed_timing *t, void *data)
2012{
2013 u8 *r = (u8 *)t;
2014 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
2015 if (r[15] & 0x10)
2016 *(bool *)data = true;
2017}
2018
2019/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
2020static bool
2021drm_monitor_supports_rb(struct edid *edid)
2022{
2023 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02002024 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00002025 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
2026 return ret;
2027 }
2028
2029 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
2030}
2031
Adam Jackson7a374352010-03-29 21:43:30 +00002032static void
2033find_gtf2(struct detailed_timing *t, void *data)
2034{
2035 u8 *r = (u8 *)t;
2036 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
2037 *(u8 **)data = r;
2038}
2039
2040/* Secondary GTF curve kicks in above some break frequency */
2041static int
2042drm_gtf2_hbreak(struct edid *edid)
2043{
2044 u8 *r = NULL;
2045 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2046 return r ? (r[12] * 2) : 0;
2047}
2048
2049static int
2050drm_gtf2_2c(struct edid *edid)
2051{
2052 u8 *r = NULL;
2053 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2054 return r ? r[13] : 0;
2055}
2056
2057static int
2058drm_gtf2_m(struct edid *edid)
2059{
2060 u8 *r = NULL;
2061 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2062 return r ? (r[15] << 8) + r[14] : 0;
2063}
2064
2065static int
2066drm_gtf2_k(struct edid *edid)
2067{
2068 u8 *r = NULL;
2069 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2070 return r ? r[16] : 0;
2071}
2072
2073static int
2074drm_gtf2_2j(struct edid *edid)
2075{
2076 u8 *r = NULL;
2077 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2078 return r ? r[17] : 0;
2079}
2080
2081/**
2082 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
2083 * @edid: EDID block to scan
2084 */
2085static int standard_timing_level(struct edid *edid)
2086{
2087 if (edid->revision >= 2) {
2088 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
2089 return LEVEL_CVT;
2090 if (drm_gtf2_hbreak(edid))
2091 return LEVEL_GTF2;
2092 return LEVEL_GTF;
2093 }
2094 return LEVEL_DMT;
2095}
2096
Adam Jackson23425ca2009-09-23 17:30:58 -04002097/*
2098 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2099 * monitors fill with ascii space (0x20) instead.
2100 */
2101static int
2102bad_std_timing(u8 a, u8 b)
2103{
2104 return (a == 0x00 && b == 0x00) ||
2105 (a == 0x01 && b == 0x01) ||
2106 (a == 0x20 && b == 0x20);
2107}
2108
Dave Airlief453ba02008-11-07 14:05:41 -08002109/**
2110 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002111 * @connector: connector of for the EDID block
2112 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002113 * @t: standard timing params
2114 *
2115 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002116 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002117 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002118static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002119drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002120 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002121{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002122 struct drm_device *dev = connector->dev;
2123 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002124 int hsize, vsize;
2125 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002126 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2127 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002128 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2129 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002130 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002131
Adam Jackson23425ca2009-09-23 17:30:58 -04002132 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2133 return NULL;
2134
Zhao Yakui5c612592009-06-22 13:17:10 +08002135 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2136 hsize = t->hsize * 8 + 248;
2137 /* vrefresh_rate = vfreq + 60 */
2138 vrefresh_rate = vfreq + 60;
2139 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002140 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002141 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002142 vsize = hsize;
2143 else
2144 vsize = (hsize * 10) / 16;
2145 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002146 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002147 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002148 vsize = (hsize * 4) / 5;
2149 else
2150 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002151
2152 /* HDTV hack, part 1 */
2153 if (vrefresh_rate == 60 &&
2154 ((hsize == 1360 && vsize == 765) ||
2155 (hsize == 1368 && vsize == 769))) {
2156 hsize = 1366;
2157 vsize = 768;
2158 }
2159
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002160 /*
2161 * If this connector already has a mode for this size and refresh
2162 * rate (because it came from detailed or CVT info), use that
2163 * instead. This way we don't have to guess at interlace or
2164 * reduced blanking.
2165 */
Adam Jackson522032d2010-04-09 16:52:49 +00002166 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002167 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2168 drm_mode_vrefresh(m) == vrefresh_rate)
2169 return NULL;
2170
Adam Jacksona0910c82010-03-29 21:43:28 +00002171 /* HDTV hack, part 2 */
2172 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2173 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002174 false);
Joe Moriartya5ef6562018-02-12 14:51:43 -05002175 if (!mode)
2176 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002177 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002178 mode->hsync_start = mode->hsync_start - 1;
2179 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002180 return mode;
2181 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002182
Zhao Yakui559ee212009-09-03 09:33:47 +08002183 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002184 if (drm_monitor_supports_rb(edid)) {
2185 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2186 true);
2187 if (mode)
2188 return mode;
2189 }
2190 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002191 if (mode)
2192 return mode;
2193
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002194 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002195 switch (timing_level) {
2196 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002197 break;
2198 case LEVEL_GTF:
2199 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2200 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002201 case LEVEL_GTF2:
2202 /*
2203 * This is potentially wrong if there's ever a monitor with
2204 * more than one ranges section, each claiming a different
2205 * secondary GTF curve. Please don't do that.
2206 */
2207 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002208 if (!mode)
2209 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002210 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002211 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002212 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2213 vrefresh_rate, 0, 0,
2214 drm_gtf2_m(edid),
2215 drm_gtf2_2c(edid),
2216 drm_gtf2_k(edid),
2217 drm_gtf2_2j(edid));
2218 }
2219 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002220 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002221 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2222 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002223 break;
2224 }
Dave Airlief453ba02008-11-07 14:05:41 -08002225 return mode;
2226}
2227
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002228/*
2229 * EDID is delightfully ambiguous about how interlaced modes are to be
2230 * encoded. Our internal representation is of frame height, but some
2231 * HDTV detailed timings are encoded as field height.
2232 *
2233 * The format list here is from CEA, in frame size. Technically we
2234 * should be checking refresh rate too. Whatever.
2235 */
2236static void
2237drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2238 struct detailed_pixel_timing *pt)
2239{
2240 int i;
2241 static const struct {
2242 int w, h;
2243 } cea_interlaced[] = {
2244 { 1920, 1080 },
2245 { 720, 480 },
2246 { 1440, 480 },
2247 { 2880, 480 },
2248 { 720, 576 },
2249 { 1440, 576 },
2250 { 2880, 576 },
2251 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002252
2253 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2254 return;
2255
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002256 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002257 if ((mode->hdisplay == cea_interlaced[i].w) &&
2258 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2259 mode->vdisplay *= 2;
2260 mode->vsync_start *= 2;
2261 mode->vsync_end *= 2;
2262 mode->vtotal *= 2;
2263 mode->vtotal |= 1;
2264 }
2265 }
2266
2267 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2268}
2269
Dave Airlief453ba02008-11-07 14:05:41 -08002270/**
2271 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2272 * @dev: DRM device (needed to create new mode)
2273 * @edid: EDID block
2274 * @timing: EDID detailed timing info
2275 * @quirks: quirks to apply
2276 *
2277 * An EDID detailed timing block contains enough info for us to create and
2278 * return a new struct drm_display_mode.
2279 */
2280static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2281 struct edid *edid,
2282 struct detailed_timing *timing,
2283 u32 quirks)
2284{
2285 struct drm_display_mode *mode;
2286 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002287 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2288 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2289 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2290 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002291 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2292 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 +01002293 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 +02002294 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 -08002295
Adam Jacksonfc438962009-06-04 10:20:34 +10002296 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002297 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002298 return NULL;
2299
Michel Dänzer0454bea2009-06-15 16:56:07 +02002300 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002301 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002302 return NULL;
2303 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002304 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002305 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002306 }
2307
Zhao Yakuifcb45612009-10-14 09:11:25 +08002308 /* it is incorrect if hsync/vsync width is zero */
2309 if (!hsync_pulse_width || !vsync_pulse_width) {
2310 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2311 "Wrong Hsync/Vsync pulse width\n");
2312 return NULL;
2313 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002314
2315 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2316 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2317 if (!mode)
2318 return NULL;
2319
2320 goto set_size;
2321 }
2322
Dave Airlief453ba02008-11-07 14:05:41 -08002323 mode = drm_mode_create(dev);
2324 if (!mode)
2325 return NULL;
2326
Dave Airlief453ba02008-11-07 14:05:41 -08002327 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002328 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002329
Michel Dänzer0454bea2009-06-15 16:56:07 +02002330 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002331
Michel Dänzer0454bea2009-06-15 16:56:07 +02002332 mode->hdisplay = hactive;
2333 mode->hsync_start = mode->hdisplay + hsync_offset;
2334 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2335 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002336
Michel Dänzer0454bea2009-06-15 16:56:07 +02002337 mode->vdisplay = vactive;
2338 mode->vsync_start = mode->vdisplay + vsync_offset;
2339 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2340 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002341
Jesse Barnes7064fef2009-11-05 10:12:54 -08002342 /* Some EDIDs have bogus h/vtotal values */
2343 if (mode->hsync_end > mode->htotal)
2344 mode->htotal = mode->hsync_end + 1;
2345 if (mode->vsync_end > mode->vtotal)
2346 mode->vtotal = mode->vsync_end + 1;
2347
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002348 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002349
2350 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002351 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002352 }
2353
Michel Dänzer0454bea2009-06-15 16:56:07 +02002354 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2355 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2356 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2357 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002358
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002359set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002360 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2361 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002362
2363 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2364 mode->width_mm *= 10;
2365 mode->height_mm *= 10;
2366 }
2367
2368 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2369 mode->width_mm = edid->width_cm * 10;
2370 mode->height_mm = edid->height_cm * 10;
2371 }
2372
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002373 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002374 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002375 drm_mode_set_name(mode);
2376
Dave Airlief453ba02008-11-07 14:05:41 -08002377 return mode;
2378}
2379
Adam Jackson07a5e632009-12-03 17:44:38 -05002380static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002381mode_in_hsync_range(const struct drm_display_mode *mode,
2382 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002383{
2384 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002385
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002386 hmin = t[7];
2387 if (edid->revision >= 4)
2388 hmin += ((t[4] & 0x04) ? 255 : 0);
2389 hmax = t[8];
2390 if (edid->revision >= 4)
2391 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002392 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002393
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002394 return (hsync <= hmax && hsync >= hmin);
2395}
2396
2397static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002398mode_in_vsync_range(const struct drm_display_mode *mode,
2399 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002400{
2401 int vsync, vmin, vmax;
2402
2403 vmin = t[5];
2404 if (edid->revision >= 4)
2405 vmin += ((t[4] & 0x01) ? 255 : 0);
2406 vmax = t[6];
2407 if (edid->revision >= 4)
2408 vmax += ((t[4] & 0x02) ? 255 : 0);
2409 vsync = drm_mode_vrefresh(mode);
2410
2411 return (vsync <= vmax && vsync >= vmin);
2412}
2413
2414static u32
2415range_pixel_clock(struct edid *edid, u8 *t)
2416{
2417 /* unspecified */
2418 if (t[9] == 0 || t[9] == 255)
2419 return 0;
2420
2421 /* 1.4 with CVT support gives us real precision, yay */
2422 if (edid->revision >= 4 && t[10] == 0x04)
2423 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2424
2425 /* 1.3 is pathetic, so fuzz up a bit */
2426 return t[9] * 10000 + 5001;
2427}
2428
Adam Jackson07a5e632009-12-03 17:44:38 -05002429static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002430mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002431 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002432{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002433 u32 max_clock;
2434 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002435
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002436 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002437 return false;
2438
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002439 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002440 return false;
2441
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002442 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002443 if (mode->clock > max_clock)
2444 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002445
2446 /* 1.4 max horizontal check */
2447 if (edid->revision >= 4 && t[10] == 0x04)
2448 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2449 return false;
2450
2451 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2452 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002453
2454 return true;
2455}
2456
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002457static bool valid_inferred_mode(const struct drm_connector *connector,
2458 const struct drm_display_mode *mode)
2459{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002460 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002461 bool ok = false;
2462
2463 list_for_each_entry(m, &connector->probed_modes, head) {
2464 if (mode->hdisplay == m->hdisplay &&
2465 mode->vdisplay == m->vdisplay &&
2466 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2467 return false; /* duplicated */
2468 if (mode->hdisplay <= m->hdisplay &&
2469 mode->vdisplay <= m->vdisplay)
2470 ok = true;
2471 }
2472 return ok;
2473}
2474
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002475static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002476drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002477 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002478{
2479 int i, modes = 0;
2480 struct drm_display_mode *newmode;
2481 struct drm_device *dev = connector->dev;
2482
Thierry Redinga6b21832012-11-23 15:01:42 +01002483 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002484 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2485 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002486 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2487 if (newmode) {
2488 drm_mode_probed_add(connector, newmode);
2489 modes++;
2490 }
2491 }
2492 }
2493
2494 return modes;
2495}
2496
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002497/* fix up 1366x768 mode from 1368x768;
2498 * GFT/CVT can't express 1366 width which isn't dividable by 8
2499 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002500void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002501{
2502 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2503 mode->hdisplay = 1366;
2504 mode->hsync_start--;
2505 mode->hsync_end--;
2506 drm_mode_set_name(mode);
2507 }
2508}
2509
Adam Jacksonb309bd32012-04-13 16:33:40 -04002510static int
2511drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2512 struct detailed_timing *timing)
2513{
2514 int i, modes = 0;
2515 struct drm_display_mode *newmode;
2516 struct drm_device *dev = connector->dev;
2517
Thierry Redinga6b21832012-11-23 15:01:42 +01002518 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002519 const struct minimode *m = &extra_modes[i];
2520 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002521 if (!newmode)
2522 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002523
Takashi Iwai969218f2017-01-17 17:43:29 +01002524 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002525 if (!mode_in_range(newmode, edid, timing) ||
2526 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002527 drm_mode_destroy(dev, newmode);
2528 continue;
2529 }
2530
2531 drm_mode_probed_add(connector, newmode);
2532 modes++;
2533 }
2534
2535 return modes;
2536}
2537
2538static int
2539drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2540 struct detailed_timing *timing)
2541{
2542 int i, modes = 0;
2543 struct drm_display_mode *newmode;
2544 struct drm_device *dev = connector->dev;
2545 bool rb = drm_monitor_supports_rb(edid);
2546
Thierry Redinga6b21832012-11-23 15:01:42 +01002547 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002548 const struct minimode *m = &extra_modes[i];
2549 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002550 if (!newmode)
2551 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002552
Takashi Iwai969218f2017-01-17 17:43:29 +01002553 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002554 if (!mode_in_range(newmode, edid, timing) ||
2555 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002556 drm_mode_destroy(dev, newmode);
2557 continue;
2558 }
2559
2560 drm_mode_probed_add(connector, newmode);
2561 modes++;
2562 }
2563
2564 return modes;
2565}
2566
Adam Jackson13931572010-08-03 14:38:19 -04002567static void
2568do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002569{
Adam Jackson13931572010-08-03 14:38:19 -04002570 struct detailed_mode_closure *closure = c;
2571 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002572 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002573
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002574 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2575 return;
2576
2577 closure->modes += drm_dmt_modes_for_range(closure->connector,
2578 closure->edid,
2579 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002580
2581 if (!version_greater(closure->edid, 1, 1))
2582 return; /* GTF not defined yet */
2583
2584 switch (range->flags) {
2585 case 0x02: /* secondary gtf, XXX could do more */
2586 case 0x00: /* default gtf */
2587 closure->modes += drm_gtf_modes_for_range(closure->connector,
2588 closure->edid,
2589 timing);
2590 break;
2591 case 0x04: /* cvt, only in 1.4+ */
2592 if (!version_greater(closure->edid, 1, 3))
2593 break;
2594
2595 closure->modes += drm_cvt_modes_for_range(closure->connector,
2596 closure->edid,
2597 timing);
2598 break;
2599 case 0x01: /* just the ranges, no formula */
2600 default:
2601 break;
2602 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002603}
2604
Adam Jackson13931572010-08-03 14:38:19 -04002605static int
2606add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2607{
2608 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002609 .connector = connector,
2610 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002611 };
2612
2613 if (version_greater(edid, 1, 0))
2614 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2615 &closure);
2616
2617 return closure.modes;
2618}
2619
Adam Jackson2255be12010-03-29 21:43:22 +00002620static int
2621drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2622{
2623 int i, j, m, modes = 0;
2624 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002625 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002626
2627 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002628 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002629 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002630 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002631 break;
2632 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002633 mode = drm_mode_find_dmt(connector->dev,
2634 est3_modes[m].w,
2635 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002636 est3_modes[m].r,
2637 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002638 if (mode) {
2639 drm_mode_probed_add(connector, mode);
2640 modes++;
2641 }
2642 }
2643 }
2644 }
2645
2646 return modes;
2647}
2648
Adam Jackson13931572010-08-03 14:38:19 -04002649static void
2650do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002651{
Adam Jackson13931572010-08-03 14:38:19 -04002652 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002653 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002654
2655 if (data->type == EDID_DETAIL_EST_TIMINGS)
2656 closure->modes += drm_est3_modes(closure->connector, timing);
2657}
2658
2659/**
2660 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002661 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002662 * @edid: EDID block to scan
2663 *
2664 * Each EDID block contains a bitmap of the supported "established modes" list
2665 * (defined above). Tease them out and add them to the global modes list.
2666 */
2667static int
2668add_established_modes(struct drm_connector *connector, struct edid *edid)
2669{
Adam Jackson9cf00972009-12-03 17:44:36 -05002670 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002671 unsigned long est_bits = edid->established_timings.t1 |
2672 (edid->established_timings.t2 << 8) |
2673 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2674 int i, modes = 0;
2675 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002676 .connector = connector,
2677 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002678 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002679
Adam Jackson13931572010-08-03 14:38:19 -04002680 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2681 if (est_bits & (1<<i)) {
2682 struct drm_display_mode *newmode;
2683 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2684 if (newmode) {
2685 drm_mode_probed_add(connector, newmode);
2686 modes++;
2687 }
2688 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002689 }
2690
Adam Jackson13931572010-08-03 14:38:19 -04002691 if (version_greater(edid, 1, 0))
2692 drm_for_each_detailed_block((u8 *)edid,
2693 do_established_modes, &closure);
2694
2695 return modes + closure.modes;
2696}
2697
2698static void
2699do_standard_modes(struct detailed_timing *timing, void *c)
2700{
2701 struct detailed_mode_closure *closure = c;
2702 struct detailed_non_pixel *data = &timing->data.other_data;
2703 struct drm_connector *connector = closure->connector;
2704 struct edid *edid = closure->edid;
2705
2706 if (data->type == EDID_DETAIL_STD_MODES) {
2707 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002708 for (i = 0; i < 6; i++) {
2709 struct std_timing *std;
2710 struct drm_display_mode *newmode;
2711
2712 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002713 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002714 if (newmode) {
2715 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002716 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002717 }
2718 }
Adam Jackson13931572010-08-03 14:38:19 -04002719 }
2720}
2721
2722/**
2723 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002724 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002725 * @edid: EDID block to scan
2726 *
2727 * Standard modes can be calculated using the appropriate standard (DMT,
2728 * GTF or CVT. Grab them from @edid and add them to the list.
2729 */
2730static int
2731add_standard_modes(struct drm_connector *connector, struct edid *edid)
2732{
2733 int i, modes = 0;
2734 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002735 .connector = connector,
2736 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002737 };
2738
2739 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2740 struct drm_display_mode *newmode;
2741
2742 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002743 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002744 if (newmode) {
2745 drm_mode_probed_add(connector, newmode);
2746 modes++;
2747 }
2748 }
2749
2750 if (version_greater(edid, 1, 0))
2751 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2752 &closure);
2753
2754 /* XXX should also look for standard codes in VTB blocks */
2755
2756 return modes + closure.modes;
2757}
2758
Dave Airlief453ba02008-11-07 14:05:41 -08002759static int drm_cvt_modes(struct drm_connector *connector,
2760 struct detailed_timing *timing)
2761{
2762 int i, j, modes = 0;
2763 struct drm_display_mode *newmode;
2764 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002765 struct cvt_timing *cvt;
2766 const int rates[] = { 60, 85, 75, 60, 50 };
2767 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002768
2769 for (i = 0; i < 4; i++) {
2770 int uninitialized_var(width), height;
2771 cvt = &(timing->data.other_data.data.cvt[i]);
2772
2773 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002774 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002775
2776 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002777 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002778 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002779 width = height * 4 / 3;
2780 break;
2781 case 0x04:
2782 width = height * 16 / 9;
2783 break;
2784 case 0x08:
2785 width = height * 16 / 10;
2786 break;
2787 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002788 width = height * 15 / 9;
2789 break;
2790 }
2791
2792 for (j = 1; j < 5; j++) {
2793 if (cvt->code[2] & (1 << j)) {
2794 newmode = drm_cvt_mode(dev, width, height,
2795 rates[j], j == 0,
2796 false, false);
2797 if (newmode) {
2798 drm_mode_probed_add(connector, newmode);
2799 modes++;
2800 }
2801 }
2802 }
2803 }
2804
2805 return modes;
2806}
2807
Adam Jackson13931572010-08-03 14:38:19 -04002808static void
2809do_cvt_mode(struct detailed_timing *timing, void *c)
2810{
2811 struct detailed_mode_closure *closure = c;
2812 struct detailed_non_pixel *data = &timing->data.other_data;
2813
2814 if (data->type == EDID_DETAIL_CVT_3BYTE)
2815 closure->modes += drm_cvt_modes(closure->connector, timing);
2816}
Adam Jackson9cf00972009-12-03 17:44:36 -05002817
2818static int
Adam Jackson13931572010-08-03 14:38:19 -04002819add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2820{
2821 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002822 .connector = connector,
2823 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002824 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002825
Adam Jackson13931572010-08-03 14:38:19 -04002826 if (version_greater(edid, 1, 2))
2827 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002828
Adam Jackson13931572010-08-03 14:38:19 -04002829 /* XXX should also look for CVT codes in VTB blocks */
2830
2831 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002832}
2833
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002834static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2835
Adam Jackson13931572010-08-03 14:38:19 -04002836static void
2837do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002838{
Adam Jackson13931572010-08-03 14:38:19 -04002839 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002840 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002841
2842 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002843 newmode = drm_mode_detailed(closure->connector->dev,
2844 closure->edid, timing,
2845 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002846 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002847 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002848
Adam Jackson13931572010-08-03 14:38:19 -04002849 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002850 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2851
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002852 /*
2853 * Detailed modes are limited to 10kHz pixel clock resolution,
2854 * so fix up anything that looks like CEA/HDMI mode, but the clock
2855 * is just slightly off.
2856 */
2857 fixup_detailed_cea_mode_clock(newmode);
2858
Adam Jackson13931572010-08-03 14:38:19 -04002859 drm_mode_probed_add(closure->connector, newmode);
2860 closure->modes++;
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002861 closure->preferred = false;
Zhao Yakui882f0212009-08-26 18:20:49 +08002862 }
Ma Ling167f3a02009-03-20 14:09:48 +08002863}
2864
Adam Jackson13931572010-08-03 14:38:19 -04002865/*
2866 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002867 * @connector: attached connector
2868 * @edid: EDID block to scan
2869 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002870 */
Adam Jackson13931572010-08-03 14:38:19 -04002871static int
2872add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2873 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002874{
Adam Jackson13931572010-08-03 14:38:19 -04002875 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002876 .connector = connector,
2877 .edid = edid,
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06002878 .preferred = true,
Julia Lawalld456ea22014-08-23 18:09:56 +02002879 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002880 };
Dave Airlief453ba02008-11-07 14:05:41 -08002881
Adam Jackson13931572010-08-03 14:38:19 -04002882 if (closure.preferred && !version_greater(edid, 1, 3))
2883 closure.preferred =
2884 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002885
Adam Jackson13931572010-08-03 14:38:19 -04002886 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002887
Adam Jackson13931572010-08-03 14:38:19 -04002888 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002889}
Dave Airlief453ba02008-11-07 14:05:41 -08002890
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002891#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002892#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002893#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002894#define SPEAKER_BLOCK 0x04
Uma Shankare85959d2019-05-16 19:40:08 +05302895#define HDR_STATIC_METADATA_BLOCK 0x6
Shashank Sharma87563fc2017-07-13 21:03:10 +05302896#define USE_EXTENDED_TAG 0x07
2897#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05302898#define EXT_VIDEO_DATA_BLOCK_420 0x0E
2899#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002900#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02002901#define EDID_CEA_YCRCB444 (1 << 5)
2902#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002903#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002904
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002905/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002906 * Search EDID for CEA extension block.
2907 */
Keith Packard170178f2017-12-13 00:44:26 -08002908static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002909{
2910 u8 *edid_ext = NULL;
2911 int i;
2912
2913 /* No EDID or EDID extensions */
2914 if (edid == NULL || edid->extensions == 0)
2915 return NULL;
2916
2917 /* Find CEA extension */
2918 for (i = 0; i < edid->extensions; i++) {
2919 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10002920 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002921 break;
2922 }
2923
2924 if (i == edid->extensions)
2925 return NULL;
2926
2927 return edid_ext;
2928}
2929
Dave Airlie40d9b042014-10-20 16:29:33 +10002930
Keith Packard170178f2017-12-13 00:44:26 -08002931static u8 *drm_find_displayid_extension(const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10002932{
2933 return drm_find_edid_extension(edid, DISPLAYID_EXT);
2934}
2935
Andres Rodrigueze28ad542019-06-19 14:09:01 -04002936static u8 *drm_find_cea_extension(const struct edid *edid)
2937{
2938 int ret;
2939 int idx = 1;
2940 int length = EDID_LENGTH;
2941 struct displayid_block *block;
2942 u8 *cea;
2943 u8 *displayid;
2944
2945 /* Look for a top level CEA extension block */
2946 cea = drm_find_edid_extension(edid, CEA_EXT);
2947 if (cea)
2948 return cea;
2949
2950 /* CEA blocks can also be found embedded in a DisplayID block */
2951 displayid = drm_find_displayid_extension(edid);
2952 if (!displayid)
2953 return NULL;
2954
2955 ret = validate_displayid(displayid, length, idx);
2956 if (ret)
2957 return NULL;
2958
2959 idx += sizeof(struct displayid_hdr);
2960 for_each_displayid_db(displayid, block, idx, length) {
2961 if (block->tag == DATA_BLOCK_CTA) {
2962 cea = (u8 *)block;
2963 break;
2964 }
2965 }
2966
2967 return cea;
2968}
2969
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002970/*
2971 * Calculate the alternate clock for the CEA mode
2972 * (60Hz vs. 59.94Hz etc.)
2973 */
2974static unsigned int
2975cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2976{
2977 unsigned int clock = cea_mode->clock;
2978
2979 if (cea_mode->vrefresh % 6 != 0)
2980 return clock;
2981
2982 /*
2983 * edid_cea_modes contains the 59.94Hz
2984 * variant for 240 and 480 line modes,
2985 * and the 60Hz variant otherwise.
2986 */
2987 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002988 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002989 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002990 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002991
2992 return clock;
2993}
2994
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002995static bool
2996cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
2997{
2998 /*
2999 * For certain VICs the spec allows the vertical
3000 * front porch to vary by one or two lines.
3001 *
3002 * cea_modes[] stores the variant with the shortest
3003 * vertical front porch. We can adjust the mode to
3004 * get the other variants by simply increasing the
3005 * vertical front porch length.
3006 */
3007 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
3008 edid_cea_modes[9].vtotal != 262 ||
3009 edid_cea_modes[12].vtotal != 262 ||
3010 edid_cea_modes[13].vtotal != 262 ||
3011 edid_cea_modes[23].vtotal != 312 ||
3012 edid_cea_modes[24].vtotal != 312 ||
3013 edid_cea_modes[27].vtotal != 312 ||
3014 edid_cea_modes[28].vtotal != 312);
3015
3016 if (((vic == 8 || vic == 9 ||
3017 vic == 12 || vic == 13) && mode->vtotal < 263) ||
3018 ((vic == 23 || vic == 24 ||
3019 vic == 27 || vic == 28) && mode->vtotal < 314)) {
3020 mode->vsync_start++;
3021 mode->vsync_end++;
3022 mode->vtotal++;
3023
3024 return true;
3025 }
3026
3027 return false;
3028}
3029
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003030static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
3031 unsigned int clock_tolerance)
3032{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303033 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003034 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003035
3036 if (!to_match->clock)
3037 return 0;
3038
Ville Syrjälä357768c2018-05-08 16:39:38 +05303039 if (to_match->picture_aspect_ratio)
3040 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3041
Jani Nikulad9278b42016-01-08 13:21:51 +02003042 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003043 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003044 unsigned int clock1, clock2;
3045
3046 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003047 clock1 = cea_mode.clock;
3048 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003049
3050 if (abs(to_match->clock - clock1) > clock_tolerance &&
3051 abs(to_match->clock - clock2) > clock_tolerance)
3052 continue;
3053
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003054 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303055 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003056 return vic;
3057 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003058 }
3059
3060 return 0;
3061}
3062
Thierry Reding18316c82012-12-20 15:41:44 +01003063/**
3064 * drm_match_cea_mode - look for a CEA mode matching given mode
3065 * @to_match: display mode
3066 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003067 * 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 +01003068 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00003069 */
Thierry Reding18316c82012-12-20 15:41:44 +01003070u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00003071{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303072 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003073 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00003074
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003075 if (!to_match->clock)
3076 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00003077
Ville Syrjälä357768c2018-05-08 16:39:38 +05303078 if (to_match->picture_aspect_ratio)
3079 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3080
Jani Nikulad9278b42016-01-08 13:21:51 +02003081 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003082 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003083 unsigned int clock1, clock2;
3084
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003085 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003086 clock1 = cea_mode.clock;
3087 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003088
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003089 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
3090 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
3091 continue;
3092
3093 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303094 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003095 return vic;
3096 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00003097 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003098
Stephane Marchesina4799032012-11-09 16:21:05 +00003099 return 0;
3100}
3101EXPORT_SYMBOL(drm_match_cea_mode);
3102
Jani Nikulad9278b42016-01-08 13:21:51 +02003103static bool drm_valid_cea_vic(u8 vic)
3104{
3105 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
3106}
3107
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303108/**
3109 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
3110 * the input VIC from the CEA mode list
3111 * @video_code: ID given to each of the CEA modes
3112 *
3113 * Returns picture aspect ratio
3114 */
3115enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
3116{
Jani Nikulad9278b42016-01-08 13:21:51 +02003117 return edid_cea_modes[video_code].picture_aspect_ratio;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303118}
3119EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
3120
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003121/*
3122 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
3123 * specific block).
3124 *
3125 * It's almost like cea_mode_alternate_clock(), we just need to add an
3126 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
3127 * one.
3128 */
3129static unsigned int
3130hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3131{
3132 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
3133 return hdmi_mode->clock;
3134
3135 return cea_mode_alternate_clock(hdmi_mode);
3136}
3137
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003138static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3139 unsigned int clock_tolerance)
3140{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303141 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003142 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003143
3144 if (!to_match->clock)
3145 return 0;
3146
Jani Nikulad9278b42016-01-08 13:21:51 +02003147 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3148 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003149 unsigned int clock1, clock2;
3150
3151 /* Make sure to also match alternate clocks */
3152 clock1 = hdmi_mode->clock;
3153 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3154
3155 if (abs(to_match->clock - clock1) > clock_tolerance &&
3156 abs(to_match->clock - clock2) > clock_tolerance)
3157 continue;
3158
Ville Syrjälä357768c2018-05-08 16:39:38 +05303159 if (drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003160 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003161 }
3162
3163 return 0;
3164}
3165
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003166/*
3167 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3168 * @to_match: display mode
3169 *
3170 * An HDMI mode is one defined in the HDMI vendor specific block.
3171 *
3172 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3173 */
3174static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3175{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303176 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003177 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003178
3179 if (!to_match->clock)
3180 return 0;
3181
Jani Nikulad9278b42016-01-08 13:21:51 +02003182 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3183 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003184 unsigned int clock1, clock2;
3185
3186 /* Make sure to also match alternate clocks */
3187 clock1 = hdmi_mode->clock;
3188 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3189
3190 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3191 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Ville Syrjälä357768c2018-05-08 16:39:38 +05303192 drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003193 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003194 }
3195 return 0;
3196}
3197
Jani Nikulad9278b42016-01-08 13:21:51 +02003198static bool drm_valid_hdmi_vic(u8 vic)
3199{
3200 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3201}
3202
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003203static int
3204add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3205{
3206 struct drm_device *dev = connector->dev;
3207 struct drm_display_mode *mode, *tmp;
3208 LIST_HEAD(list);
3209 int modes = 0;
3210
3211 /* Don't add CEA modes if the CEA extension block is missing */
3212 if (!drm_find_cea_extension(edid))
3213 return 0;
3214
3215 /*
3216 * Go through all probed modes and create a new mode
3217 * with the alternate clock for certain CEA modes.
3218 */
3219 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003220 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003221 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003222 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003223 unsigned int clock1, clock2;
3224
Jani Nikulad9278b42016-01-08 13:21:51 +02003225 if (drm_valid_cea_vic(vic)) {
3226 cea_mode = &edid_cea_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003227 clock2 = cea_mode_alternate_clock(cea_mode);
3228 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003229 vic = drm_match_hdmi_mode(mode);
3230 if (drm_valid_hdmi_vic(vic)) {
3231 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003232 clock2 = hdmi_mode_alternate_clock(cea_mode);
3233 }
3234 }
3235
3236 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003237 continue;
3238
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003239 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003240
3241 if (clock1 == clock2)
3242 continue;
3243
3244 if (mode->clock != clock1 && mode->clock != clock2)
3245 continue;
3246
3247 newmode = drm_mode_duplicate(dev, cea_mode);
3248 if (!newmode)
3249 continue;
3250
Damien Lespiau27130212013-09-25 16:45:28 +01003251 /* Carry over the stereo flags */
3252 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3253
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003254 /*
3255 * The current mode could be either variant. Make
3256 * sure to pick the "other" clock for the new mode.
3257 */
3258 if (mode->clock != clock1)
3259 newmode->clock = clock1;
3260 else
3261 newmode->clock = clock2;
3262
3263 list_add_tail(&newmode->head, &list);
3264 }
3265
3266 list_for_each_entry_safe(mode, tmp, &list, head) {
3267 list_del(&mode->head);
3268 drm_mode_probed_add(connector, mode);
3269 modes++;
3270 }
3271
3272 return modes;
3273}
Stephane Marchesina4799032012-11-09 16:21:05 +00003274
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303275static u8 svd_to_vic(u8 svd)
3276{
3277 /* 0-6 bit vic, 7th bit native mode indicator */
3278 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3279 return svd & 127;
3280
3281 return svd;
3282}
3283
Thomas Woodaff04ac2013-11-29 15:33:27 +00003284static struct drm_display_mode *
3285drm_display_mode_from_vic_index(struct drm_connector *connector,
3286 const u8 *video_db, u8 video_len,
3287 u8 video_index)
3288{
3289 struct drm_device *dev = connector->dev;
3290 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003291 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003292
3293 if (video_db == NULL || video_index >= video_len)
3294 return NULL;
3295
3296 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303297 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003298 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003299 return NULL;
3300
Jani Nikulad9278b42016-01-08 13:21:51 +02003301 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00003302 if (!newmode)
3303 return NULL;
3304
Thomas Woodaff04ac2013-11-29 15:33:27 +00003305 newmode->vrefresh = 0;
3306
3307 return newmode;
3308}
3309
Shashank Sharma832d4f22017-07-14 16:03:46 +05303310/*
3311 * do_y420vdb_modes - Parse YCBCR 420 only modes
3312 * @connector: connector corresponding to the HDMI sink
3313 * @svds: start of the data block of CEA YCBCR 420 VDB
3314 * @len: length of the CEA YCBCR 420 VDB
3315 *
3316 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3317 * which contains modes which can be supported in YCBCR 420
3318 * output format only.
3319 */
3320static int do_y420vdb_modes(struct drm_connector *connector,
3321 const u8 *svds, u8 svds_len)
3322{
3323 int modes = 0, i;
3324 struct drm_device *dev = connector->dev;
3325 struct drm_display_info *info = &connector->display_info;
3326 struct drm_hdmi_info *hdmi = &info->hdmi;
3327
3328 for (i = 0; i < svds_len; i++) {
3329 u8 vic = svd_to_vic(svds[i]);
3330 struct drm_display_mode *newmode;
3331
3332 if (!drm_valid_cea_vic(vic))
3333 continue;
3334
3335 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3336 if (!newmode)
3337 break;
3338 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3339 drm_mode_probed_add(connector, newmode);
3340 modes++;
3341 }
3342
3343 if (modes > 0)
3344 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3345 return modes;
3346}
3347
3348/*
3349 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3350 * @connector: connector corresponding to the HDMI sink
3351 * @vic: CEA vic for the video mode to be added in the map
3352 *
3353 * Makes an entry for a videomode in the YCBCR 420 bitmap
3354 */
3355static void
3356drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3357{
3358 u8 vic = svd_to_vic(svd);
3359 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3360
3361 if (!drm_valid_cea_vic(vic))
3362 return;
3363
3364 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3365}
3366
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003367static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003368do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003369{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003370 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303371 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003372
Thomas Woodaff04ac2013-11-29 15:33:27 +00003373 for (i = 0; i < len; i++) {
3374 struct drm_display_mode *mode;
3375 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3376 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303377 /*
3378 * YCBCR420 capability block contains a bitmap which
3379 * gives the index of CEA modes from CEA VDB, which
3380 * can support YCBCR 420 sampling output also (apart
3381 * from RGB/YCBCR444 etc).
3382 * For example, if the bit 0 in bitmap is set,
3383 * first mode in VDB can support YCBCR420 output too.
3384 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3385 */
3386 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3387 drm_add_cmdb_modes(connector, db[i]);
3388
Thomas Woodaff04ac2013-11-29 15:33:27 +00003389 drm_mode_probed_add(connector, mode);
3390 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003391 }
3392 }
3393
3394 return modes;
3395}
3396
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003397struct stereo_mandatory_mode {
3398 int width, height, vrefresh;
3399 unsigned int flags;
3400};
3401
3402static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003403 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3404 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003405 { 1920, 1080, 50,
3406 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3407 { 1920, 1080, 60,
3408 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003409 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3410 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3411 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3412 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003413};
3414
3415static bool
3416stereo_match_mandatory(const struct drm_display_mode *mode,
3417 const struct stereo_mandatory_mode *stereo_mode)
3418{
3419 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3420
3421 return mode->hdisplay == stereo_mode->width &&
3422 mode->vdisplay == stereo_mode->height &&
3423 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3424 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3425}
3426
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003427static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3428{
3429 struct drm_device *dev = connector->dev;
3430 const struct drm_display_mode *mode;
3431 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003432 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003433
3434 INIT_LIST_HEAD(&stereo_modes);
3435
3436 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003437 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3438 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003439 struct drm_display_mode *new_mode;
3440
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003441 if (!stereo_match_mandatory(mode,
3442 &stereo_mandatory_modes[i]))
3443 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003444
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003445 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003446 new_mode = drm_mode_duplicate(dev, mode);
3447 if (!new_mode)
3448 continue;
3449
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003450 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003451 list_add_tail(&new_mode->head, &stereo_modes);
3452 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003453 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003454 }
3455
3456 list_splice_tail(&stereo_modes, &connector->probed_modes);
3457
3458 return modes;
3459}
3460
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003461static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3462{
3463 struct drm_device *dev = connector->dev;
3464 struct drm_display_mode *newmode;
3465
Jani Nikulad9278b42016-01-08 13:21:51 +02003466 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003467 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3468 return 0;
3469 }
3470
3471 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3472 if (!newmode)
3473 return 0;
3474
3475 drm_mode_probed_add(connector, newmode);
3476
3477 return 1;
3478}
3479
Thomas Woodfbf46022013-10-16 15:58:50 +01003480static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3481 const u8 *video_db, u8 video_len, u8 video_index)
3482{
Thomas Woodfbf46022013-10-16 15:58:50 +01003483 struct drm_display_mode *newmode;
3484 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003485
3486 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003487 newmode = drm_display_mode_from_vic_index(connector, video_db,
3488 video_len,
3489 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003490 if (newmode) {
3491 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3492 drm_mode_probed_add(connector, newmode);
3493 modes++;
3494 }
3495 }
3496 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003497 newmode = drm_display_mode_from_vic_index(connector, video_db,
3498 video_len,
3499 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003500 if (newmode) {
3501 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3502 drm_mode_probed_add(connector, newmode);
3503 modes++;
3504 }
3505 }
3506 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003507 newmode = drm_display_mode_from_vic_index(connector, video_db,
3508 video_len,
3509 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003510 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003511 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003512 drm_mode_probed_add(connector, newmode);
3513 modes++;
3514 }
3515 }
3516
3517 return modes;
3518}
3519
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003520/*
3521 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3522 * @connector: connector corresponding to the HDMI sink
3523 * @db: start of the CEA vendor specific block
3524 * @len: length of the CEA block payload, ie. one can access up to db[len]
3525 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003526 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3527 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003528 */
3529static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003530do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3531 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003532{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003533 struct drm_display_info *info = &connector->display_info;
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003534 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003535 u8 vic_len, hdmi_3d_len = 0;
3536 u16 mask;
3537 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003538
3539 if (len < 8)
3540 goto out;
3541
3542 /* no HDMI_Video_Present */
3543 if (!(db[8] & (1 << 5)))
3544 goto out;
3545
3546 /* Latency_Fields_Present */
3547 if (db[8] & (1 << 7))
3548 offset += 2;
3549
3550 /* I_Latency_Fields_Present */
3551 if (db[8] & (1 << 6))
3552 offset += 2;
3553
3554 /* the declared length is not long enough for the 2 first bytes
3555 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003556 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003557 goto out;
3558
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003559 /* 3D_Present */
3560 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003561 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003562 modes += add_hdmi_mandatory_stereo_modes(connector);
3563
Thomas Woodfbf46022013-10-16 15:58:50 +01003564 /* 3D_Multi_present */
3565 multi_present = (db[8 + offset] & 0x60) >> 5;
3566 }
3567
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003568 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003569 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003570 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003571
3572 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003573 u8 vic;
3574
3575 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003576 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003577 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003578 offset += 1 + vic_len;
3579
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003580 if (multi_present == 1)
3581 multi_len = 2;
3582 else if (multi_present == 2)
3583 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003584 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003585 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003586
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003587 if (len < (8 + offset + hdmi_3d_len - 1))
3588 goto out;
3589
3590 if (hdmi_3d_len < multi_len)
3591 goto out;
3592
3593 if (multi_present == 1 || multi_present == 2) {
3594 /* 3D_Structure_ALL */
3595 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3596
3597 /* check if 3D_MASK is present */
3598 if (multi_present == 2)
3599 mask = (db[10 + offset] << 8) | db[11 + offset];
3600 else
3601 mask = 0xffff;
3602
3603 for (i = 0; i < 16; i++) {
3604 if (mask & (1 << i))
3605 modes += add_3d_struct_modes(connector,
3606 structure_all,
3607 video_db,
3608 video_len, i);
3609 }
3610 }
3611
3612 offset += multi_len;
3613
3614 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3615 int vic_index;
3616 struct drm_display_mode *newmode = NULL;
3617 unsigned int newflag = 0;
3618 bool detail_present;
3619
3620 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3621
3622 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3623 break;
3624
3625 /* 2D_VIC_order_X */
3626 vic_index = db[8 + offset + i] >> 4;
3627
3628 /* 3D_Structure_X */
3629 switch (db[8 + offset + i] & 0x0f) {
3630 case 0:
3631 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3632 break;
3633 case 6:
3634 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3635 break;
3636 case 8:
3637 /* 3D_Detail_X */
3638 if ((db[9 + offset + i] >> 4) == 1)
3639 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3640 break;
3641 }
3642
3643 if (newflag != 0) {
3644 newmode = drm_display_mode_from_vic_index(connector,
3645 video_db,
3646 video_len,
3647 vic_index);
3648
3649 if (newmode) {
3650 newmode->flags |= newflag;
3651 drm_mode_probed_add(connector, newmode);
3652 modes++;
3653 }
3654 }
3655
3656 if (detail_present)
3657 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003658 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003659
3660out:
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003661 if (modes > 0)
3662 info->has_hdmi_infoframe = true;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003663 return modes;
3664}
3665
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003666static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003667cea_db_payload_len(const u8 *db)
3668{
3669 return db[0] & 0x1f;
3670}
3671
3672static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05303673cea_db_extended_tag(const u8 *db)
3674{
3675 return db[1];
3676}
3677
3678static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003679cea_db_tag(const u8 *db)
3680{
3681 return db[0] >> 5;
3682}
3683
3684static int
3685cea_revision(const u8 *cea)
3686{
3687 return cea[1];
3688}
3689
3690static int
3691cea_db_offsets(const u8 *cea, int *start, int *end)
3692{
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003693 /* DisplayID CTA extension blocks and top-level CEA EDID
3694 * block header definitions differ in the following bytes:
3695 * 1) Byte 2 of the header specifies length differently,
3696 * 2) Byte 3 is only present in the CEA top level block.
3697 *
3698 * The different definitions for byte 2 follow.
3699 *
3700 * DisplayID CTA extension block defines byte 2 as:
3701 * Number of payload bytes
3702 *
3703 * CEA EDID block defines byte 2 as:
3704 * Byte number (decimal) within this block where the 18-byte
3705 * DTDs begin. If no non-DTD data is present in this extension
3706 * block, the value should be set to 04h (the byte after next).
3707 * If set to 00h, there are no DTDs present in this block and
3708 * no non-DTD data.
3709 */
3710 if (cea[0] == DATA_BLOCK_CTA) {
3711 *start = 3;
3712 *end = *start + cea[2];
3713 } else if (cea[0] == CEA_EXT) {
3714 /* Data block offset in CEA extension block */
3715 *start = 4;
3716 *end = cea[2];
3717 if (*end == 0)
3718 *end = 127;
3719 if (*end < 4 || *end > 127)
3720 return -ERANGE;
3721 } else {
Daniel Vetterc7581a42019-09-04 16:39:42 +02003722 return -EOPNOTSUPP;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003723 }
3724
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003725 return 0;
3726}
3727
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003728static bool cea_db_is_hdmi_vsdb(const u8 *db)
3729{
3730 int hdmi_id;
3731
3732 if (cea_db_tag(db) != VENDOR_BLOCK)
3733 return false;
3734
3735 if (cea_db_payload_len(db) < 5)
3736 return false;
3737
3738 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3739
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003740 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003741}
3742
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303743static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3744{
3745 unsigned int oui;
3746
3747 if (cea_db_tag(db) != VENDOR_BLOCK)
3748 return false;
3749
3750 if (cea_db_payload_len(db) < 7)
3751 return false;
3752
3753 oui = db[3] << 16 | db[2] << 8 | db[1];
3754
3755 return oui == HDMI_FORUM_IEEE_OUI;
3756}
3757
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02003758static bool cea_db_is_vcdb(const u8 *db)
3759{
3760 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3761 return false;
3762
3763 if (cea_db_payload_len(db) != 2)
3764 return false;
3765
3766 if (cea_db_extended_tag(db) != EXT_VIDEO_CAPABILITY_BLOCK)
3767 return false;
3768
3769 return true;
3770}
3771
Shashank Sharma832d4f22017-07-14 16:03:46 +05303772static bool cea_db_is_y420cmdb(const u8 *db)
3773{
3774 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3775 return false;
3776
3777 if (!cea_db_payload_len(db))
3778 return false;
3779
3780 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3781 return false;
3782
3783 return true;
3784}
3785
3786static bool cea_db_is_y420vdb(const u8 *db)
3787{
3788 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3789 return false;
3790
3791 if (!cea_db_payload_len(db))
3792 return false;
3793
3794 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3795 return false;
3796
3797 return true;
3798}
3799
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003800#define for_each_cea_db(cea, i, start, end) \
3801 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3802
Shashank Sharma832d4f22017-07-14 16:03:46 +05303803static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3804 const u8 *db)
3805{
3806 struct drm_display_info *info = &connector->display_info;
3807 struct drm_hdmi_info *hdmi = &info->hdmi;
3808 u8 map_len = cea_db_payload_len(db) - 1;
3809 u8 count;
3810 u64 map = 0;
3811
3812 if (map_len == 0) {
3813 /* All CEA modes support ycbcr420 sampling also.*/
3814 hdmi->y420_cmdb_map = U64_MAX;
3815 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3816 return;
3817 }
3818
3819 /*
3820 * This map indicates which of the existing CEA block modes
3821 * from VDB can support YCBCR420 output too. So if bit=0 is
3822 * set, first mode from VDB can support YCBCR420 output too.
3823 * We will parse and keep this map, before parsing VDB itself
3824 * to avoid going through the same block again and again.
3825 *
3826 * Spec is not clear about max possible size of this block.
3827 * Clamping max bitmap block size at 8 bytes. Every byte can
3828 * address 8 CEA modes, in this way this map can address
3829 * 8*8 = first 64 SVDs.
3830 */
3831 if (WARN_ON_ONCE(map_len > 8))
3832 map_len = 8;
3833
3834 for (count = 0; count < map_len; count++)
3835 map |= (u64)db[2 + count] << (8 * count);
3836
3837 if (map)
3838 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3839
3840 hdmi->y420_cmdb_map = map;
3841}
3842
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003843static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003844add_cea_modes(struct drm_connector *connector, struct edid *edid)
3845{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003846 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003847 const u8 *db, *hdmi = NULL, *video = NULL;
3848 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003849 int modes = 0;
3850
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003851 if (cea && cea_revision(cea) >= 3) {
3852 int i, start, end;
3853
3854 if (cea_db_offsets(cea, &start, &end))
3855 return 0;
3856
3857 for_each_cea_db(cea, i, start, end) {
3858 db = &cea[i];
3859 dbl = cea_db_payload_len(db);
3860
Thomas Woodfbf46022013-10-16 15:58:50 +01003861 if (cea_db_tag(db) == VIDEO_BLOCK) {
3862 video = db + 1;
3863 video_len = dbl;
3864 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05303865 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003866 hdmi = db;
3867 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303868 } else if (cea_db_is_y420vdb(db)) {
3869 const u8 *vdb420 = &db[2];
3870
3871 /* Add 4:2:0(only) modes present in EDID */
3872 modes += do_y420vdb_modes(connector,
3873 vdb420,
3874 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003875 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003876 }
3877 }
3878
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003879 /*
3880 * We parse the HDMI VSDB after having added the cea modes as we will
3881 * be patching their flags when the sink supports stereo 3D.
3882 */
3883 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003884 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3885 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003886
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003887 return modes;
3888}
3889
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003890static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3891{
3892 const struct drm_display_mode *cea_mode;
3893 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02003894 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003895 const char *type;
3896
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003897 /*
3898 * allow 5kHz clock difference either way to account for
3899 * the 10kHz clock resolution limit of detailed timings.
3900 */
Jani Nikulad9278b42016-01-08 13:21:51 +02003901 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
3902 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003903 type = "CEA";
Jani Nikulad9278b42016-01-08 13:21:51 +02003904 cea_mode = &edid_cea_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003905 clock1 = cea_mode->clock;
3906 clock2 = cea_mode_alternate_clock(cea_mode);
3907 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003908 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
3909 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003910 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02003911 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003912 clock1 = cea_mode->clock;
3913 clock2 = hdmi_mode_alternate_clock(cea_mode);
3914 } else {
3915 return;
3916 }
3917 }
3918
3919 /* pick whichever is closest */
3920 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
3921 clock = clock1;
3922 else
3923 clock = clock2;
3924
3925 if (mode->clock == clock)
3926 return;
3927
3928 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02003929 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003930 mode->clock = clock;
3931}
3932
Uma Shankare85959d2019-05-16 19:40:08 +05303933static bool cea_db_is_hdmi_hdr_metadata_block(const u8 *db)
3934{
3935 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3936 return false;
3937
3938 if (db[1] != HDR_STATIC_METADATA_BLOCK)
3939 return false;
3940
3941 if (cea_db_payload_len(db) < 3)
3942 return false;
3943
3944 return true;
3945}
3946
3947static uint8_t eotf_supported(const u8 *edid_ext)
3948{
3949 return edid_ext[2] &
3950 (BIT(HDMI_EOTF_TRADITIONAL_GAMMA_SDR) |
3951 BIT(HDMI_EOTF_TRADITIONAL_GAMMA_HDR) |
Ville Syrjäläb5e3eed2019-05-16 19:40:12 +05303952 BIT(HDMI_EOTF_SMPTE_ST2084) |
3953 BIT(HDMI_EOTF_BT_2100_HLG));
Uma Shankare85959d2019-05-16 19:40:08 +05303954}
3955
3956static uint8_t hdr_metadata_type(const u8 *edid_ext)
3957{
3958 return edid_ext[3] &
3959 BIT(HDMI_STATIC_METADATA_TYPE1);
3960}
3961
3962static void
3963drm_parse_hdr_metadata_block(struct drm_connector *connector, const u8 *db)
3964{
3965 u16 len;
3966
3967 len = cea_db_payload_len(db);
3968
3969 connector->hdr_sink_metadata.hdmi_type1.eotf =
3970 eotf_supported(db);
3971 connector->hdr_sink_metadata.hdmi_type1.metadata_type =
3972 hdr_metadata_type(db);
3973
3974 if (len >= 4)
3975 connector->hdr_sink_metadata.hdmi_type1.max_cll = db[4];
3976 if (len >= 5)
3977 connector->hdr_sink_metadata.hdmi_type1.max_fall = db[5];
3978 if (len >= 6)
3979 connector->hdr_sink_metadata.hdmi_type1.min_cll = db[6];
3980}
3981
Wu Fengguang76adaa342011-09-05 14:23:20 +08003982static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003983drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003984{
Ville Syrjälä85040722012-08-16 14:55:05 +00003985 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003986
Jani Nikulaf7da77852017-11-01 16:20:57 +02003987 if (len >= 6 && (db[6] & (1 << 7)))
3988 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
Ville Syrjälä85040722012-08-16 14:55:05 +00003989 if (len >= 8) {
3990 connector->latency_present[0] = db[8] >> 7;
3991 connector->latency_present[1] = (db[8] >> 6) & 1;
3992 }
3993 if (len >= 9)
3994 connector->video_latency[0] = db[9];
3995 if (len >= 10)
3996 connector->audio_latency[0] = db[10];
3997 if (len >= 11)
3998 connector->video_latency[1] = db[11];
3999 if (len >= 12)
4000 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004001
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004002 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
4003 "video latency %d %d, "
4004 "audio latency %d %d\n",
4005 connector->latency_present[0],
4006 connector->latency_present[1],
4007 connector->video_latency[0],
4008 connector->video_latency[1],
4009 connector->audio_latency[0],
4010 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004011}
4012
4013static void
4014monitor_name(struct detailed_timing *t, void *data)
4015{
4016 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
4017 *(u8 **)data = t->data.other_data.data.str.str;
4018}
4019
Jim Bride59f7c0f2016-04-14 10:18:35 -07004020static int get_monitor_name(struct edid *edid, char name[13])
4021{
4022 char *edid_name = NULL;
4023 int mnl;
4024
4025 if (!edid || !name)
4026 return 0;
4027
4028 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
4029 for (mnl = 0; edid_name && mnl < 13; mnl++) {
4030 if (edid_name[mnl] == 0x0a)
4031 break;
4032
4033 name[mnl] = edid_name[mnl];
4034 }
4035
4036 return mnl;
4037}
4038
4039/**
4040 * drm_edid_get_monitor_name - fetch the monitor name from the edid
4041 * @edid: monitor EDID information
4042 * @name: pointer to a character array to hold the name of the monitor
4043 * @bufsize: The size of the name buffer (should be at least 14 chars.)
4044 *
4045 */
4046void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
4047{
4048 int name_length;
4049 char buf[13];
4050
4051 if (bufsize <= 0)
4052 return;
4053
4054 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
4055 memcpy(name, buf, name_length);
4056 name[name_length] = '\0';
4057}
4058EXPORT_SYMBOL(drm_edid_get_monitor_name);
4059
Jani Nikula42750d32017-11-01 16:21:00 +02004060static void clear_eld(struct drm_connector *connector)
4061{
4062 memset(connector->eld, 0, sizeof(connector->eld));
4063
4064 connector->latency_present[0] = false;
4065 connector->latency_present[1] = false;
4066 connector->video_latency[0] = 0;
4067 connector->audio_latency[0] = 0;
4068 connector->video_latency[1] = 0;
4069 connector->audio_latency[1] = 0;
4070}
4071
Jani Nikula79436a12017-11-01 16:21:03 +02004072/*
Wu Fengguang76adaa342011-09-05 14:23:20 +08004073 * drm_edid_to_eld - build ELD from EDID
4074 * @connector: connector corresponding to the HDMI/DP sink
4075 * @edid: EDID to parse
4076 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004077 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
Jani Nikula1d1c3662017-11-01 16:20:58 +02004078 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004079 */
Jani Nikula79436a12017-11-01 16:21:03 +02004080static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004081{
4082 uint8_t *eld = connector->eld;
4083 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004084 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02004085 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004086 int mnl;
4087 int dbl;
4088
Jani Nikula42750d32017-11-01 16:21:00 +02004089 clear_eld(connector);
Ville Syrjälä85c91582016-09-28 16:51:34 +03004090
Jani Nikulae9bd0b82017-02-17 17:20:52 +02004091 if (!edid)
4092 return;
4093
Wu Fengguang76adaa342011-09-05 14:23:20 +08004094 cea = drm_find_cea_extension(edid);
4095 if (!cea) {
4096 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
4097 return;
4098 }
4099
Jani Nikulaf7da77852017-11-01 16:20:57 +02004100 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
4101 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
Jim Bride59f7c0f2016-04-14 10:18:35 -07004102
Jani Nikulaf7da77852017-11-01 16:20:57 +02004103 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
4104 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004105
Jani Nikulaf7da77852017-11-01 16:20:57 +02004106 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004107
Jani Nikulaf7da77852017-11-01 16:20:57 +02004108 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
4109 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
4110 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
4111 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004112
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004113 if (cea_revision(cea) >= 3) {
4114 int i, start, end;
4115
4116 if (cea_db_offsets(cea, &start, &end)) {
4117 start = 0;
4118 end = 0;
4119 }
4120
4121 for_each_cea_db(cea, i, start, end) {
4122 db = &cea[i];
4123 dbl = cea_db_payload_len(db);
4124
4125 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02004126 int sad_count;
4127
Christian Schmidta0ab7342011-12-19 20:03:38 +01004128 case AUDIO_BLOCK:
4129 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02004130 sad_count = min(dbl / 3, 15 - total_sad_count);
4131 if (sad_count >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004132 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
Ville Syrjälä7c018782016-03-09 22:07:46 +02004133 &db[1], sad_count * 3);
4134 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01004135 break;
4136 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004137 /* Speaker Allocation Data Block */
4138 if (dbl >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004139 eld[DRM_ELD_SPEAKER] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01004140 break;
4141 case VENDOR_BLOCK:
4142 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004143 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004144 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01004145 break;
4146 default:
4147 break;
4148 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08004149 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004150 }
Jani Nikulaf7da77852017-11-01 16:20:57 +02004151 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004152
Jani Nikula1d1c3662017-11-01 16:20:58 +02004153 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4154 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4155 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
4156 else
4157 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004158
Jani Nikula938fd8a2014-10-28 16:20:48 +02004159 eld[DRM_ELD_BASELINE_ELD_LEN] =
4160 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
4161
4162 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02004163 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004164}
Wu Fengguang76adaa342011-09-05 14:23:20 +08004165
4166/**
Rafał Miłeckife214162013-04-19 19:01:25 +02004167 * drm_edid_to_sad - extracts SADs from EDID
4168 * @edid: EDID to parse
4169 * @sads: pointer that will be set to the extracted SADs
4170 *
4171 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02004172 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004173 * Note: The returned pointer needs to be freed using kfree().
4174 *
4175 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02004176 */
4177int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
4178{
4179 int count = 0;
4180 int i, start, end, dbl;
4181 u8 *cea;
4182
4183 cea = drm_find_cea_extension(edid);
4184 if (!cea) {
4185 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4186 return -ENOENT;
4187 }
4188
4189 if (cea_revision(cea) < 3) {
4190 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Daniel Vetterc7581a42019-09-04 16:39:42 +02004191 return -EOPNOTSUPP;
Rafał Miłeckife214162013-04-19 19:01:25 +02004192 }
4193
4194 if (cea_db_offsets(cea, &start, &end)) {
4195 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4196 return -EPROTO;
4197 }
4198
4199 for_each_cea_db(cea, i, start, end) {
4200 u8 *db = &cea[i];
4201
4202 if (cea_db_tag(db) == AUDIO_BLOCK) {
4203 int j;
4204 dbl = cea_db_payload_len(db);
4205
4206 count = dbl / 3; /* SAD is 3B */
4207 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
4208 if (!*sads)
4209 return -ENOMEM;
4210 for (j = 0; j < count; j++) {
4211 u8 *sad = &db[1 + j * 3];
4212
4213 (*sads)[j].format = (sad[0] & 0x78) >> 3;
4214 (*sads)[j].channels = sad[0] & 0x7;
4215 (*sads)[j].freq = sad[1] & 0x7F;
4216 (*sads)[j].byte2 = sad[2];
4217 }
4218 break;
4219 }
4220 }
4221
4222 return count;
4223}
4224EXPORT_SYMBOL(drm_edid_to_sad);
4225
4226/**
Alex Deucherd105f472013-07-25 15:55:32 -04004227 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4228 * @edid: EDID to parse
4229 * @sadb: pointer to the speaker block
4230 *
4231 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04004232 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004233 * Note: The returned pointer needs to be freed using kfree().
4234 *
4235 * Return: The number of found Speaker Allocation Blocks or negative number on
4236 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004237 */
4238int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4239{
4240 int count = 0;
4241 int i, start, end, dbl;
4242 const u8 *cea;
4243
4244 cea = drm_find_cea_extension(edid);
4245 if (!cea) {
4246 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4247 return -ENOENT;
4248 }
4249
4250 if (cea_revision(cea) < 3) {
4251 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Daniel Vetterc7581a42019-09-04 16:39:42 +02004252 return -EOPNOTSUPP;
Alex Deucherd105f472013-07-25 15:55:32 -04004253 }
4254
4255 if (cea_db_offsets(cea, &start, &end)) {
4256 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4257 return -EPROTO;
4258 }
4259
4260 for_each_cea_db(cea, i, start, end) {
4261 const u8 *db = &cea[i];
4262
4263 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4264 dbl = cea_db_payload_len(db);
4265
4266 /* Speaker Allocation Data Block */
4267 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004268 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004269 if (!*sadb)
4270 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004271 count = dbl;
4272 break;
4273 }
4274 }
4275 }
4276
4277 return count;
4278}
4279EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4280
4281/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004282 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004283 * @connector: connector associated with the HDMI/DP sink
4284 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004285 *
4286 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4287 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004288 */
4289int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004290 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004291{
4292 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4293 int a, v;
4294
4295 if (!connector->latency_present[0])
4296 return 0;
4297 if (!connector->latency_present[1])
4298 i = 0;
4299
4300 a = connector->audio_latency[i];
4301 v = connector->video_latency[i];
4302
4303 /*
4304 * HDMI/DP sink doesn't support audio or video?
4305 */
4306 if (a == 255 || v == 255)
4307 return 0;
4308
4309 /*
4310 * Convert raw EDID values to millisecond.
4311 * Treat unknown latency as 0ms.
4312 */
4313 if (a)
4314 a = min(2 * (a - 1), 500);
4315 if (v)
4316 v = min(2 * (v - 1), 500);
4317
4318 return max(v - a, 0);
4319}
4320EXPORT_SYMBOL(drm_av_sync_delay);
4321
4322/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004323 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004324 * @edid: monitor EDID information
4325 *
4326 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004327 *
4328 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004329 */
4330bool drm_detect_hdmi_monitor(struct edid *edid)
4331{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004332 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004333 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004334 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004335
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004336 edid_ext = drm_find_cea_extension(edid);
4337 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004338 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004339
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004340 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004341 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004342
4343 /*
4344 * Because HDMI identifier is in Vendor Specific Block,
4345 * search it from all data blocks of CEA extension.
4346 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004347 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004348 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4349 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004350 }
4351
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004352 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004353}
4354EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4355
Dave Airlief453ba02008-11-07 14:05:41 -08004356/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004357 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004358 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004359 *
4360 * Monitor should have CEA extension block.
4361 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4362 * audio' only. If there is any audio extension block and supported
4363 * audio format, assume at least 'basic audio' support, even if 'basic
4364 * audio' is not defined in EDID.
4365 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004366 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004367 */
4368bool drm_detect_monitor_audio(struct edid *edid)
4369{
4370 u8 *edid_ext;
4371 int i, j;
4372 bool has_audio = false;
4373 int start_offset, end_offset;
4374
4375 edid_ext = drm_find_cea_extension(edid);
4376 if (!edid_ext)
4377 goto end;
4378
4379 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4380
4381 if (has_audio) {
4382 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4383 goto end;
4384 }
4385
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004386 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4387 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004388
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004389 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4390 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004391 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004392 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004393 DRM_DEBUG_KMS("CEA audio format %d\n",
4394 (edid_ext[i + j] >> 3) & 0xf);
4395 goto end;
4396 }
4397 }
4398end:
4399 return has_audio;
4400}
4401EXPORT_SYMBOL(drm_detect_monitor_audio);
4402
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004403
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004404/**
4405 * drm_default_rgb_quant_range - default RGB quantization range
4406 * @mode: display mode
4407 *
4408 * Determine the default RGB quantization range for the mode,
4409 * as specified in CEA-861.
4410 *
4411 * Return: The default RGB quantization range for the mode
4412 */
4413enum hdmi_quantization_range
4414drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4415{
4416 /* All CEA modes other than VIC 1 use limited quantization range. */
4417 return drm_match_cea_mode(mode) > 1 ?
4418 HDMI_QUANTIZATION_RANGE_LIMITED :
4419 HDMI_QUANTIZATION_RANGE_FULL;
4420}
4421EXPORT_SYMBOL(drm_default_rgb_quant_range);
4422
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004423static void drm_parse_vcdb(struct drm_connector *connector, const u8 *db)
4424{
4425 struct drm_display_info *info = &connector->display_info;
4426
4427 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", db[2]);
4428
4429 if (db[2] & EDID_CEA_VCDB_QS)
4430 info->rgb_quant_range_selectable = true;
4431}
4432
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304433static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4434 const u8 *db)
4435{
4436 u8 dc_mask;
4437 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4438
4439 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
Clint Taylor9068e022018-10-05 14:52:15 -07004440 hdmi->y420_dc_modes = dc_mask;
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304441}
4442
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304443static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4444 const u8 *hf_vsdb)
4445{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304446 struct drm_display_info *display = &connector->display_info;
4447 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304448
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004449 display->has_hdmi_infoframe = true;
4450
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304451 if (hf_vsdb[6] & 0x80) {
4452 hdmi->scdc.supported = true;
4453 if (hf_vsdb[6] & 0x40)
4454 hdmi->scdc.read_request = true;
4455 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304456
4457 /*
4458 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4459 * And as per the spec, three factors confirm this:
4460 * * Availability of a HF-VSDB block in EDID (check)
4461 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4462 * * SCDC support available (let's check)
4463 * Lets check it out.
4464 */
4465
4466 if (hf_vsdb[5]) {
4467 /* max clock is 5000 KHz times block value */
4468 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4469 struct drm_scdc *scdc = &hdmi->scdc;
4470
4471 if (max_tmds_clock > 340000) {
4472 display->max_tmds_clock = max_tmds_clock;
4473 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4474 display->max_tmds_clock);
4475 }
4476
4477 if (scdc->supported) {
4478 scdc->scrambling.supported = true;
4479
4480 /* Few sinks support scrambling for cloks < 340M */
4481 if ((hf_vsdb[6] & 0x8))
4482 scdc->scrambling.low_rates = true;
4483 }
4484 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304485
4486 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304487}
4488
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004489static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4490 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01004491{
Ville Syrjälä18267502016-09-28 16:51:38 +03004492 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004493 unsigned int dc_bpc = 0;
4494
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004495 /* HDMI supports at least 8 bpc */
4496 info->bpc = 8;
4497
4498 if (cea_db_payload_len(hdmi) < 6)
4499 return;
4500
4501 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4502 dc_bpc = 10;
4503 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4504 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4505 connector->name);
4506 }
4507
4508 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4509 dc_bpc = 12;
4510 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4511 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4512 connector->name);
4513 }
4514
4515 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4516 dc_bpc = 16;
4517 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4518 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4519 connector->name);
4520 }
4521
4522 if (dc_bpc == 0) {
4523 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4524 connector->name);
4525 return;
4526 }
4527
4528 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4529 connector->name, dc_bpc);
4530 info->bpc = dc_bpc;
4531
4532 /*
4533 * Deep color support mandates RGB444 support for all video
4534 * modes and forbids YCRCB422 support for all video modes per
4535 * HDMI 1.3 spec.
4536 */
4537 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4538
4539 /* YCRCB444 is optional according to spec. */
4540 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4541 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4542 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4543 connector->name);
4544 }
4545
4546 /*
4547 * Spec says that if any deep color mode is supported at all,
4548 * then deep color 36 bit must be supported.
4549 */
4550 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4551 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4552 connector->name);
4553 }
4554}
4555
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004556static void
4557drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4558{
4559 struct drm_display_info *info = &connector->display_info;
4560 u8 len = cea_db_payload_len(db);
4561
4562 if (len >= 6)
4563 info->dvi_dual = db[6] & 1;
4564 if (len >= 7)
4565 info->max_tmds_clock = db[7] * 5000;
4566
4567 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4568 "max TMDS clock %d kHz\n",
4569 info->dvi_dual,
4570 info->max_tmds_clock);
4571
4572 drm_parse_hdmi_deep_color_info(connector, db);
4573}
4574
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004575static void drm_parse_cea_ext(struct drm_connector *connector,
Keith Packard170178f2017-12-13 00:44:26 -08004576 const struct edid *edid)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004577{
4578 struct drm_display_info *info = &connector->display_info;
4579 const u8 *edid_ext;
4580 int i, start, end;
4581
Mario Kleinerd0c94692014-03-27 19:59:39 +01004582 edid_ext = drm_find_cea_extension(edid);
4583 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004584 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004585
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004586 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004587
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004588 /* The existence of a CEA block should imply RGB support */
4589 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4590 if (edid_ext[3] & EDID_CEA_YCRCB444)
4591 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4592 if (edid_ext[3] & EDID_CEA_YCRCB422)
4593 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004594
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004595 if (cea_db_offsets(edid_ext, &start, &end))
4596 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004597
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004598 for_each_cea_db(edid_ext, i, start, end) {
4599 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004600
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004601 if (cea_db_is_hdmi_vsdb(db))
4602 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304603 if (cea_db_is_hdmi_forum_vsdb(db))
4604 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304605 if (cea_db_is_y420cmdb(db))
4606 drm_parse_y420cmdb_bitmap(connector, db);
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004607 if (cea_db_is_vcdb(db))
4608 drm_parse_vcdb(connector, db);
Uma Shankare85959d2019-05-16 19:40:08 +05304609 if (cea_db_is_hdmi_hdr_metadata_block(db))
4610 drm_parse_hdr_metadata_block(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004611 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01004612}
4613
Keith Packard170178f2017-12-13 00:44:26 -08004614/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
4615 * all of the values which would have been set from EDID
4616 */
4617void
4618drm_reset_display_info(struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07004619{
Ville Syrjälä18267502016-09-28 16:51:38 +03004620 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07004621
Keith Packard170178f2017-12-13 00:44:26 -08004622 info->width_mm = 0;
4623 info->height_mm = 0;
4624
4625 info->bpc = 0;
4626 info->color_formats = 0;
4627 info->cea_rev = 0;
4628 info->max_tmds_clock = 0;
4629 info->dvi_dual = false;
4630 info->has_hdmi_infoframe = false;
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004631 info->rgb_quant_range_selectable = false;
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03004632 memset(&info->hdmi, 0, sizeof(info->hdmi));
Keith Packard170178f2017-12-13 00:44:26 -08004633
4634 info->non_desktop = 0;
4635}
Keith Packard170178f2017-12-13 00:44:26 -08004636
4637u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
4638{
4639 struct drm_display_info *info = &connector->display_info;
4640
4641 u32 quirks = edid_get_quirks(edid);
4642
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03004643 drm_reset_display_info(connector);
4644
Jesse Barnes3b112282011-04-15 12:49:23 -07004645 info->width_mm = edid->width_cm * 10;
4646 info->height_mm = edid->height_cm * 10;
4647
Dave Airlie66660d42017-10-16 05:08:09 +01004648 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4649
Keith Packard170178f2017-12-13 00:44:26 -08004650 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
4651
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004652 if (edid->revision < 3)
Keith Packard170178f2017-12-13 00:44:26 -08004653 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004654
4655 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
Keith Packard170178f2017-12-13 00:44:26 -08004656 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004657
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004658 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004659
Mario Kleiner210a0212016-07-06 12:05:48 +02004660 /*
4661 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4662 *
4663 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4664 * tells us to assume 8 bpc color depth if the EDID doesn't have
4665 * extensions which tell otherwise.
4666 */
Ville Syrjälä3bde4492019-05-29 14:02:04 +03004667 if (info->bpc == 0 && edid->revision == 3 &&
4668 edid->input & DRM_EDID_DIGITAL_DFP_1_X) {
Mario Kleiner210a0212016-07-06 12:05:48 +02004669 info->bpc = 8;
4670 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4671 connector->name, info->bpc);
4672 }
4673
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004674 /* Only defined for 1.4 with digital displays */
4675 if (edid->revision < 4)
Keith Packard170178f2017-12-13 00:44:26 -08004676 return quirks;
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004677
Jesse Barnes3b112282011-04-15 12:49:23 -07004678 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4679 case DRM_EDID_DIGITAL_DEPTH_6:
4680 info->bpc = 6;
4681 break;
4682 case DRM_EDID_DIGITAL_DEPTH_8:
4683 info->bpc = 8;
4684 break;
4685 case DRM_EDID_DIGITAL_DEPTH_10:
4686 info->bpc = 10;
4687 break;
4688 case DRM_EDID_DIGITAL_DEPTH_12:
4689 info->bpc = 12;
4690 break;
4691 case DRM_EDID_DIGITAL_DEPTH_14:
4692 info->bpc = 14;
4693 break;
4694 case DRM_EDID_DIGITAL_DEPTH_16:
4695 info->bpc = 16;
4696 break;
4697 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4698 default:
4699 info->bpc = 0;
4700 break;
4701 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004702
Mario Kleinerd0c94692014-03-27 19:59:39 +01004703 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004704 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004705
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004706 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004707 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4708 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4709 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4710 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Keith Packard170178f2017-12-13 00:44:26 -08004711 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07004712}
4713
Dave Airliec97291772016-05-03 15:38:37 +10004714static int validate_displayid(u8 *displayid, int length, int idx)
4715{
4716 int i;
4717 u8 csum = 0;
4718 struct displayid_hdr *base;
4719
4720 base = (struct displayid_hdr *)&displayid[idx];
4721
4722 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4723 base->rev, base->bytes, base->prod_id, base->ext_count);
4724
4725 if (base->bytes + 5 > length - idx)
4726 return -EINVAL;
4727 for (i = idx; i <= base->bytes + 5; i++) {
4728 csum += displayid[i];
4729 }
4730 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004731 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004732 return -EINVAL;
4733 }
4734 return 0;
4735}
4736
Dave Airliea39ed682016-05-02 08:35:05 +10004737static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4738 struct displayid_detailed_timings_1 *timings)
4739{
4740 struct drm_display_mode *mode;
4741 unsigned pixel_clock = (timings->pixel_clock[0] |
4742 (timings->pixel_clock[1] << 8) |
4743 (timings->pixel_clock[2] << 16));
4744 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4745 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4746 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4747 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4748 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4749 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4750 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4751 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4752 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4753 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4754 mode = drm_mode_create(dev);
4755 if (!mode)
4756 return NULL;
4757
4758 mode->clock = pixel_clock * 10;
4759 mode->hdisplay = hactive;
4760 mode->hsync_start = mode->hdisplay + hsync;
4761 mode->hsync_end = mode->hsync_start + hsync_width;
4762 mode->htotal = mode->hdisplay + hblank;
4763
4764 mode->vdisplay = vactive;
4765 mode->vsync_start = mode->vdisplay + vsync;
4766 mode->vsync_end = mode->vsync_start + vsync_width;
4767 mode->vtotal = mode->vdisplay + vblank;
4768
4769 mode->flags = 0;
4770 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4771 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4772 mode->type = DRM_MODE_TYPE_DRIVER;
4773
4774 if (timings->flags & 0x80)
4775 mode->type |= DRM_MODE_TYPE_PREFERRED;
4776 mode->vrefresh = drm_mode_vrefresh(mode);
4777 drm_mode_set_name(mode);
4778
4779 return mode;
4780}
4781
4782static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4783 struct displayid_block *block)
4784{
4785 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4786 int i;
4787 int num_timings;
4788 struct drm_display_mode *newmode;
4789 int num_modes = 0;
4790 /* blocks must be multiple of 20 bytes length */
4791 if (block->num_bytes % 20)
4792 return 0;
4793
4794 num_timings = block->num_bytes / 20;
4795 for (i = 0; i < num_timings; i++) {
4796 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4797
4798 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4799 if (!newmode)
4800 continue;
4801
4802 drm_mode_probed_add(connector, newmode);
4803 num_modes++;
4804 }
4805 return num_modes;
4806}
4807
4808static int add_displayid_detailed_modes(struct drm_connector *connector,
4809 struct edid *edid)
4810{
4811 u8 *displayid;
4812 int ret;
4813 int idx = 1;
4814 int length = EDID_LENGTH;
4815 struct displayid_block *block;
4816 int num_modes = 0;
4817
4818 displayid = drm_find_displayid_extension(edid);
4819 if (!displayid)
4820 return 0;
4821
4822 ret = validate_displayid(displayid, length, idx);
4823 if (ret)
4824 return 0;
4825
4826 idx += sizeof(struct displayid_hdr);
Andres Rodriguez80d42db2019-06-19 14:30:33 -04004827 for_each_displayid_db(displayid, block, idx, length) {
Dave Airliea39ed682016-05-02 08:35:05 +10004828 switch (block->tag) {
4829 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4830 num_modes += add_displayid_detailed_1_modes(connector, block);
4831 break;
4832 }
4833 }
4834 return num_modes;
4835}
4836
Jesse Barnes3b112282011-04-15 12:49:23 -07004837/**
Dave Airlief453ba02008-11-07 14:05:41 -08004838 * drm_add_edid_modes - add modes from EDID data, if available
4839 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004840 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004841 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004842 * Add the specified modes to the connector's mode list. Also fills out the
Jani Nikulac945b8c2017-11-01 16:21:01 +02004843 * &drm_display_info structure and ELD in @connector with any information which
4844 * can be derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004845 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004846 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004847 */
4848int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4849{
4850 int num_modes = 0;
4851 u32 quirks;
4852
4853 if (edid == NULL) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004854 clear_eld(connector);
Dave Airlief453ba02008-11-07 14:05:41 -08004855 return 0;
4856 }
Alex Deucher3c537882010-02-05 04:21:19 -05004857 if (!drm_edid_is_valid(edid)) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02004858 clear_eld(connector);
Jordan Crousedcdb1672010-05-27 13:40:25 -06004859 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004860 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004861 return 0;
4862 }
4863
Jani Nikulac945b8c2017-11-01 16:21:01 +02004864 drm_edid_to_eld(connector, edid);
4865
Adam Jacksonc867df72010-03-29 21:43:21 +00004866 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304867 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4868 * To avoid multiple parsing of same block, lets parse that map
4869 * from sink info, before parsing CEA modes.
4870 */
Keith Packard170178f2017-12-13 00:44:26 -08004871 quirks = drm_add_display_info(connector, edid);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304872
4873 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00004874 * EDID spec says modes should be preferred in this order:
4875 * - preferred detailed mode
4876 * - other detailed modes from base block
4877 * - detailed modes from extension blocks
4878 * - CVT 3-byte code modes
4879 * - standard timing codes
4880 * - established timing codes
4881 * - modes inferred from GTF or CVT range information
4882 *
Adam Jackson13931572010-08-03 14:38:19 -04004883 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00004884 *
4885 * XXX order for additional mode types in extension blocks?
4886 */
Adam Jackson13931572010-08-03 14:38:19 -04004887 num_modes += add_detailed_modes(connector, edid, quirks);
4888 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00004889 num_modes += add_standard_modes(connector, edid);
4890 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004891 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03004892 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10004893 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03004894 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
4895 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08004896
4897 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
4898 edid_fixup_preferred(connector, quirks);
4899
Mario Kleinere10aec62016-07-06 12:05:44 +02004900 if (quirks & EDID_QUIRK_FORCE_6BPC)
4901 connector->display_info.bpc = 6;
4902
Rafał Miłecki49d45a312013-12-07 13:22:42 +01004903 if (quirks & EDID_QUIRK_FORCE_8BPC)
4904 connector->display_info.bpc = 8;
4905
Mario Kleinere345da82017-04-21 17:05:08 +02004906 if (quirks & EDID_QUIRK_FORCE_10BPC)
4907 connector->display_info.bpc = 10;
4908
Mario Kleinerbc5b9642014-05-23 21:40:55 +02004909 if (quirks & EDID_QUIRK_FORCE_12BPC)
4910 connector->display_info.bpc = 12;
4911
Dave Airlief453ba02008-11-07 14:05:41 -08004912 return num_modes;
4913}
4914EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004915
4916/**
4917 * drm_add_modes_noedid - add modes for the connectors without EDID
4918 * @connector: connector we're probing
4919 * @hdisplay: the horizontal display limit
4920 * @vdisplay: the vertical display limit
4921 *
4922 * Add the specified modes to the connector's mode list. Only when the
4923 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4924 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004925 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004926 */
4927int drm_add_modes_noedid(struct drm_connector *connector,
4928 int hdisplay, int vdisplay)
4929{
4930 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004931 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004932 struct drm_device *dev = connector->dev;
4933
Daniel Vetterfbb40b22015-08-10 11:55:37 +02004934 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004935 if (hdisplay < 0)
4936 hdisplay = 0;
4937 if (vdisplay < 0)
4938 vdisplay = 0;
4939
4940 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004941 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004942 if (hdisplay && vdisplay) {
4943 /*
4944 * Only when two are valid, they will be used to check
4945 * whether the mode should be added to the mode list of
4946 * the connector.
4947 */
4948 if (ptr->hdisplay > hdisplay ||
4949 ptr->vdisplay > vdisplay)
4950 continue;
4951 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05004952 if (drm_mode_vrefresh(ptr) > 61)
4953 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004954 mode = drm_mode_duplicate(dev, ptr);
4955 if (mode) {
4956 drm_mode_probed_add(connector, mode);
4957 num_modes++;
4958 }
4959 }
4960 return num_modes;
4961}
4962EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01004963
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004964/**
4965 * drm_set_preferred_mode - Sets the preferred mode of a connector
4966 * @connector: connector whose mode list should be processed
4967 * @hpref: horizontal resolution of preferred mode
4968 * @vpref: vertical resolution of preferred mode
4969 *
4970 * Marks a mode as preferred if it matches the resolution specified by @hpref
4971 * and @vpref.
4972 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004973void drm_set_preferred_mode(struct drm_connector *connector,
4974 int hpref, int vpref)
4975{
4976 struct drm_display_mode *mode;
4977
4978 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004979 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01004980 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004981 mode->type |= DRM_MODE_TYPE_PREFERRED;
4982 }
4983}
4984EXPORT_SYMBOL(drm_set_preferred_mode);
4985
Ville Syrjälä13d0add2019-01-08 19:28:25 +02004986static bool is_hdmi2_sink(struct drm_connector *connector)
4987{
4988 /*
4989 * FIXME: sil-sii8620 doesn't have a connector around when
4990 * we need one, so we have to be prepared for a NULL connector.
4991 */
4992 if (!connector)
4993 return true;
4994
4995 return connector->display_info.hdmi.scdc.supported ||
4996 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCRCB420;
4997}
4998
Uma Shankar2cdbfd62019-05-16 19:40:09 +05304999static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
5000{
5001 return sink_eotf & BIT(output_eotf);
5002}
5003
5004/**
5005 * drm_hdmi_infoframe_set_hdr_metadata() - fill an HDMI DRM infoframe with
5006 * HDR metadata from userspace
5007 * @frame: HDMI DRM infoframe
Sean Paul6ac98822019-05-23 09:54:58 -04005008 * @conn_state: Connector state containing HDR metadata
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305009 *
5010 * Return: 0 on success or a negative error code on failure.
5011 */
5012int
5013drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
5014 const struct drm_connector_state *conn_state)
5015{
5016 struct drm_connector *connector;
5017 struct hdr_output_metadata *hdr_metadata;
5018 int err;
5019
5020 if (!frame || !conn_state)
5021 return -EINVAL;
5022
5023 connector = conn_state->connector;
5024
5025 if (!conn_state->hdr_output_metadata)
5026 return -EINVAL;
5027
5028 hdr_metadata = conn_state->hdr_output_metadata->data;
5029
5030 if (!hdr_metadata || !connector)
5031 return -EINVAL;
5032
5033 /* Sink EOTF is Bit map while infoframe is absolute values */
5034 if (!is_eotf_supported(hdr_metadata->hdmi_metadata_type1.eotf,
5035 connector->hdr_sink_metadata.hdmi_type1.eotf)) {
5036 DRM_DEBUG_KMS("EOTF Not Supported\n");
5037 return -EINVAL;
5038 }
5039
5040 err = hdmi_drm_infoframe_init(frame);
5041 if (err < 0)
5042 return err;
5043
5044 frame->eotf = hdr_metadata->hdmi_metadata_type1.eotf;
5045 frame->metadata_type = hdr_metadata->hdmi_metadata_type1.metadata_type;
5046
5047 BUILD_BUG_ON(sizeof(frame->display_primaries) !=
5048 sizeof(hdr_metadata->hdmi_metadata_type1.display_primaries));
5049 BUILD_BUG_ON(sizeof(frame->white_point) !=
5050 sizeof(hdr_metadata->hdmi_metadata_type1.white_point));
5051
5052 memcpy(&frame->display_primaries,
5053 &hdr_metadata->hdmi_metadata_type1.display_primaries,
5054 sizeof(frame->display_primaries));
5055
5056 memcpy(&frame->white_point,
5057 &hdr_metadata->hdmi_metadata_type1.white_point,
5058 sizeof(frame->white_point));
5059
5060 frame->max_display_mastering_luminance =
5061 hdr_metadata->hdmi_metadata_type1.max_display_mastering_luminance;
5062 frame->min_display_mastering_luminance =
5063 hdr_metadata->hdmi_metadata_type1.min_display_mastering_luminance;
5064 frame->max_fall = hdr_metadata->hdmi_metadata_type1.max_fall;
5065 frame->max_cll = hdr_metadata->hdmi_metadata_type1.max_cll;
5066
5067 return 0;
5068}
5069EXPORT_SYMBOL(drm_hdmi_infoframe_set_hdr_metadata);
5070
Thierry Reding10a85122012-11-21 15:31:35 +01005071/**
5072 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
5073 * data from a DRM display mode
5074 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005075 * @connector: the connector
Thierry Reding10a85122012-11-21 15:31:35 +01005076 * @mode: DRM display mode
5077 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005078 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01005079 */
5080int
5081drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005082 struct drm_connector *connector,
5083 const struct drm_display_mode *mode)
Thierry Reding10a85122012-11-21 15:31:35 +01005084{
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305085 enum hdmi_picture_aspect picture_aspect;
Thierry Reding10a85122012-11-21 15:31:35 +01005086 int err;
5087
5088 if (!frame || !mode)
5089 return -EINVAL;
5090
5091 err = hdmi_avi_infoframe_init(frame);
5092 if (err < 0)
5093 return err;
5094
Damien Lespiaubf02db92013-08-06 20:32:22 +01005095 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
5096 frame->pixel_repeat = 1;
5097
Thierry Reding10a85122012-11-21 15:31:35 +01005098 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01005099
Shashank Sharma0c1f5282017-07-13 21:03:07 +05305100 /*
5101 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
5102 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
5103 * have to make sure we dont break HDMI 1.4 sinks.
5104 */
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005105 if (!is_hdmi2_sink(connector) && frame->video_code > 64)
Shashank Sharma0c1f5282017-07-13 21:03:07 +05305106 frame->video_code = 0;
5107
5108 /*
5109 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
5110 * we should send its VIC in vendor infoframes, else send the
5111 * VIC in AVI infoframes. Lets check if this mode is present in
5112 * HDMI 1.4b 4K modes
5113 */
5114 if (frame->video_code) {
5115 u8 vendor_if_vic = drm_match_hdmi_mode(mode);
5116 bool is_s3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
5117
5118 if (drm_valid_hdmi_vic(vendor_if_vic) && !is_s3d)
5119 frame->video_code = 0;
5120 }
5121
Thierry Reding10a85122012-11-21 15:31:35 +01005122 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305123
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305124 /*
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +03005125 * As some drivers don't support atomic, we can't use connector state.
5126 * So just initialize the frame with default values, just the same way
5127 * as it's done with other properties here.
5128 */
5129 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
5130 frame->itc = 0;
5131
5132 /*
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305133 * Populate picture aspect ratio from either
5134 * user input (if specified) or from the CEA mode list.
5135 */
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305136 picture_aspect = mode->picture_aspect_ratio;
5137 if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
5138 picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305139
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305140 /*
5141 * The infoframe can't convey anything but none, 4:3
5142 * and 16:9, so if the user has asked for anything else
5143 * we can only satisfy it by specifying the right VIC.
5144 */
5145 if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
5146 if (picture_aspect !=
5147 drm_get_cea_aspect_ratio(frame->video_code))
5148 return -EINVAL;
5149 picture_aspect = HDMI_PICTURE_ASPECT_NONE;
5150 }
5151
5152 frame->picture_aspect = picture_aspect;
Thierry Reding10a85122012-11-21 15:31:35 +01005153 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06005154 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01005155
5156 return 0;
5157}
5158EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005159
Uma Shankar0d68b882019-02-19 22:43:00 +05305160/* HDMI Colorspace Spec Definitions */
5161#define FULL_COLORIMETRY_MASK 0x1FF
5162#define NORMAL_COLORIMETRY_MASK 0x3
5163#define EXTENDED_COLORIMETRY_MASK 0x7
5164#define EXTENDED_ACE_COLORIMETRY_MASK 0xF
5165
5166#define C(x) ((x) << 0)
5167#define EC(x) ((x) << 2)
5168#define ACE(x) ((x) << 5)
5169
5170#define HDMI_COLORIMETRY_NO_DATA 0x0
5171#define HDMI_COLORIMETRY_SMPTE_170M_YCC (C(1) | EC(0) | ACE(0))
5172#define HDMI_COLORIMETRY_BT709_YCC (C(2) | EC(0) | ACE(0))
5173#define HDMI_COLORIMETRY_XVYCC_601 (C(3) | EC(0) | ACE(0))
5174#define HDMI_COLORIMETRY_XVYCC_709 (C(3) | EC(1) | ACE(0))
5175#define HDMI_COLORIMETRY_SYCC_601 (C(3) | EC(2) | ACE(0))
5176#define HDMI_COLORIMETRY_OPYCC_601 (C(3) | EC(3) | ACE(0))
5177#define HDMI_COLORIMETRY_OPRGB (C(3) | EC(4) | ACE(0))
5178#define HDMI_COLORIMETRY_BT2020_CYCC (C(3) | EC(5) | ACE(0))
5179#define HDMI_COLORIMETRY_BT2020_RGB (C(3) | EC(6) | ACE(0))
5180#define HDMI_COLORIMETRY_BT2020_YCC (C(3) | EC(6) | ACE(0))
5181#define HDMI_COLORIMETRY_DCI_P3_RGB_D65 (C(3) | EC(7) | ACE(0))
5182#define HDMI_COLORIMETRY_DCI_P3_RGB_THEATER (C(3) | EC(7) | ACE(1))
5183
5184static const u32 hdmi_colorimetry_val[] = {
5185 [DRM_MODE_COLORIMETRY_NO_DATA] = HDMI_COLORIMETRY_NO_DATA,
5186 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = HDMI_COLORIMETRY_SMPTE_170M_YCC,
5187 [DRM_MODE_COLORIMETRY_BT709_YCC] = HDMI_COLORIMETRY_BT709_YCC,
5188 [DRM_MODE_COLORIMETRY_XVYCC_601] = HDMI_COLORIMETRY_XVYCC_601,
5189 [DRM_MODE_COLORIMETRY_XVYCC_709] = HDMI_COLORIMETRY_XVYCC_709,
5190 [DRM_MODE_COLORIMETRY_SYCC_601] = HDMI_COLORIMETRY_SYCC_601,
5191 [DRM_MODE_COLORIMETRY_OPYCC_601] = HDMI_COLORIMETRY_OPYCC_601,
5192 [DRM_MODE_COLORIMETRY_OPRGB] = HDMI_COLORIMETRY_OPRGB,
5193 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = HDMI_COLORIMETRY_BT2020_CYCC,
5194 [DRM_MODE_COLORIMETRY_BT2020_RGB] = HDMI_COLORIMETRY_BT2020_RGB,
5195 [DRM_MODE_COLORIMETRY_BT2020_YCC] = HDMI_COLORIMETRY_BT2020_YCC,
5196};
5197
5198#undef C
5199#undef EC
5200#undef ACE
5201
5202/**
5203 * drm_hdmi_avi_infoframe_colorspace() - fill the HDMI AVI infoframe
5204 * colorspace information
5205 * @frame: HDMI AVI infoframe
5206 * @conn_state: connector state
5207 */
5208void
5209drm_hdmi_avi_infoframe_colorspace(struct hdmi_avi_infoframe *frame,
5210 const struct drm_connector_state *conn_state)
5211{
5212 u32 colorimetry_val;
5213 u32 colorimetry_index = conn_state->colorspace & FULL_COLORIMETRY_MASK;
5214
5215 if (colorimetry_index >= ARRAY_SIZE(hdmi_colorimetry_val))
5216 colorimetry_val = HDMI_COLORIMETRY_NO_DATA;
5217 else
5218 colorimetry_val = hdmi_colorimetry_val[colorimetry_index];
5219
5220 frame->colorimetry = colorimetry_val & NORMAL_COLORIMETRY_MASK;
5221 /*
5222 * ToDo: Extend it for ACE formats as well. Modify the infoframe
5223 * structure and extend it in drivers/video/hdmi
5224 */
5225 frame->extended_colorimetry = (colorimetry_val >> 2) &
5226 EXTENDED_COLORIMETRY_MASK;
5227}
5228EXPORT_SYMBOL(drm_hdmi_avi_infoframe_colorspace);
5229
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005230/**
5231 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
5232 * quantization range information
5233 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005234 * @connector: the connector
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005235 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005236 * @rgb_quant_range: RGB quantization range (Q)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005237 */
5238void
5239drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005240 struct drm_connector *connector,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005241 const struct drm_display_mode *mode,
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005242 enum hdmi_quantization_range rgb_quant_range)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005243{
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005244 const struct drm_display_info *info = &connector->display_info;
5245
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005246 /*
5247 * CEA-861:
5248 * "A Source shall not send a non-zero Q value that does not correspond
5249 * to the default RGB Quantization Range for the transmitted Picture
5250 * unless the Sink indicates support for the Q bit in a Video
5251 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005252 *
5253 * HDMI 2.0 recommends sending non-zero Q when it does match the
5254 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005255 */
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005256 if (info->rgb_quant_range_selectable ||
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005257 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005258 frame->quantization_range = rgb_quant_range;
5259 else
5260 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005261
5262 /*
5263 * CEA-861-F:
5264 * "When transmitting any RGB colorimetry, the Source should set the
5265 * YQ-field to match the RGB Quantization Range being transmitted
5266 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
5267 * set YQ=1) and the Sink shall ignore the YQ-field."
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005268 *
5269 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
5270 * by non-zero YQ when receiving RGB. There doesn't seem to be any
5271 * good way to tell which version of CEA-861 the sink supports, so
5272 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
5273 * on on CEA-861-F.
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005274 */
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005275 if (!is_hdmi2_sink(connector) ||
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005276 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005277 frame->ycc_quantization_range =
5278 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
5279 else
5280 frame->ycc_quantization_range =
5281 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005282}
5283EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
5284
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005285static enum hdmi_3d_structure
5286s3d_structure_from_display_mode(const struct drm_display_mode *mode)
5287{
5288 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
5289
5290 switch (layout) {
5291 case DRM_MODE_FLAG_3D_FRAME_PACKING:
5292 return HDMI_3D_STRUCTURE_FRAME_PACKING;
5293 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
5294 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
5295 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
5296 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
5297 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
5298 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
5299 case DRM_MODE_FLAG_3D_L_DEPTH:
5300 return HDMI_3D_STRUCTURE_L_DEPTH;
5301 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
5302 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
5303 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
5304 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
5305 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
5306 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
5307 default:
5308 return HDMI_3D_STRUCTURE_INVALID;
5309 }
5310}
5311
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005312/**
5313 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
5314 * data from a DRM display mode
5315 * @frame: HDMI vendor infoframe
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005316 * @connector: the connector
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005317 * @mode: DRM display mode
5318 *
5319 * Note that there's is a need to send HDMI vendor infoframes only when using a
5320 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
5321 * function will return -EINVAL, error that can be safely ignored.
5322 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005323 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005324 */
5325int
5326drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005327 struct drm_connector *connector,
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005328 const struct drm_display_mode *mode)
5329{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005330 /*
5331 * FIXME: sil-sii8620 doesn't have a connector around when
5332 * we need one, so we have to be prepared for a NULL connector.
5333 */
5334 bool has_hdmi_infoframe = connector ?
5335 connector->display_info.has_hdmi_infoframe : false;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005336 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005337 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005338 u8 vic;
5339
5340 if (!frame || !mode)
5341 return -EINVAL;
5342
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005343 if (!has_hdmi_infoframe)
5344 return -EINVAL;
5345
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005346 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005347 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
5348
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005349 /*
5350 * Even if it's not absolutely necessary to send the infoframe
5351 * (ie.vic==0 and s3d_struct==0) we will still send it if we
5352 * know that the sink can handle it. This is based on a
5353 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
5354 * have trouble realizing that they shuld switch from 3D to 2D
5355 * mode if the source simply stops sending the infoframe when
5356 * it wants to switch from 3D to 2D.
5357 */
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005358
5359 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005360 return -EINVAL;
5361
5362 err = hdmi_vendor_infoframe_init(frame);
5363 if (err < 0)
5364 return err;
5365
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005366 frame->vic = vic;
5367 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005368
5369 return 0;
5370}
5371EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10005372
Dave Airlie5e546cd2016-05-03 15:31:12 +10005373static int drm_parse_tiled_block(struct drm_connector *connector,
5374 struct displayid_block *block)
5375{
5376 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
5377 u16 w, h;
5378 u8 tile_v_loc, tile_h_loc;
5379 u8 num_v_tile, num_h_tile;
5380 struct drm_tile_group *tg;
5381
5382 w = tile->tile_size[0] | tile->tile_size[1] << 8;
5383 h = tile->tile_size[2] | tile->tile_size[3] << 8;
5384
5385 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
5386 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
5387 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
5388 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
5389
5390 connector->has_tile = true;
5391 if (tile->tile_cap & 0x80)
5392 connector->tile_is_single_monitor = true;
5393
5394 connector->num_h_tile = num_h_tile + 1;
5395 connector->num_v_tile = num_v_tile + 1;
5396 connector->tile_h_loc = tile_h_loc;
5397 connector->tile_v_loc = tile_v_loc;
5398 connector->tile_h_size = w + 1;
5399 connector->tile_v_size = h + 1;
5400
5401 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
5402 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
5403 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
5404 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
5405 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
5406
5407 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
5408 if (!tg) {
5409 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
5410 }
5411 if (!tg)
5412 return -ENOMEM;
5413
5414 if (connector->tile_group != tg) {
5415 /* if we haven't got a pointer,
5416 take the reference, drop ref to old tile group */
5417 if (connector->tile_group) {
5418 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5419 }
5420 connector->tile_group = tg;
5421 } else
5422 /* if same tile group, then release the ref we just took. */
5423 drm_mode_put_tile_group(connector->dev, tg);
5424 return 0;
5425}
5426
Dave Airlie40d9b042014-10-20 16:29:33 +10005427static int drm_parse_display_id(struct drm_connector *connector,
5428 u8 *displayid, int length,
5429 bool is_edid_extension)
5430{
5431 /* if this is an EDID extension the first byte will be 0x70 */
5432 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10005433 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10005434 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005435
5436 if (is_edid_extension)
5437 idx = 1;
5438
Dave Airliec97291772016-05-03 15:38:37 +10005439 ret = validate_displayid(displayid, length, idx);
5440 if (ret)
5441 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005442
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005443 idx += sizeof(struct displayid_hdr);
Andres Rodriguez80d42db2019-06-19 14:30:33 -04005444 for_each_displayid_db(displayid, block, idx, length) {
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005445 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5446 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10005447
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005448 switch (block->tag) {
5449 case DATA_BLOCK_TILED_DISPLAY:
5450 ret = drm_parse_tiled_block(connector, block);
5451 if (ret)
5452 return ret;
5453 break;
Dave Airliea39ed682016-05-02 08:35:05 +10005454 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5455 /* handled in mode gathering code. */
5456 break;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04005457 case DATA_BLOCK_CTA:
5458 /* handled in the cea parser code. */
5459 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005460 default:
5461 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5462 break;
5463 }
Dave Airlie40d9b042014-10-20 16:29:33 +10005464 }
5465 return 0;
5466}
5467
5468static void drm_get_displayid(struct drm_connector *connector,
5469 struct edid *edid)
5470{
5471 void *displayid = NULL;
5472 int ret;
5473 connector->has_tile = false;
5474 displayid = drm_find_displayid_extension(edid);
5475 if (!displayid) {
5476 /* drop reference to any tile group we had */
5477 goto out_drop_ref;
5478 }
5479
5480 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5481 if (ret < 0)
5482 goto out_drop_ref;
5483 if (!connector->has_tile)
5484 goto out_drop_ref;
5485 return;
5486out_drop_ref:
5487 if (connector->tile_group) {
5488 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5489 connector->tile_group = NULL;
5490 }
5491 return;
5492}