blob: 1e24d5d9d659732a6f64560fdfe25f66b1d03a9f [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright (c) 2006 Luc Verhaegen (quirks list)
3 * Copyright (c) 2007-2008 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
Adam Jackson61e57a82010-03-29 21:43:18 +00005 * Copyright 2010 Red Hat, Inc.
Dave Airlief453ba02008-11-07 14:05:41 -08006 *
7 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
8 * FB layer.
9 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sub license,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the
19 * next paragraph) shall be included in all copies or substantial portions
20 * of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 */
30#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Thierry Reding10a85122012-11-21 15:31:35 +010032#include <linux/hdmi.h>
Dave Airlief453ba02008-11-07 14:05:41 -080033#include <linux/i2c.h>
Adam Jackson47819ba2012-05-30 16:42:39 -040034#include <linux/module.h>
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +010035#include <linux/vga_switcheroo.h>
David Howells760285e2012-10-02 18:01:07 +010036#include <drm/drmP.h>
37#include <drm/drm_edid.h>
Laurent Pinchart93382032016-11-28 20:51:09 +020038#include <drm/drm_encoder.h>
Dave Airlie40d9b042014-10-20 16:29:33 +100039#include <drm/drm_displayid.h>
Shashank Sharma62c58af2017-03-13 16:54:02 +053040#include <drm/drm_scdc_helper.h>
Dave Airlief453ba02008-11-07 14:05:41 -080041
Takashi Iwai969218f2017-01-17 17:43:29 +010042#include "drm_crtc_internal.h"
43
Adam Jackson13931572010-08-03 14:38:19 -040044#define version_greater(edid, maj, min) \
45 (((edid)->version > (maj)) || \
46 ((edid)->version == (maj) && (edid)->revision > (min)))
Dave Airlief453ba02008-11-07 14:05:41 -080047
Adam Jacksond1ff6402010-03-29 21:43:26 +000048#define EDID_EST_TIMINGS 16
49#define EDID_STD_TIMINGS 8
50#define EDID_DETAILED_TIMINGS 4
Dave Airlief453ba02008-11-07 14:05:41 -080051
52/*
53 * EDID blocks out in the wild have a variety of bugs, try to collect
54 * them here (note that userspace may work around broken monitors first,
55 * but fixes should make their way here so that the kernel "just works"
56 * on as many displays as possible).
57 */
58
59/* First detailed mode wrong, use largest 60Hz mode */
60#define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
61/* Reported 135MHz pixel clock is too high, needs adjustment */
62#define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
63/* Prefer the largest mode at 75 Hz */
64#define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
65/* Detail timing is in cm not mm */
66#define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
67/* Detailed timing descriptors have bogus size values, so just take the
68 * maximum size and use that.
69 */
70#define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
71/* Monitor forgot to set the first detailed is preferred bit. */
72#define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
73/* use +hsync +vsync for detailed mode */
74#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
Adam Jacksonbc42aab2012-05-23 16:26:54 -040075/* Force reduced-blanking timings for detailed modes */
76#define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
Rafał Miłecki49d45a312013-12-07 13:22:42 +010077/* Force 8bpc */
78#define EDID_QUIRK_FORCE_8BPC (1 << 8)
Mario Kleinerbc5b9642014-05-23 21:40:55 +020079/* Force 12bpc */
80#define EDID_QUIRK_FORCE_12BPC (1 << 9)
Mario Kleinere10aec62016-07-06 12:05:44 +020081/* Force 6bpc */
82#define EDID_QUIRK_FORCE_6BPC (1 << 10)
Mario Kleinere345da82017-04-21 17:05:08 +020083/* Force 10bpc */
84#define EDID_QUIRK_FORCE_10BPC (1 << 11)
Dave Airlie66660d42017-10-16 05:08:09 +010085/* Non desktop display (i.e. HMD) */
86#define EDID_QUIRK_NON_DESKTOP (1 << 12)
Alex Deucher3c537882010-02-05 04:21:19 -050087
Adam Jackson13931572010-08-03 14:38:19 -040088struct detailed_mode_closure {
89 struct drm_connector *connector;
90 struct edid *edid;
91 bool preferred;
92 u32 quirks;
93 int modes;
94};
Dave Airlief453ba02008-11-07 14:05:41 -080095
Zhao Yakui5c612592009-06-22 13:17:10 +080096#define LEVEL_DMT 0
97#define LEVEL_GTF 1
Adam Jackson7a374352010-03-29 21:43:30 +000098#define LEVEL_GTF2 2
99#define LEVEL_CVT 3
Zhao Yakui5c612592009-06-22 13:17:10 +0800100
Jani Nikula23c4cfb2016-12-28 13:06:26 +0200101static const struct edid_quirk {
Ian Pilcherc51a3fd62012-04-22 11:40:26 -0500102 char vendor[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800103 int product_id;
104 u32 quirks;
105} edid_quirk_list[] = {
106 /* Acer AL1706 */
107 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
108 /* Acer F51 */
109 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
110 /* Unknown Acer */
111 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
112
Mario Kleinere10aec62016-07-06 12:05:44 +0200113 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
114 { "AEO", 0, EDID_QUIRK_FORCE_6BPC },
115
Dave Airlief453ba02008-11-07 14:05:41 -0800116 /* Belinea 10 15 55 */
117 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
118 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
119
120 /* Envision Peripherals, Inc. EN-7100e */
121 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
Adam Jacksonba1163d2010-04-06 16:11:00 +0000122 /* Envision EN2028 */
123 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
Dave Airlief453ba02008-11-07 14:05:41 -0800124
125 /* Funai Electronics PM36B */
126 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
127 EDID_QUIRK_DETAILED_IN_CM },
128
Mario Kleinere345da82017-04-21 17:05:08 +0200129 /* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
130 { "LGD", 764, EDID_QUIRK_FORCE_10BPC },
131
Dave Airlief453ba02008-11-07 14:05:41 -0800132 /* LG Philips LCD LP154W01-A5 */
133 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
134 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
135
136 /* Philips 107p5 CRT */
137 { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
138
139 /* Proview AY765C */
140 { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
141
142 /* Samsung SyncMaster 205BW. Note: irony */
143 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
144 /* Samsung SyncMaster 22[5-6]BW */
145 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
146 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400147
Mario Kleinerbc5b9642014-05-23 21:40:55 +0200148 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
149 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
150
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400151 /* ViewSonic VA2026w */
152 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
Alex Deucher118bdbd2013-08-12 11:04:29 -0400153
154 /* Medion MD 30217 PG */
155 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100156
157 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
158 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
Tomeu Vizoso36fc5792017-02-20 16:25:45 +0100159
160 /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
161 { "ETR", 13896, EDID_QUIRK_FORCE_8BPC },
Dave Airlief453ba02008-11-07 14:05:41 -0800162};
163
Thierry Redinga6b21832012-11-23 15:01:42 +0100164/*
165 * Autogenerated from the DMT spec.
166 * This table is copied from xfree86/modes/xf86EdidModes.c.
167 */
168static const struct drm_display_mode drm_dmt_modes[] = {
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300169 /* 0x01 - 640x350@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100170 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
171 736, 832, 0, 350, 382, 385, 445, 0,
172 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300173 /* 0x02 - 640x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100174 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
175 736, 832, 0, 400, 401, 404, 445, 0,
176 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300177 /* 0x03 - 720x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100178 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
179 828, 936, 0, 400, 401, 404, 446, 0,
180 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300181 /* 0x04 - 640x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100182 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300183 752, 800, 0, 480, 490, 492, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100184 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300185 /* 0x05 - 640x480@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100186 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
187 704, 832, 0, 480, 489, 492, 520, 0,
188 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300189 /* 0x06 - 640x480@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100190 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
191 720, 840, 0, 480, 481, 484, 500, 0,
192 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300193 /* 0x07 - 640x480@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100194 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
195 752, 832, 0, 480, 481, 484, 509, 0,
196 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300197 /* 0x08 - 800x600@56Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100198 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
199 896, 1024, 0, 600, 601, 603, 625, 0,
200 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300201 /* 0x09 - 800x600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100202 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
203 968, 1056, 0, 600, 601, 605, 628, 0,
204 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300205 /* 0x0a - 800x600@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100206 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
207 976, 1040, 0, 600, 637, 643, 666, 0,
208 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300209 /* 0x0b - 800x600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100210 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
211 896, 1056, 0, 600, 601, 604, 625, 0,
212 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300213 /* 0x0c - 800x600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100214 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
215 896, 1048, 0, 600, 601, 604, 631, 0,
216 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300217 /* 0x0d - 800x600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100218 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
219 880, 960, 0, 600, 603, 607, 636, 0,
220 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300221 /* 0x0e - 848x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100222 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
223 976, 1088, 0, 480, 486, 494, 517, 0,
224 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300225 /* 0x0f - 1024x768@43Hz, interlace */
Thierry Redinga6b21832012-11-23 15:01:42 +0100226 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
Paul Parsons735b1002016-04-04 20:36:34 +0100227 1208, 1264, 0, 768, 768, 776, 817, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100228 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300229 DRM_MODE_FLAG_INTERLACE) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300230 /* 0x10 - 1024x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100231 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
232 1184, 1344, 0, 768, 771, 777, 806, 0,
233 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300234 /* 0x11 - 1024x768@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100235 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
236 1184, 1328, 0, 768, 771, 777, 806, 0,
237 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300238 /* 0x12 - 1024x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100239 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
240 1136, 1312, 0, 768, 769, 772, 800, 0,
241 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300242 /* 0x13 - 1024x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100243 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
244 1168, 1376, 0, 768, 769, 772, 808, 0,
245 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300246 /* 0x14 - 1024x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100247 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
248 1104, 1184, 0, 768, 771, 775, 813, 0,
249 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300250 /* 0x15 - 1152x864@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100251 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
252 1344, 1600, 0, 864, 865, 868, 900, 0,
253 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300254 /* 0x55 - 1280x720@60Hz */
255 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
256 1430, 1650, 0, 720, 725, 730, 750, 0,
257 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300258 /* 0x16 - 1280x768@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100259 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
260 1360, 1440, 0, 768, 771, 778, 790, 0,
261 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300262 /* 0x17 - 1280x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100263 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
264 1472, 1664, 0, 768, 771, 778, 798, 0,
265 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300266 /* 0x18 - 1280x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100267 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
268 1488, 1696, 0, 768, 771, 778, 805, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300269 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300270 /* 0x19 - 1280x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100271 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
272 1496, 1712, 0, 768, 771, 778, 809, 0,
273 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300274 /* 0x1a - 1280x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100275 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
276 1360, 1440, 0, 768, 771, 778, 813, 0,
277 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300278 /* 0x1b - 1280x800@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100279 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
280 1360, 1440, 0, 800, 803, 809, 823, 0,
281 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300282 /* 0x1c - 1280x800@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100283 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
284 1480, 1680, 0, 800, 803, 809, 831, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300285 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300286 /* 0x1d - 1280x800@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100287 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
288 1488, 1696, 0, 800, 803, 809, 838, 0,
289 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300290 /* 0x1e - 1280x800@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100291 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
292 1496, 1712, 0, 800, 803, 809, 843, 0,
293 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300294 /* 0x1f - 1280x800@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100295 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
296 1360, 1440, 0, 800, 803, 809, 847, 0,
297 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300298 /* 0x20 - 1280x960@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100299 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
300 1488, 1800, 0, 960, 961, 964, 1000, 0,
301 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300302 /* 0x21 - 1280x960@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100303 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
304 1504, 1728, 0, 960, 961, 964, 1011, 0,
305 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300306 /* 0x22 - 1280x960@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100307 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
308 1360, 1440, 0, 960, 963, 967, 1017, 0,
309 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300310 /* 0x23 - 1280x1024@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100311 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
312 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
313 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300314 /* 0x24 - 1280x1024@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100315 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
316 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
317 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300318 /* 0x25 - 1280x1024@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100319 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
320 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
321 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300322 /* 0x26 - 1280x1024@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100323 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
324 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
325 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300326 /* 0x27 - 1360x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100327 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
328 1536, 1792, 0, 768, 771, 777, 795, 0,
329 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300330 /* 0x28 - 1360x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100331 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
332 1440, 1520, 0, 768, 771, 776, 813, 0,
333 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300334 /* 0x51 - 1366x768@60Hz */
335 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
336 1579, 1792, 0, 768, 771, 774, 798, 0,
337 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
338 /* 0x56 - 1366x768@60Hz */
339 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
340 1436, 1500, 0, 768, 769, 772, 800, 0,
341 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300342 /* 0x29 - 1400x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100343 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
344 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
345 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300346 /* 0x2a - 1400x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100347 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
348 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
349 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300350 /* 0x2b - 1400x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100351 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
352 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
353 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300354 /* 0x2c - 1400x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100355 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
356 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
357 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300358 /* 0x2d - 1400x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100359 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
360 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
361 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300362 /* 0x2e - 1440x900@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100363 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
364 1520, 1600, 0, 900, 903, 909, 926, 0,
365 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300366 /* 0x2f - 1440x900@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100367 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
368 1672, 1904, 0, 900, 903, 909, 934, 0,
369 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300370 /* 0x30 - 1440x900@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100371 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
372 1688, 1936, 0, 900, 903, 909, 942, 0,
373 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300374 /* 0x31 - 1440x900@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100375 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
376 1696, 1952, 0, 900, 903, 909, 948, 0,
377 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300378 /* 0x32 - 1440x900@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100379 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
380 1520, 1600, 0, 900, 903, 909, 953, 0,
381 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300382 /* 0x53 - 1600x900@60Hz */
383 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
384 1704, 1800, 0, 900, 901, 904, 1000, 0,
385 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300386 /* 0x33 - 1600x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100387 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
388 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
389 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300390 /* 0x34 - 1600x1200@65Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100391 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
392 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
393 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300394 /* 0x35 - 1600x1200@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100395 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
396 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
397 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300398 /* 0x36 - 1600x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100399 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
400 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
401 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300402 /* 0x37 - 1600x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100403 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
404 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
405 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300406 /* 0x38 - 1600x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100407 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
408 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
409 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300410 /* 0x39 - 1680x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100411 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
412 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
413 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300414 /* 0x3a - 1680x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100415 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
416 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
417 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300418 /* 0x3b - 1680x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100419 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
420 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
421 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300422 /* 0x3c - 1680x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100423 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
424 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
425 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300426 /* 0x3d - 1680x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100427 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
428 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
429 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300430 /* 0x3e - 1792x1344@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100431 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
432 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
433 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300434 /* 0x3f - 1792x1344@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100435 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
436 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
437 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300438 /* 0x40 - 1792x1344@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100439 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
440 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
441 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300442 /* 0x41 - 1856x1392@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100443 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
444 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
445 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300446 /* 0x42 - 1856x1392@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100447 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300448 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100449 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300450 /* 0x43 - 1856x1392@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100451 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
452 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
453 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300454 /* 0x52 - 1920x1080@60Hz */
455 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
456 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
457 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300458 /* 0x44 - 1920x1200@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100459 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
460 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
461 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300462 /* 0x45 - 1920x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100463 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
464 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
465 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300466 /* 0x46 - 1920x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100467 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
468 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
469 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300470 /* 0x47 - 1920x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100471 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
472 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
473 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300474 /* 0x48 - 1920x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100475 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
476 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
477 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300478 /* 0x49 - 1920x1440@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100479 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
480 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
481 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300482 /* 0x4a - 1920x1440@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100483 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
484 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
485 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300486 /* 0x4b - 1920x1440@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100487 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
488 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
489 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300490 /* 0x54 - 2048x1152@60Hz */
491 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
492 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
493 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300494 /* 0x4c - 2560x1600@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100495 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
496 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
497 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300498 /* 0x4d - 2560x1600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100499 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
500 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
501 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300502 /* 0x4e - 2560x1600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100503 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
504 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
505 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300506 /* 0x4f - 2560x1600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100507 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
508 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
509 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300510 /* 0x50 - 2560x1600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100511 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
512 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
513 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300514 /* 0x57 - 4096x2160@60Hz RB */
515 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
516 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
517 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
518 /* 0x58 - 4096x2160@59.94Hz RB */
519 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
520 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
521 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Thierry Redinga6b21832012-11-23 15:01:42 +0100522};
523
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300524/*
525 * These more or less come from the DMT spec. The 720x400 modes are
526 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
527 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
528 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
529 * mode.
530 *
531 * The DMT modes have been fact-checked; the rest are mild guesses.
532 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100533static const struct drm_display_mode edid_est_modes[] = {
534 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
535 968, 1056, 0, 600, 601, 605, 628, 0,
536 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
537 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
538 896, 1024, 0, 600, 601, 603, 625, 0,
539 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
540 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
541 720, 840, 0, 480, 481, 484, 500, 0,
542 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
543 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
Paul Parsons87707cf2016-04-02 11:08:06 +0100544 704, 832, 0, 480, 489, 492, 520, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100545 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
546 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
547 768, 864, 0, 480, 483, 486, 525, 0,
548 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100549 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Thierry Redinga6b21832012-11-23 15:01:42 +0100550 752, 800, 0, 480, 490, 492, 525, 0,
551 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
552 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
553 846, 900, 0, 400, 421, 423, 449, 0,
554 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
555 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
556 846, 900, 0, 400, 412, 414, 449, 0,
557 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
558 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
559 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
560 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100561 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
Thierry Redinga6b21832012-11-23 15:01:42 +0100562 1136, 1312, 0, 768, 769, 772, 800, 0,
563 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
564 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
565 1184, 1328, 0, 768, 771, 777, 806, 0,
566 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
567 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
568 1184, 1344, 0, 768, 771, 777, 806, 0,
569 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
570 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
571 1208, 1264, 0, 768, 768, 776, 817, 0,
572 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
573 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
574 928, 1152, 0, 624, 625, 628, 667, 0,
575 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
576 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
577 896, 1056, 0, 600, 601, 604, 625, 0,
578 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
579 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
580 976, 1040, 0, 600, 637, 643, 666, 0,
581 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
582 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
583 1344, 1600, 0, 864, 865, 868, 900, 0,
584 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
585};
586
587struct minimode {
588 short w;
589 short h;
590 short r;
591 short rb;
592};
593
594static const struct minimode est3_modes[] = {
595 /* byte 6 */
596 { 640, 350, 85, 0 },
597 { 640, 400, 85, 0 },
598 { 720, 400, 85, 0 },
599 { 640, 480, 85, 0 },
600 { 848, 480, 60, 0 },
601 { 800, 600, 85, 0 },
602 { 1024, 768, 85, 0 },
603 { 1152, 864, 75, 0 },
604 /* byte 7 */
605 { 1280, 768, 60, 1 },
606 { 1280, 768, 60, 0 },
607 { 1280, 768, 75, 0 },
608 { 1280, 768, 85, 0 },
609 { 1280, 960, 60, 0 },
610 { 1280, 960, 85, 0 },
611 { 1280, 1024, 60, 0 },
612 { 1280, 1024, 85, 0 },
613 /* byte 8 */
614 { 1360, 768, 60, 0 },
615 { 1440, 900, 60, 1 },
616 { 1440, 900, 60, 0 },
617 { 1440, 900, 75, 0 },
618 { 1440, 900, 85, 0 },
619 { 1400, 1050, 60, 1 },
620 { 1400, 1050, 60, 0 },
621 { 1400, 1050, 75, 0 },
622 /* byte 9 */
623 { 1400, 1050, 85, 0 },
624 { 1680, 1050, 60, 1 },
625 { 1680, 1050, 60, 0 },
626 { 1680, 1050, 75, 0 },
627 { 1680, 1050, 85, 0 },
628 { 1600, 1200, 60, 0 },
629 { 1600, 1200, 65, 0 },
630 { 1600, 1200, 70, 0 },
631 /* byte 10 */
632 { 1600, 1200, 75, 0 },
633 { 1600, 1200, 85, 0 },
634 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300635 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100636 { 1856, 1392, 60, 0 },
637 { 1856, 1392, 75, 0 },
638 { 1920, 1200, 60, 1 },
639 { 1920, 1200, 60, 0 },
640 /* byte 11 */
641 { 1920, 1200, 75, 0 },
642 { 1920, 1200, 85, 0 },
643 { 1920, 1440, 60, 0 },
644 { 1920, 1440, 75, 0 },
645};
646
647static const struct minimode extra_modes[] = {
648 { 1024, 576, 60, 0 },
649 { 1366, 768, 60, 0 },
650 { 1600, 900, 60, 0 },
651 { 1680, 945, 60, 0 },
652 { 1920, 1080, 60, 0 },
653 { 2048, 1152, 60, 0 },
654 { 2048, 1536, 60, 0 },
655};
656
657/*
658 * Probably taken from CEA-861 spec.
659 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
Jani Nikulad9278b42016-01-08 13:21:51 +0200660 *
661 * Index using the VIC.
Thierry Redinga6b21832012-11-23 15:01:42 +0100662 */
663static const struct drm_display_mode edid_cea_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +0200664 /* 0 - dummy, VICs start at 1 */
665 { },
Thierry Redinga6b21832012-11-23 15:01:42 +0100666 /* 1 - 640x480@60Hz */
667 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
668 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300669 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530670 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100671 /* 2 - 720x480@60Hz */
672 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
673 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300674 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530675 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100676 /* 3 - 720x480@60Hz */
677 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
678 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300679 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530680 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100681 /* 4 - 1280x720@60Hz */
682 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
683 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300684 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530685 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100686 /* 5 - 1920x1080i@60Hz */
687 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
688 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
689 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300690 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530691 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700692 /* 6 - 720(1440)x480i@60Hz */
693 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
694 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100695 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300696 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530697 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700698 /* 7 - 720(1440)x480i@60Hz */
699 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
700 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100701 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300702 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530703 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700704 /* 8 - 720(1440)x240@60Hz */
705 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
706 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100707 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300708 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530709 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700710 /* 9 - 720(1440)x240@60Hz */
711 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
712 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100713 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300714 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530715 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100716 /* 10 - 2880x480i@60Hz */
717 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
718 3204, 3432, 0, 480, 488, 494, 525, 0,
719 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300720 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530721 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100722 /* 11 - 2880x480i@60Hz */
723 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
724 3204, 3432, 0, 480, 488, 494, 525, 0,
725 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300726 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530727 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100728 /* 12 - 2880x240@60Hz */
729 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
730 3204, 3432, 0, 240, 244, 247, 262, 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100733 /* 13 - 2880x240@60Hz */
734 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
735 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300736 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530737 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100738 /* 14 - 1440x480@60Hz */
739 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
740 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300741 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530742 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100743 /* 15 - 1440x480@60Hz */
744 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
745 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300746 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530747 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100748 /* 16 - 1920x1080@60Hz */
749 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
750 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300751 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530752 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100753 /* 17 - 720x576@50Hz */
754 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
755 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300756 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530757 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100758 /* 18 - 720x576@50Hz */
759 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
760 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300761 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530762 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100763 /* 19 - 1280x720@50Hz */
764 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
765 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300766 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530767 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100768 /* 20 - 1920x1080i@50Hz */
769 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
770 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
771 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300772 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530773 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700774 /* 21 - 720(1440)x576i@50Hz */
775 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
776 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100777 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300778 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530779 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700780 /* 22 - 720(1440)x576i@50Hz */
781 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
782 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100783 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300784 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530785 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700786 /* 23 - 720(1440)x288@50Hz */
787 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
788 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100789 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300790 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530791 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700792 /* 24 - 720(1440)x288@50Hz */
793 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
794 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100795 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300796 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530797 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100798 /* 25 - 2880x576i@50Hz */
799 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
800 3180, 3456, 0, 576, 580, 586, 625, 0,
801 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300802 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530803 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100804 /* 26 - 2880x576i@50Hz */
805 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
806 3180, 3456, 0, 576, 580, 586, 625, 0,
807 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300808 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530809 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100810 /* 27 - 2880x288@50Hz */
811 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
812 3180, 3456, 0, 288, 290, 293, 312, 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100815 /* 28 - 2880x288@50Hz */
816 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
817 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300818 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530819 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100820 /* 29 - 1440x576@50Hz */
821 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
822 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300823 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530824 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100825 /* 30 - 1440x576@50Hz */
826 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
827 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300828 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530829 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100830 /* 31 - 1920x1080@50Hz */
831 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
832 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300833 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530834 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100835 /* 32 - 1920x1080@24Hz */
836 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
837 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300838 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530839 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100840 /* 33 - 1920x1080@25Hz */
841 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
842 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300843 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530844 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100845 /* 34 - 1920x1080@30Hz */
846 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
847 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300848 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530849 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100850 /* 35 - 2880x480@60Hz */
851 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
852 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300853 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530854 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100855 /* 36 - 2880x480@60Hz */
856 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
857 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300858 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530859 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100860 /* 37 - 2880x576@50Hz */
861 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
862 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300863 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530864 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100865 /* 38 - 2880x576@50Hz */
866 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
867 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300868 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530869 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100870 /* 39 - 1920x1080i@50Hz */
871 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
872 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
873 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300874 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530875 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100876 /* 40 - 1920x1080i@100Hz */
877 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
878 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
879 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300880 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530881 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100882 /* 41 - 1280x720@100Hz */
883 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
884 1760, 1980, 0, 720, 725, 730, 750, 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 = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100887 /* 42 - 720x576@100Hz */
888 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
889 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300890 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530891 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100892 /* 43 - 720x576@100Hz */
893 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
894 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300895 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530896 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700897 /* 44 - 720(1440)x576i@100Hz */
898 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
899 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100900 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700901 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530902 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700903 /* 45 - 720(1440)x576i@100Hz */
904 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
905 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100906 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700907 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530908 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100909 /* 46 - 1920x1080i@120Hz */
910 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
911 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
912 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300913 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530914 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100915 /* 47 - 1280x720@120Hz */
916 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
917 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300918 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530919 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100920 /* 48 - 720x480@120Hz */
921 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
922 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300923 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530924 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100925 /* 49 - 720x480@120Hz */
926 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
927 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300928 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530929 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700930 /* 50 - 720(1440)x480i@120Hz */
931 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
932 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100933 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300934 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530935 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700936 /* 51 - 720(1440)x480i@120Hz */
937 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
938 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100939 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300940 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530941 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100942 /* 52 - 720x576@200Hz */
943 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
944 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300945 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530946 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100947 /* 53 - 720x576@200Hz */
948 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
949 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300950 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530951 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700952 /* 54 - 720(1440)x576i@200Hz */
953 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
954 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100955 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300956 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530957 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700958 /* 55 - 720(1440)x576i@200Hz */
959 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
960 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100961 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300962 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530963 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100964 /* 56 - 720x480@240Hz */
965 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
966 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300967 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530968 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100969 /* 57 - 720x480@240Hz */
970 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
971 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300972 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530973 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200974 /* 58 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700975 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
976 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100977 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300978 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530979 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200980 /* 59 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700981 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
982 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100983 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300984 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530985 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100986 /* 60 - 1280x720@24Hz */
987 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
988 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300989 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530990 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100991 /* 61 - 1280x720@25Hz */
992 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
993 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300994 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530995 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100996 /* 62 - 1280x720@30Hz */
997 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
998 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300999 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301000 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001001 /* 63 - 1920x1080@120Hz */
1002 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1003 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001004 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301005 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001006 /* 64 - 1920x1080@100Hz */
1007 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -07001008 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001009 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +05301010 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301011 /* 65 - 1280x720@24Hz */
1012 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1013 3080, 3300, 0, 720, 725, 730, 750, 0,
1014 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1015 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1016 /* 66 - 1280x720@25Hz */
1017 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1018 3740, 3960, 0, 720, 725, 730, 750, 0,
1019 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1020 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1021 /* 67 - 1280x720@30Hz */
1022 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1023 3080, 3300, 0, 720, 725, 730, 750, 0,
1024 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1025 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1026 /* 68 - 1280x720@50Hz */
1027 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1028 1760, 1980, 0, 720, 725, 730, 750, 0,
1029 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1030 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1031 /* 69 - 1280x720@60Hz */
1032 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1033 1430, 1650, 0, 720, 725, 730, 750, 0,
1034 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1035 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1036 /* 70 - 1280x720@100Hz */
1037 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1038 1760, 1980, 0, 720, 725, 730, 750, 0,
1039 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1040 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1041 /* 71 - 1280x720@120Hz */
1042 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1043 1430, 1650, 0, 720, 725, 730, 750, 0,
1044 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1045 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1046 /* 72 - 1920x1080@24Hz */
1047 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1048 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1049 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1050 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1051 /* 73 - 1920x1080@25Hz */
1052 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1053 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1054 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1055 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1056 /* 74 - 1920x1080@30Hz */
1057 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1058 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1059 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1060 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1061 /* 75 - 1920x1080@50Hz */
1062 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1063 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1064 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1065 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1066 /* 76 - 1920x1080@60Hz */
1067 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1068 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1069 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1070 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1071 /* 77 - 1920x1080@100Hz */
1072 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1073 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1074 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1075 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1076 /* 78 - 1920x1080@120Hz */
1077 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1078 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1079 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1080 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1081 /* 79 - 1680x720@24Hz */
1082 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1083 3080, 3300, 0, 720, 725, 730, 750, 0,
1084 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1085 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1086 /* 80 - 1680x720@25Hz */
1087 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1088 2948, 3168, 0, 720, 725, 730, 750, 0,
1089 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1090 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1091 /* 81 - 1680x720@30Hz */
1092 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1093 2420, 2640, 0, 720, 725, 730, 750, 0,
1094 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1095 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1096 /* 82 - 1680x720@50Hz */
1097 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1098 1980, 2200, 0, 720, 725, 730, 750, 0,
1099 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1100 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1101 /* 83 - 1680x720@60Hz */
1102 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1103 1980, 2200, 0, 720, 725, 730, 750, 0,
1104 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1105 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1106 /* 84 - 1680x720@100Hz */
1107 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1108 1780, 2000, 0, 720, 725, 730, 825, 0,
1109 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1110 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1111 /* 85 - 1680x720@120Hz */
1112 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1113 1780, 2000, 0, 720, 725, 730, 825, 0,
1114 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1115 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1116 /* 86 - 2560x1080@24Hz */
1117 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1118 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1119 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1120 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1121 /* 87 - 2560x1080@25Hz */
1122 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1123 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1124 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1125 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1126 /* 88 - 2560x1080@30Hz */
1127 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1128 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1129 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1130 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1131 /* 89 - 2560x1080@50Hz */
1132 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1133 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1134 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1135 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1136 /* 90 - 2560x1080@60Hz */
1137 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1138 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1139 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1140 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1141 /* 91 - 2560x1080@100Hz */
1142 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1143 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1144 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1145 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1146 /* 92 - 2560x1080@120Hz */
1147 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1148 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1149 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1150 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1151 /* 93 - 3840x2160p@24Hz 16:9 */
1152 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1153 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1154 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1155 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1156 /* 94 - 3840x2160p@25Hz 16:9 */
1157 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1158 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1159 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1160 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1161 /* 95 - 3840x2160p@30Hz 16:9 */
1162 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1163 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1164 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1165 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1166 /* 96 - 3840x2160p@50Hz 16:9 */
1167 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1168 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1169 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1170 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1171 /* 97 - 3840x2160p@60Hz 16:9 */
1172 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1173 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1174 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1175 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1176 /* 98 - 4096x2160p@24Hz 256:135 */
1177 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1178 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1179 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1180 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1181 /* 99 - 4096x2160p@25Hz 256:135 */
1182 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1183 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1184 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1185 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1186 /* 100 - 4096x2160p@30Hz 256:135 */
1187 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1188 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1189 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1190 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1191 /* 101 - 4096x2160p@50Hz 256:135 */
1192 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1193 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1194 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1195 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1196 /* 102 - 4096x2160p@60Hz 256:135 */
1197 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1198 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1199 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1200 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1201 /* 103 - 3840x2160p@24Hz 64:27 */
1202 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1203 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1204 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1205 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1206 /* 104 - 3840x2160p@25Hz 64:27 */
1207 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1208 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1209 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1210 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1211 /* 105 - 3840x2160p@30Hz 64:27 */
1212 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1213 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1214 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1215 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1216 /* 106 - 3840x2160p@50Hz 64:27 */
1217 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1218 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1219 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1220 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1221 /* 107 - 3840x2160p@60Hz 64:27 */
1222 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1223 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1224 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1225 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001226};
1227
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001228/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001229 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001230 */
1231static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001232 /* 0 - dummy, VICs start at 1 */
1233 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001234 /* 1 - 3840x2160@30Hz */
1235 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1236 3840, 4016, 4104, 4400, 0,
1237 2160, 2168, 2178, 2250, 0,
1238 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1239 .vrefresh = 30, },
1240 /* 2 - 3840x2160@25Hz */
1241 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1242 3840, 4896, 4984, 5280, 0,
1243 2160, 2168, 2178, 2250, 0,
1244 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1245 .vrefresh = 25, },
1246 /* 3 - 3840x2160@24Hz */
1247 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1248 3840, 5116, 5204, 5500, 0,
1249 2160, 2168, 2178, 2250, 0,
1250 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1251 .vrefresh = 24, },
1252 /* 4 - 4096x2160@24Hz (SMPTE) */
1253 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1254 4096, 5116, 5204, 5500, 0,
1255 2160, 2168, 2178, 2250, 0,
1256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1257 .vrefresh = 24, },
1258};
1259
Adam Jackson61e57a82010-03-29 21:43:18 +00001260/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001261
Adam Jackson083ae052009-09-23 17:30:45 -04001262static const u8 edid_header[] = {
1263 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1264};
Dave Airlief453ba02008-11-07 14:05:41 -08001265
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001266/**
1267 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1268 * @raw_edid: pointer to raw base EDID block
1269 *
1270 * Sanity check the header of the base EDID block.
1271 *
1272 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001273 */
1274int drm_edid_header_is_valid(const u8 *raw_edid)
1275{
1276 int i, score = 0;
1277
1278 for (i = 0; i < sizeof(edid_header); i++)
1279 if (raw_edid[i] == edid_header[i])
1280 score++;
1281
1282 return score;
1283}
1284EXPORT_SYMBOL(drm_edid_header_is_valid);
1285
Adam Jackson47819ba2012-05-30 16:42:39 -04001286static int edid_fixup __read_mostly = 6;
1287module_param_named(edid_fixup, edid_fixup, int, 0400);
1288MODULE_PARM_DESC(edid_fixup,
1289 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001290
Dave Airlie40d9b042014-10-20 16:29:33 +10001291static void drm_get_displayid(struct drm_connector *connector,
1292 struct edid *edid);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001293
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001294static int drm_edid_block_checksum(const u8 *raw_edid)
1295{
1296 int i;
1297 u8 csum = 0;
1298 for (i = 0; i < EDID_LENGTH; i++)
1299 csum += raw_edid[i];
1300
1301 return csum;
1302}
1303
Stefan Brünsd6885d62014-11-30 19:57:41 +01001304static bool drm_edid_is_zero(const u8 *in_edid, int length)
1305{
1306 if (memchr_inv(in_edid, 0, length))
1307 return false;
1308
1309 return true;
1310}
1311
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001312/**
1313 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1314 * @raw_edid: pointer to raw EDID block
1315 * @block: type of block to validate (0 for base, extension otherwise)
1316 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001317 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001318 *
1319 * Validate a base or extension EDID block and optionally dump bad blocks to
1320 * the console.
1321 *
1322 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001323 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001324bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1325 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001326{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001327 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001328 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001329
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001330 if (WARN_ON(!raw_edid))
1331 return false;
1332
Adam Jackson47819ba2012-05-30 16:42:39 -04001333 if (edid_fixup > 8 || edid_fixup < 0)
1334 edid_fixup = 6;
1335
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001336 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001337 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001338 if (score == 8) {
1339 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001340 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001341 } else if (score >= edid_fixup) {
1342 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1343 * The corrupt flag needs to be set here otherwise, the
1344 * fix-up code here will correct the problem, the
1345 * checksum is correct and the test fails
1346 */
1347 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001348 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001349 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1350 memcpy(raw_edid, edid_header, sizeof(edid_header));
1351 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001352 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001353 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001354 goto bad;
1355 }
1356 }
Dave Airlief453ba02008-11-07 14:05:41 -08001357
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001358 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001359 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001360 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001361 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001362
Adam Jackson4a638b42010-05-25 16:33:09 -04001363 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001364 if (raw_edid[0] == CEA_EXT) {
1365 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1366 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1367 } else {
1368 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001369 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001370
Adam Jackson4a638b42010-05-25 16:33:09 -04001371 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001372 }
Dave Airlief453ba02008-11-07 14:05:41 -08001373 }
1374
Adam Jackson61e57a82010-03-29 21:43:18 +00001375 /* per-block-type checks */
1376 switch (raw_edid[0]) {
1377 case 0: /* base */
1378 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001379 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001380 goto bad;
1381 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001382
Adam Jackson61e57a82010-03-29 21:43:18 +00001383 if (edid->revision > 4)
1384 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1385 break;
1386
1387 default:
1388 break;
1389 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001390
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001391 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001392
1393bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001394 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001395 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001396 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001397 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001398 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001399 print_hex_dump(KERN_NOTICE,
1400 " \t", DUMP_PREFIX_NONE, 16, 1,
1401 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001402 }
Dave Airlief453ba02008-11-07 14:05:41 -08001403 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001404 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001405}
Carsten Emdeda0df922012-03-18 22:37:33 +01001406EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001407
1408/**
1409 * drm_edid_is_valid - sanity check EDID data
1410 * @edid: EDID data
1411 *
1412 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001413 *
1414 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001415 */
1416bool drm_edid_is_valid(struct edid *edid)
1417{
1418 int i;
1419 u8 *raw = (u8 *)edid;
1420
1421 if (!edid)
1422 return false;
1423
1424 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001425 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001426 return false;
1427
1428 return true;
1429}
Alex Deucher3c537882010-02-05 04:21:19 -05001430EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001431
Adam Jackson61e57a82010-03-29 21:43:18 +00001432#define DDC_SEGMENT_ADDR 0x30
1433/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001434 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001435 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001436 * @buf: EDID data buffer to be filled
1437 * @block: 128 byte EDID block to start fetching from
1438 * @len: EDID data buffer length to fetch
1439 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001440 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001441 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001442 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001443 */
1444static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001445drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001446{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001447 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001448 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001449 unsigned char segment = block >> 1;
1450 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001451 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001452
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001453 /*
1454 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001455 * adapter reports EAGAIN. However, we find that bit-banging transfers
1456 * are susceptible to errors under a heavily loaded machine and
1457 * generate spurious NAKs and timeouts. Retrying the transfer
1458 * of the individual block a few times seems to overcome this.
1459 */
1460 do {
1461 struct i2c_msg msgs[] = {
1462 {
Shirish Scd004b32012-08-30 07:04:06 +00001463 .addr = DDC_SEGMENT_ADDR,
1464 .flags = 0,
1465 .len = 1,
1466 .buf = &segment,
1467 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001468 .addr = DDC_ADDR,
1469 .flags = 0,
1470 .len = 1,
1471 .buf = &start,
1472 }, {
1473 .addr = DDC_ADDR,
1474 .flags = I2C_M_RD,
1475 .len = len,
1476 .buf = buf,
1477 }
1478 };
Shirish Scd004b32012-08-30 07:04:06 +00001479
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001480 /*
1481 * Avoid sending the segment addr to not upset non-compliant
1482 * DDC monitors.
1483 */
Shirish Scd004b32012-08-30 07:04:06 +00001484 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1485
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001486 if (ret == -ENXIO) {
1487 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1488 adapter->name);
1489 break;
1490 }
Shirish Scd004b32012-08-30 07:04:06 +00001491 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001492
Shirish Scd004b32012-08-30 07:04:06 +00001493 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001494}
1495
Chris Wilson14544d02016-10-24 12:38:21 +01001496static void connector_bad_edid(struct drm_connector *connector,
1497 u8 *edid, int num_blocks)
1498{
1499 int i;
1500
1501 if (connector->bad_edid_counter++ && !(drm_debug & DRM_UT_KMS))
1502 return;
1503
1504 dev_warn(connector->dev->dev,
1505 "%s: EDID is invalid:\n",
1506 connector->name);
1507 for (i = 0; i < num_blocks; i++) {
1508 u8 *block = edid + i * EDID_LENGTH;
1509 char prefix[20];
1510
1511 if (drm_edid_is_zero(block, EDID_LENGTH))
1512 sprintf(prefix, "\t[%02x] ZERO ", i);
1513 else if (!drm_edid_block_valid(block, i, false, NULL))
1514 sprintf(prefix, "\t[%02x] BAD ", i);
1515 else
1516 sprintf(prefix, "\t[%02x] GOOD ", i);
1517
1518 print_hex_dump(KERN_WARNING,
1519 prefix, DUMP_PREFIX_NONE, 16, 1,
1520 block, EDID_LENGTH, false);
1521 }
1522}
1523
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001524/**
1525 * drm_do_get_edid - get EDID data using a custom EDID block read function
1526 * @connector: connector we're probing
1527 * @get_edid_block: EDID block read function
1528 * @data: private data passed to the block read function
1529 *
1530 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1531 * exposes a different interface to read EDID blocks this function can be used
1532 * to get EDID data using a custom block read function.
1533 *
1534 * As in the general case the DDC bus is accessible by the kernel at the I2C
1535 * level, drivers must make all reasonable efforts to expose it as an I2C
1536 * adapter and use drm_get_edid() instead of abusing this function.
1537 *
Jani Nikula53fd40a2017-09-12 11:19:26 +03001538 * The EDID may be overridden using debugfs override_edid or firmare EDID
1539 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1540 * order. Having either of them bypasses actual EDID reads.
1541 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001542 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1543 */
1544struct edid *drm_do_get_edid(struct drm_connector *connector,
1545 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1546 size_t len),
1547 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001548{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001549 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001550 u8 *edid, *new;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001551 struct edid *override = NULL;
1552
1553 if (connector->override_edid)
1554 override = drm_edid_duplicate((const struct edid *)
1555 connector->edid_blob_ptr->data);
1556
1557 if (!override)
1558 override = drm_load_edid_firmware(connector);
1559
1560 if (!IS_ERR_OR_NULL(override))
1561 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001562
Chris Wilsonf14f3682016-10-17 09:35:12 +01001563 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001564 return NULL;
1565
1566 /* base block fetch */
1567 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001568 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001569 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001570 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001571 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001572 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001573 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001574 connector->null_edid_counter++;
1575 goto carp;
1576 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001577 }
1578 if (i == 4)
1579 goto carp;
1580
1581 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001582 valid_extensions = edid[0x7e];
1583 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001584 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001585
Chris Wilson14544d02016-10-24 12:38:21 +01001586 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001587 if (!new)
1588 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001589 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001590
Chris Wilsonf14f3682016-10-17 09:35:12 +01001591 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001592 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001593
Adam Jackson61e57a82010-03-29 21:43:18 +00001594 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001595 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001596 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001597 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001598 break;
1599 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001600
Chris Wilson14544d02016-10-24 12:38:21 +01001601 if (i == 4)
1602 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001603 }
1604
Chris Wilsonf14f3682016-10-17 09:35:12 +01001605 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001606 u8 *base;
1607
1608 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1609
Chris Wilsonf14f3682016-10-17 09:35:12 +01001610 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1611 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001612
1613 new = kmalloc((valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001614 if (!new)
1615 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001616
1617 base = new;
1618 for (i = 0; i <= edid[0x7e]; i++) {
1619 u8 *block = edid + i * EDID_LENGTH;
1620
1621 if (!drm_edid_block_valid(block, i, false, NULL))
1622 continue;
1623
1624 memcpy(base, block, EDID_LENGTH);
1625 base += EDID_LENGTH;
1626 }
1627
1628 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001629 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001630 }
1631
Chris Wilsonf14f3682016-10-17 09:35:12 +01001632 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001633
1634carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001635 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001636out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001637 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001638 return NULL;
1639}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001640EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001641
1642/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001643 * drm_probe_ddc() - probe DDC presence
1644 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001645 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001646 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001647 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001648bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001649drm_probe_ddc(struct i2c_adapter *adapter)
1650{
1651 unsigned char out;
1652
1653 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1654}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001655EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001656
1657/**
1658 * drm_get_edid - get EDID data, if available
1659 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001660 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001661 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001662 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001663 * attach it to the connector.
1664 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001665 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001666 */
1667struct edid *drm_get_edid(struct drm_connector *connector,
1668 struct i2c_adapter *adapter)
1669{
Dave Airlie40d9b042014-10-20 16:29:33 +10001670 struct edid *edid;
1671
Jani Nikula15f080f2017-02-17 17:20:53 +02001672 if (connector->force == DRM_FORCE_OFF)
1673 return NULL;
1674
1675 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001676 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001677
Dave Airlie40d9b042014-10-20 16:29:33 +10001678 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1679 if (edid)
1680 drm_get_displayid(connector, edid);
1681 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001682}
1683EXPORT_SYMBOL(drm_get_edid);
1684
Jani Nikula51f8da52013-09-27 15:08:27 +03001685/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001686 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1687 * @connector: connector we're probing
1688 * @adapter: I2C adapter to use for DDC
1689 *
1690 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1691 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1692 * switch DDC to the GPU which is retrieving EDID.
1693 *
1694 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1695 */
1696struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1697 struct i2c_adapter *adapter)
1698{
1699 struct pci_dev *pdev = connector->dev->pdev;
1700 struct edid *edid;
1701
1702 vga_switcheroo_lock_ddc(pdev);
1703 edid = drm_get_edid(connector, adapter);
1704 vga_switcheroo_unlock_ddc(pdev);
1705
1706 return edid;
1707}
1708EXPORT_SYMBOL(drm_get_edid_switcheroo);
1709
1710/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001711 * drm_edid_duplicate - duplicate an EDID and the extensions
1712 * @edid: EDID to duplicate
1713 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001714 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001715 */
1716struct edid *drm_edid_duplicate(const struct edid *edid)
1717{
1718 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1719}
1720EXPORT_SYMBOL(drm_edid_duplicate);
1721
Adam Jackson61e57a82010-03-29 21:43:18 +00001722/*** EDID parsing ***/
1723
Dave Airlief453ba02008-11-07 14:05:41 -08001724/**
1725 * edid_vendor - match a string against EDID's obfuscated vendor field
1726 * @edid: EDID to match
1727 * @vendor: vendor string
1728 *
1729 * Returns true if @vendor is in @edid, false otherwise
1730 */
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001731static bool edid_vendor(struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001732{
1733 char edid_vendor[3];
1734
1735 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1736 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1737 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001738 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001739
1740 return !strncmp(edid_vendor, vendor, 3);
1741}
1742
1743/**
1744 * edid_get_quirks - return quirk flags for a given EDID
1745 * @edid: EDID to process
1746 *
1747 * This tells subsequent routines what fixes they need to apply.
1748 */
1749static u32 edid_get_quirks(struct edid *edid)
1750{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001751 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001752 int i;
1753
1754 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1755 quirk = &edid_quirk_list[i];
1756
1757 if (edid_vendor(edid, quirk->vendor) &&
1758 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1759 return quirk->quirks;
1760 }
1761
1762 return 0;
1763}
1764
1765#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001766#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001767
Dave Airlief453ba02008-11-07 14:05:41 -08001768/**
1769 * edid_fixup_preferred - set preferred modes based on quirk list
1770 * @connector: has mode list to fix up
1771 * @quirks: quirks list
1772 *
1773 * Walk the mode list for @connector, clearing the preferred status
1774 * on existing modes and setting it anew for the right mode ala @quirks.
1775 */
1776static void edid_fixup_preferred(struct drm_connector *connector,
1777 u32 quirks)
1778{
1779 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001780 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001781 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001782
1783 if (list_empty(&connector->probed_modes))
1784 return;
1785
1786 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1787 target_refresh = 60;
1788 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1789 target_refresh = 75;
1790
1791 preferred_mode = list_first_entry(&connector->probed_modes,
1792 struct drm_display_mode, head);
1793
1794 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1795 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1796
1797 if (cur_mode == preferred_mode)
1798 continue;
1799
1800 /* Largest mode is preferred */
1801 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1802 preferred_mode = cur_mode;
1803
Alex Deucher339d2022013-08-15 11:42:14 -04001804 cur_vrefresh = cur_mode->vrefresh ?
1805 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1806 preferred_vrefresh = preferred_mode->vrefresh ?
1807 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08001808 /* At a given size, try to get closest to target refresh */
1809 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04001810 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1811 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08001812 preferred_mode = cur_mode;
1813 }
1814 }
1815
1816 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1817}
1818
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001819static bool
1820mode_is_rb(const struct drm_display_mode *mode)
1821{
1822 return (mode->htotal - mode->hdisplay == 160) &&
1823 (mode->hsync_end - mode->hdisplay == 80) &&
1824 (mode->hsync_end - mode->hsync_start == 32) &&
1825 (mode->vsync_start - mode->vdisplay == 3);
1826}
1827
Adam Jackson33c75312012-04-13 16:33:29 -04001828/*
1829 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1830 * @dev: Device to duplicate against
1831 * @hsize: Mode width
1832 * @vsize: Mode height
1833 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001834 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04001835 *
1836 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001837 *
1838 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04001839 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001840struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001841 int hsize, int vsize, int fresh,
1842 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08001843{
Adam Jackson07a5e632009-12-03 17:44:38 -05001844 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08001845
Thierry Redinga6b21832012-11-23 15:01:42 +01001846 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001847 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001848 if (hsize != ptr->hdisplay)
1849 continue;
1850 if (vsize != ptr->vdisplay)
1851 continue;
1852 if (fresh != drm_mode_vrefresh(ptr))
1853 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001854 if (rb != mode_is_rb(ptr))
1855 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001856
1857 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08001858 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001859
1860 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08001861}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001862EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04001863
Adam Jacksond1ff6402010-03-29 21:43:26 +00001864typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1865
1866static void
Adam Jackson4d76a222010-08-03 14:38:17 -04001867cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1868{
1869 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001870 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04001871 u8 *det_base = ext + d;
1872
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001873 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04001874 for (i = 0; i < n; i++)
1875 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1876}
1877
1878static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001879vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1880{
1881 unsigned int i, n = min((int)ext[0x02], 6);
1882 u8 *det_base = ext + 5;
1883
1884 if (ext[0x01] != 1)
1885 return; /* unknown version */
1886
1887 for (i = 0; i < n; i++)
1888 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1889}
1890
1891static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00001892drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1893{
1894 int i;
1895 struct edid *edid = (struct edid *)raw_edid;
1896
1897 if (edid == NULL)
1898 return;
1899
1900 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1901 cb(&(edid->detailed_timings[i]), closure);
1902
Adam Jackson4d76a222010-08-03 14:38:17 -04001903 for (i = 1; i <= raw_edid[0x7e]; i++) {
1904 u8 *ext = raw_edid + (i * EDID_LENGTH);
1905 switch (*ext) {
1906 case CEA_EXT:
1907 cea_for_each_detailed_block(ext, cb, closure);
1908 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001909 case VTB_EXT:
1910 vtb_for_each_detailed_block(ext, cb, closure);
1911 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04001912 default:
1913 break;
1914 }
1915 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00001916}
1917
1918static void
1919is_rb(struct detailed_timing *t, void *data)
1920{
1921 u8 *r = (u8 *)t;
1922 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
1923 if (r[15] & 0x10)
1924 *(bool *)data = true;
1925}
1926
1927/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1928static bool
1929drm_monitor_supports_rb(struct edid *edid)
1930{
1931 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02001932 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00001933 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
1934 return ret;
1935 }
1936
1937 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
1938}
1939
Adam Jackson7a374352010-03-29 21:43:30 +00001940static void
1941find_gtf2(struct detailed_timing *t, void *data)
1942{
1943 u8 *r = (u8 *)t;
1944 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
1945 *(u8 **)data = r;
1946}
1947
1948/* Secondary GTF curve kicks in above some break frequency */
1949static int
1950drm_gtf2_hbreak(struct edid *edid)
1951{
1952 u8 *r = NULL;
1953 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1954 return r ? (r[12] * 2) : 0;
1955}
1956
1957static int
1958drm_gtf2_2c(struct edid *edid)
1959{
1960 u8 *r = NULL;
1961 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1962 return r ? r[13] : 0;
1963}
1964
1965static int
1966drm_gtf2_m(struct edid *edid)
1967{
1968 u8 *r = NULL;
1969 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1970 return r ? (r[15] << 8) + r[14] : 0;
1971}
1972
1973static int
1974drm_gtf2_k(struct edid *edid)
1975{
1976 u8 *r = NULL;
1977 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1978 return r ? r[16] : 0;
1979}
1980
1981static int
1982drm_gtf2_2j(struct edid *edid)
1983{
1984 u8 *r = NULL;
1985 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1986 return r ? r[17] : 0;
1987}
1988
1989/**
1990 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
1991 * @edid: EDID block to scan
1992 */
1993static int standard_timing_level(struct edid *edid)
1994{
1995 if (edid->revision >= 2) {
1996 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
1997 return LEVEL_CVT;
1998 if (drm_gtf2_hbreak(edid))
1999 return LEVEL_GTF2;
2000 return LEVEL_GTF;
2001 }
2002 return LEVEL_DMT;
2003}
2004
Adam Jackson23425ca2009-09-23 17:30:58 -04002005/*
2006 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2007 * monitors fill with ascii space (0x20) instead.
2008 */
2009static int
2010bad_std_timing(u8 a, u8 b)
2011{
2012 return (a == 0x00 && b == 0x00) ||
2013 (a == 0x01 && b == 0x01) ||
2014 (a == 0x20 && b == 0x20);
2015}
2016
Dave Airlief453ba02008-11-07 14:05:41 -08002017/**
2018 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002019 * @connector: connector of for the EDID block
2020 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002021 * @t: standard timing params
2022 *
2023 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002024 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002025 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002026static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002027drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002028 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002029{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002030 struct drm_device *dev = connector->dev;
2031 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002032 int hsize, vsize;
2033 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002034 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2035 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002036 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2037 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002038 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002039
Adam Jackson23425ca2009-09-23 17:30:58 -04002040 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2041 return NULL;
2042
Zhao Yakui5c612592009-06-22 13:17:10 +08002043 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2044 hsize = t->hsize * 8 + 248;
2045 /* vrefresh_rate = vfreq + 60 */
2046 vrefresh_rate = vfreq + 60;
2047 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002048 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002049 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002050 vsize = hsize;
2051 else
2052 vsize = (hsize * 10) / 16;
2053 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002054 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002055 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002056 vsize = (hsize * 4) / 5;
2057 else
2058 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002059
2060 /* HDTV hack, part 1 */
2061 if (vrefresh_rate == 60 &&
2062 ((hsize == 1360 && vsize == 765) ||
2063 (hsize == 1368 && vsize == 769))) {
2064 hsize = 1366;
2065 vsize = 768;
2066 }
2067
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002068 /*
2069 * If this connector already has a mode for this size and refresh
2070 * rate (because it came from detailed or CVT info), use that
2071 * instead. This way we don't have to guess at interlace or
2072 * reduced blanking.
2073 */
Adam Jackson522032d2010-04-09 16:52:49 +00002074 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002075 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2076 drm_mode_vrefresh(m) == vrefresh_rate)
2077 return NULL;
2078
Adam Jacksona0910c82010-03-29 21:43:28 +00002079 /* HDTV hack, part 2 */
2080 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2081 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002082 false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002083 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002084 mode->hsync_start = mode->hsync_start - 1;
2085 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002086 return mode;
2087 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002088
Zhao Yakui559ee212009-09-03 09:33:47 +08002089 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002090 if (drm_monitor_supports_rb(edid)) {
2091 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2092 true);
2093 if (mode)
2094 return mode;
2095 }
2096 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002097 if (mode)
2098 return mode;
2099
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002100 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002101 switch (timing_level) {
2102 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002103 break;
2104 case LEVEL_GTF:
2105 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2106 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002107 case LEVEL_GTF2:
2108 /*
2109 * This is potentially wrong if there's ever a monitor with
2110 * more than one ranges section, each claiming a different
2111 * secondary GTF curve. Please don't do that.
2112 */
2113 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002114 if (!mode)
2115 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002116 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002117 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002118 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2119 vrefresh_rate, 0, 0,
2120 drm_gtf2_m(edid),
2121 drm_gtf2_2c(edid),
2122 drm_gtf2_k(edid),
2123 drm_gtf2_2j(edid));
2124 }
2125 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002126 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002127 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2128 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002129 break;
2130 }
Dave Airlief453ba02008-11-07 14:05:41 -08002131 return mode;
2132}
2133
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002134/*
2135 * EDID is delightfully ambiguous about how interlaced modes are to be
2136 * encoded. Our internal representation is of frame height, but some
2137 * HDTV detailed timings are encoded as field height.
2138 *
2139 * The format list here is from CEA, in frame size. Technically we
2140 * should be checking refresh rate too. Whatever.
2141 */
2142static void
2143drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2144 struct detailed_pixel_timing *pt)
2145{
2146 int i;
2147 static const struct {
2148 int w, h;
2149 } cea_interlaced[] = {
2150 { 1920, 1080 },
2151 { 720, 480 },
2152 { 1440, 480 },
2153 { 2880, 480 },
2154 { 720, 576 },
2155 { 1440, 576 },
2156 { 2880, 576 },
2157 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002158
2159 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2160 return;
2161
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002162 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002163 if ((mode->hdisplay == cea_interlaced[i].w) &&
2164 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2165 mode->vdisplay *= 2;
2166 mode->vsync_start *= 2;
2167 mode->vsync_end *= 2;
2168 mode->vtotal *= 2;
2169 mode->vtotal |= 1;
2170 }
2171 }
2172
2173 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2174}
2175
Dave Airlief453ba02008-11-07 14:05:41 -08002176/**
2177 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2178 * @dev: DRM device (needed to create new mode)
2179 * @edid: EDID block
2180 * @timing: EDID detailed timing info
2181 * @quirks: quirks to apply
2182 *
2183 * An EDID detailed timing block contains enough info for us to create and
2184 * return a new struct drm_display_mode.
2185 */
2186static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2187 struct edid *edid,
2188 struct detailed_timing *timing,
2189 u32 quirks)
2190{
2191 struct drm_display_mode *mode;
2192 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002193 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2194 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2195 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2196 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002197 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2198 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 +01002199 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 +02002200 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 -08002201
Adam Jacksonfc438962009-06-04 10:20:34 +10002202 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002203 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002204 return NULL;
2205
Michel Dänzer0454bea2009-06-15 16:56:07 +02002206 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002207 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002208 return NULL;
2209 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002210 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002211 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002212 }
2213
Zhao Yakuifcb45612009-10-14 09:11:25 +08002214 /* it is incorrect if hsync/vsync width is zero */
2215 if (!hsync_pulse_width || !vsync_pulse_width) {
2216 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2217 "Wrong Hsync/Vsync pulse width\n");
2218 return NULL;
2219 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002220
2221 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2222 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2223 if (!mode)
2224 return NULL;
2225
2226 goto set_size;
2227 }
2228
Dave Airlief453ba02008-11-07 14:05:41 -08002229 mode = drm_mode_create(dev);
2230 if (!mode)
2231 return NULL;
2232
Dave Airlief453ba02008-11-07 14:05:41 -08002233 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002234 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002235
Michel Dänzer0454bea2009-06-15 16:56:07 +02002236 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002237
Michel Dänzer0454bea2009-06-15 16:56:07 +02002238 mode->hdisplay = hactive;
2239 mode->hsync_start = mode->hdisplay + hsync_offset;
2240 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2241 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002242
Michel Dänzer0454bea2009-06-15 16:56:07 +02002243 mode->vdisplay = vactive;
2244 mode->vsync_start = mode->vdisplay + vsync_offset;
2245 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2246 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002247
Jesse Barnes7064fef2009-11-05 10:12:54 -08002248 /* Some EDIDs have bogus h/vtotal values */
2249 if (mode->hsync_end > mode->htotal)
2250 mode->htotal = mode->hsync_end + 1;
2251 if (mode->vsync_end > mode->vtotal)
2252 mode->vtotal = mode->vsync_end + 1;
2253
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002254 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002255
2256 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002257 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002258 }
2259
Michel Dänzer0454bea2009-06-15 16:56:07 +02002260 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2261 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2262 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2263 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002264
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002265set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002266 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2267 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002268
2269 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2270 mode->width_mm *= 10;
2271 mode->height_mm *= 10;
2272 }
2273
2274 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2275 mode->width_mm = edid->width_cm * 10;
2276 mode->height_mm = edid->height_cm * 10;
2277 }
2278
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002279 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002280 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002281 drm_mode_set_name(mode);
2282
Dave Airlief453ba02008-11-07 14:05:41 -08002283 return mode;
2284}
2285
Adam Jackson07a5e632009-12-03 17:44:38 -05002286static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002287mode_in_hsync_range(const struct drm_display_mode *mode,
2288 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002289{
2290 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002291
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002292 hmin = t[7];
2293 if (edid->revision >= 4)
2294 hmin += ((t[4] & 0x04) ? 255 : 0);
2295 hmax = t[8];
2296 if (edid->revision >= 4)
2297 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002298 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002299
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002300 return (hsync <= hmax && hsync >= hmin);
2301}
2302
2303static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002304mode_in_vsync_range(const struct drm_display_mode *mode,
2305 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002306{
2307 int vsync, vmin, vmax;
2308
2309 vmin = t[5];
2310 if (edid->revision >= 4)
2311 vmin += ((t[4] & 0x01) ? 255 : 0);
2312 vmax = t[6];
2313 if (edid->revision >= 4)
2314 vmax += ((t[4] & 0x02) ? 255 : 0);
2315 vsync = drm_mode_vrefresh(mode);
2316
2317 return (vsync <= vmax && vsync >= vmin);
2318}
2319
2320static u32
2321range_pixel_clock(struct edid *edid, u8 *t)
2322{
2323 /* unspecified */
2324 if (t[9] == 0 || t[9] == 255)
2325 return 0;
2326
2327 /* 1.4 with CVT support gives us real precision, yay */
2328 if (edid->revision >= 4 && t[10] == 0x04)
2329 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2330
2331 /* 1.3 is pathetic, so fuzz up a bit */
2332 return t[9] * 10000 + 5001;
2333}
2334
Adam Jackson07a5e632009-12-03 17:44:38 -05002335static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002336mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002337 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002338{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002339 u32 max_clock;
2340 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002341
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002342 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002343 return false;
2344
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002345 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002346 return false;
2347
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002348 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002349 if (mode->clock > max_clock)
2350 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002351
2352 /* 1.4 max horizontal check */
2353 if (edid->revision >= 4 && t[10] == 0x04)
2354 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2355 return false;
2356
2357 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2358 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002359
2360 return true;
2361}
2362
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002363static bool valid_inferred_mode(const struct drm_connector *connector,
2364 const struct drm_display_mode *mode)
2365{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002366 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002367 bool ok = false;
2368
2369 list_for_each_entry(m, &connector->probed_modes, head) {
2370 if (mode->hdisplay == m->hdisplay &&
2371 mode->vdisplay == m->vdisplay &&
2372 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2373 return false; /* duplicated */
2374 if (mode->hdisplay <= m->hdisplay &&
2375 mode->vdisplay <= m->vdisplay)
2376 ok = true;
2377 }
2378 return ok;
2379}
2380
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002381static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002382drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002383 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002384{
2385 int i, modes = 0;
2386 struct drm_display_mode *newmode;
2387 struct drm_device *dev = connector->dev;
2388
Thierry Redinga6b21832012-11-23 15:01:42 +01002389 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002390 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2391 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002392 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2393 if (newmode) {
2394 drm_mode_probed_add(connector, newmode);
2395 modes++;
2396 }
2397 }
2398 }
2399
2400 return modes;
2401}
2402
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002403/* fix up 1366x768 mode from 1368x768;
2404 * GFT/CVT can't express 1366 width which isn't dividable by 8
2405 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002406void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002407{
2408 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2409 mode->hdisplay = 1366;
2410 mode->hsync_start--;
2411 mode->hsync_end--;
2412 drm_mode_set_name(mode);
2413 }
2414}
2415
Adam Jacksonb309bd32012-04-13 16:33:40 -04002416static int
2417drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2418 struct detailed_timing *timing)
2419{
2420 int i, modes = 0;
2421 struct drm_display_mode *newmode;
2422 struct drm_device *dev = connector->dev;
2423
Thierry Redinga6b21832012-11-23 15:01:42 +01002424 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002425 const struct minimode *m = &extra_modes[i];
2426 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002427 if (!newmode)
2428 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002429
Takashi Iwai969218f2017-01-17 17:43:29 +01002430 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002431 if (!mode_in_range(newmode, edid, timing) ||
2432 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002433 drm_mode_destroy(dev, newmode);
2434 continue;
2435 }
2436
2437 drm_mode_probed_add(connector, newmode);
2438 modes++;
2439 }
2440
2441 return modes;
2442}
2443
2444static int
2445drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2446 struct detailed_timing *timing)
2447{
2448 int i, modes = 0;
2449 struct drm_display_mode *newmode;
2450 struct drm_device *dev = connector->dev;
2451 bool rb = drm_monitor_supports_rb(edid);
2452
Thierry Redinga6b21832012-11-23 15:01:42 +01002453 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002454 const struct minimode *m = &extra_modes[i];
2455 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002456 if (!newmode)
2457 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002458
Takashi Iwai969218f2017-01-17 17:43:29 +01002459 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002460 if (!mode_in_range(newmode, edid, timing) ||
2461 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002462 drm_mode_destroy(dev, newmode);
2463 continue;
2464 }
2465
2466 drm_mode_probed_add(connector, newmode);
2467 modes++;
2468 }
2469
2470 return modes;
2471}
2472
Adam Jackson13931572010-08-03 14:38:19 -04002473static void
2474do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002475{
Adam Jackson13931572010-08-03 14:38:19 -04002476 struct detailed_mode_closure *closure = c;
2477 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002478 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002479
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002480 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2481 return;
2482
2483 closure->modes += drm_dmt_modes_for_range(closure->connector,
2484 closure->edid,
2485 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002486
2487 if (!version_greater(closure->edid, 1, 1))
2488 return; /* GTF not defined yet */
2489
2490 switch (range->flags) {
2491 case 0x02: /* secondary gtf, XXX could do more */
2492 case 0x00: /* default gtf */
2493 closure->modes += drm_gtf_modes_for_range(closure->connector,
2494 closure->edid,
2495 timing);
2496 break;
2497 case 0x04: /* cvt, only in 1.4+ */
2498 if (!version_greater(closure->edid, 1, 3))
2499 break;
2500
2501 closure->modes += drm_cvt_modes_for_range(closure->connector,
2502 closure->edid,
2503 timing);
2504 break;
2505 case 0x01: /* just the ranges, no formula */
2506 default:
2507 break;
2508 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002509}
2510
Adam Jackson13931572010-08-03 14:38:19 -04002511static int
2512add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2513{
2514 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002515 .connector = connector,
2516 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002517 };
2518
2519 if (version_greater(edid, 1, 0))
2520 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2521 &closure);
2522
2523 return closure.modes;
2524}
2525
Adam Jackson2255be12010-03-29 21:43:22 +00002526static int
2527drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2528{
2529 int i, j, m, modes = 0;
2530 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002531 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002532
2533 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002534 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002535 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002536 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002537 break;
2538 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002539 mode = drm_mode_find_dmt(connector->dev,
2540 est3_modes[m].w,
2541 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002542 est3_modes[m].r,
2543 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002544 if (mode) {
2545 drm_mode_probed_add(connector, mode);
2546 modes++;
2547 }
2548 }
2549 }
2550 }
2551
2552 return modes;
2553}
2554
Adam Jackson13931572010-08-03 14:38:19 -04002555static void
2556do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002557{
Adam Jackson13931572010-08-03 14:38:19 -04002558 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002559 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002560
2561 if (data->type == EDID_DETAIL_EST_TIMINGS)
2562 closure->modes += drm_est3_modes(closure->connector, timing);
2563}
2564
2565/**
2566 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002567 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002568 * @edid: EDID block to scan
2569 *
2570 * Each EDID block contains a bitmap of the supported "established modes" list
2571 * (defined above). Tease them out and add them to the global modes list.
2572 */
2573static int
2574add_established_modes(struct drm_connector *connector, struct edid *edid)
2575{
Adam Jackson9cf00972009-12-03 17:44:36 -05002576 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002577 unsigned long est_bits = edid->established_timings.t1 |
2578 (edid->established_timings.t2 << 8) |
2579 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2580 int i, modes = 0;
2581 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002582 .connector = connector,
2583 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002584 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002585
Adam Jackson13931572010-08-03 14:38:19 -04002586 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2587 if (est_bits & (1<<i)) {
2588 struct drm_display_mode *newmode;
2589 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2590 if (newmode) {
2591 drm_mode_probed_add(connector, newmode);
2592 modes++;
2593 }
2594 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002595 }
2596
Adam Jackson13931572010-08-03 14:38:19 -04002597 if (version_greater(edid, 1, 0))
2598 drm_for_each_detailed_block((u8 *)edid,
2599 do_established_modes, &closure);
2600
2601 return modes + closure.modes;
2602}
2603
2604static void
2605do_standard_modes(struct detailed_timing *timing, void *c)
2606{
2607 struct detailed_mode_closure *closure = c;
2608 struct detailed_non_pixel *data = &timing->data.other_data;
2609 struct drm_connector *connector = closure->connector;
2610 struct edid *edid = closure->edid;
2611
2612 if (data->type == EDID_DETAIL_STD_MODES) {
2613 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002614 for (i = 0; i < 6; i++) {
2615 struct std_timing *std;
2616 struct drm_display_mode *newmode;
2617
2618 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002619 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002620 if (newmode) {
2621 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002622 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002623 }
2624 }
Adam Jackson13931572010-08-03 14:38:19 -04002625 }
2626}
2627
2628/**
2629 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002630 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002631 * @edid: EDID block to scan
2632 *
2633 * Standard modes can be calculated using the appropriate standard (DMT,
2634 * GTF or CVT. Grab them from @edid and add them to the list.
2635 */
2636static int
2637add_standard_modes(struct drm_connector *connector, struct edid *edid)
2638{
2639 int i, modes = 0;
2640 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002641 .connector = connector,
2642 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002643 };
2644
2645 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2646 struct drm_display_mode *newmode;
2647
2648 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002649 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002650 if (newmode) {
2651 drm_mode_probed_add(connector, newmode);
2652 modes++;
2653 }
2654 }
2655
2656 if (version_greater(edid, 1, 0))
2657 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2658 &closure);
2659
2660 /* XXX should also look for standard codes in VTB blocks */
2661
2662 return modes + closure.modes;
2663}
2664
Dave Airlief453ba02008-11-07 14:05:41 -08002665static int drm_cvt_modes(struct drm_connector *connector,
2666 struct detailed_timing *timing)
2667{
2668 int i, j, modes = 0;
2669 struct drm_display_mode *newmode;
2670 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002671 struct cvt_timing *cvt;
2672 const int rates[] = { 60, 85, 75, 60, 50 };
2673 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002674
2675 for (i = 0; i < 4; i++) {
2676 int uninitialized_var(width), height;
2677 cvt = &(timing->data.other_data.data.cvt[i]);
2678
2679 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002680 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002681
2682 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002683 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002684 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002685 width = height * 4 / 3;
2686 break;
2687 case 0x04:
2688 width = height * 16 / 9;
2689 break;
2690 case 0x08:
2691 width = height * 16 / 10;
2692 break;
2693 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002694 width = height * 15 / 9;
2695 break;
2696 }
2697
2698 for (j = 1; j < 5; j++) {
2699 if (cvt->code[2] & (1 << j)) {
2700 newmode = drm_cvt_mode(dev, width, height,
2701 rates[j], j == 0,
2702 false, false);
2703 if (newmode) {
2704 drm_mode_probed_add(connector, newmode);
2705 modes++;
2706 }
2707 }
2708 }
2709 }
2710
2711 return modes;
2712}
2713
Adam Jackson13931572010-08-03 14:38:19 -04002714static void
2715do_cvt_mode(struct detailed_timing *timing, void *c)
2716{
2717 struct detailed_mode_closure *closure = c;
2718 struct detailed_non_pixel *data = &timing->data.other_data;
2719
2720 if (data->type == EDID_DETAIL_CVT_3BYTE)
2721 closure->modes += drm_cvt_modes(closure->connector, timing);
2722}
Adam Jackson9cf00972009-12-03 17:44:36 -05002723
2724static int
Adam Jackson13931572010-08-03 14:38:19 -04002725add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2726{
2727 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002728 .connector = connector,
2729 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002730 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002731
Adam Jackson13931572010-08-03 14:38:19 -04002732 if (version_greater(edid, 1, 2))
2733 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002734
Adam Jackson13931572010-08-03 14:38:19 -04002735 /* XXX should also look for CVT codes in VTB blocks */
2736
2737 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002738}
2739
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002740static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2741
Adam Jackson13931572010-08-03 14:38:19 -04002742static void
2743do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002744{
Adam Jackson13931572010-08-03 14:38:19 -04002745 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002746 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002747
2748 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002749 newmode = drm_mode_detailed(closure->connector->dev,
2750 closure->edid, timing,
2751 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002752 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002753 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002754
Adam Jackson13931572010-08-03 14:38:19 -04002755 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002756 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2757
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002758 /*
2759 * Detailed modes are limited to 10kHz pixel clock resolution,
2760 * so fix up anything that looks like CEA/HDMI mode, but the clock
2761 * is just slightly off.
2762 */
2763 fixup_detailed_cea_mode_clock(newmode);
2764
Adam Jackson13931572010-08-03 14:38:19 -04002765 drm_mode_probed_add(closure->connector, newmode);
2766 closure->modes++;
2767 closure->preferred = 0;
Zhao Yakui882f0212009-08-26 18:20:49 +08002768 }
Ma Ling167f3a02009-03-20 14:09:48 +08002769}
2770
Adam Jackson13931572010-08-03 14:38:19 -04002771/*
2772 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002773 * @connector: attached connector
2774 * @edid: EDID block to scan
2775 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002776 */
Adam Jackson13931572010-08-03 14:38:19 -04002777static int
2778add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2779 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002780{
Adam Jackson13931572010-08-03 14:38:19 -04002781 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002782 .connector = connector,
2783 .edid = edid,
2784 .preferred = 1,
2785 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002786 };
Dave Airlief453ba02008-11-07 14:05:41 -08002787
Adam Jackson13931572010-08-03 14:38:19 -04002788 if (closure.preferred && !version_greater(edid, 1, 3))
2789 closure.preferred =
2790 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002791
Adam Jackson13931572010-08-03 14:38:19 -04002792 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002793
Adam Jackson13931572010-08-03 14:38:19 -04002794 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002795}
Dave Airlief453ba02008-11-07 14:05:41 -08002796
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002797#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002798#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002799#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002800#define SPEAKER_BLOCK 0x04
Shashank Sharma87563fc2017-07-13 21:03:10 +05302801#define USE_EXTENDED_TAG 0x07
2802#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05302803#define EXT_VIDEO_DATA_BLOCK_420 0x0E
2804#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002805#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02002806#define EDID_CEA_YCRCB444 (1 << 5)
2807#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002808#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002809
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002810/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002811 * Search EDID for CEA extension block.
2812 */
Dave Airlie40d9b042014-10-20 16:29:33 +10002813static u8 *drm_find_edid_extension(struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002814{
2815 u8 *edid_ext = NULL;
2816 int i;
2817
2818 /* No EDID or EDID extensions */
2819 if (edid == NULL || edid->extensions == 0)
2820 return NULL;
2821
2822 /* Find CEA extension */
2823 for (i = 0; i < edid->extensions; i++) {
2824 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10002825 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002826 break;
2827 }
2828
2829 if (i == edid->extensions)
2830 return NULL;
2831
2832 return edid_ext;
2833}
2834
Dave Airlie40d9b042014-10-20 16:29:33 +10002835static u8 *drm_find_cea_extension(struct edid *edid)
2836{
2837 return drm_find_edid_extension(edid, CEA_EXT);
2838}
2839
2840static u8 *drm_find_displayid_extension(struct edid *edid)
2841{
2842 return drm_find_edid_extension(edid, DISPLAYID_EXT);
2843}
2844
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002845/*
2846 * Calculate the alternate clock for the CEA mode
2847 * (60Hz vs. 59.94Hz etc.)
2848 */
2849static unsigned int
2850cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2851{
2852 unsigned int clock = cea_mode->clock;
2853
2854 if (cea_mode->vrefresh % 6 != 0)
2855 return clock;
2856
2857 /*
2858 * edid_cea_modes contains the 59.94Hz
2859 * variant for 240 and 480 line modes,
2860 * and the 60Hz variant otherwise.
2861 */
2862 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002863 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002864 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002865 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002866
2867 return clock;
2868}
2869
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002870static bool
2871cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
2872{
2873 /*
2874 * For certain VICs the spec allows the vertical
2875 * front porch to vary by one or two lines.
2876 *
2877 * cea_modes[] stores the variant with the shortest
2878 * vertical front porch. We can adjust the mode to
2879 * get the other variants by simply increasing the
2880 * vertical front porch length.
2881 */
2882 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
2883 edid_cea_modes[9].vtotal != 262 ||
2884 edid_cea_modes[12].vtotal != 262 ||
2885 edid_cea_modes[13].vtotal != 262 ||
2886 edid_cea_modes[23].vtotal != 312 ||
2887 edid_cea_modes[24].vtotal != 312 ||
2888 edid_cea_modes[27].vtotal != 312 ||
2889 edid_cea_modes[28].vtotal != 312);
2890
2891 if (((vic == 8 || vic == 9 ||
2892 vic == 12 || vic == 13) && mode->vtotal < 263) ||
2893 ((vic == 23 || vic == 24 ||
2894 vic == 27 || vic == 28) && mode->vtotal < 314)) {
2895 mode->vsync_start++;
2896 mode->vsync_end++;
2897 mode->vtotal++;
2898
2899 return true;
2900 }
2901
2902 return false;
2903}
2904
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002905static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
2906 unsigned int clock_tolerance)
2907{
Jani Nikulad9278b42016-01-08 13:21:51 +02002908 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002909
2910 if (!to_match->clock)
2911 return 0;
2912
Jani Nikulad9278b42016-01-08 13:21:51 +02002913 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002914 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002915 unsigned int clock1, clock2;
2916
2917 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002918 clock1 = cea_mode.clock;
2919 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002920
2921 if (abs(to_match->clock - clock1) > clock_tolerance &&
2922 abs(to_match->clock - clock2) > clock_tolerance)
2923 continue;
2924
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002925 do {
2926 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2927 return vic;
2928 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002929 }
2930
2931 return 0;
2932}
2933
Thierry Reding18316c82012-12-20 15:41:44 +01002934/**
2935 * drm_match_cea_mode - look for a CEA mode matching given mode
2936 * @to_match: display mode
2937 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002938 * 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 +01002939 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00002940 */
Thierry Reding18316c82012-12-20 15:41:44 +01002941u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00002942{
Jani Nikulad9278b42016-01-08 13:21:51 +02002943 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00002944
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002945 if (!to_match->clock)
2946 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00002947
Jani Nikulad9278b42016-01-08 13:21:51 +02002948 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002949 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002950 unsigned int clock1, clock2;
2951
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002952 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002953 clock1 = cea_mode.clock;
2954 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002955
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002956 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
2957 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
2958 continue;
2959
2960 do {
2961 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2962 return vic;
2963 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00002964 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002965
Stephane Marchesina4799032012-11-09 16:21:05 +00002966 return 0;
2967}
2968EXPORT_SYMBOL(drm_match_cea_mode);
2969
Jani Nikulad9278b42016-01-08 13:21:51 +02002970static bool drm_valid_cea_vic(u8 vic)
2971{
2972 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
2973}
2974
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302975/**
2976 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2977 * the input VIC from the CEA mode list
2978 * @video_code: ID given to each of the CEA modes
2979 *
2980 * Returns picture aspect ratio
2981 */
2982enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
2983{
Jani Nikulad9278b42016-01-08 13:21:51 +02002984 return edid_cea_modes[video_code].picture_aspect_ratio;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302985}
2986EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
2987
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002988/*
2989 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
2990 * specific block).
2991 *
2992 * It's almost like cea_mode_alternate_clock(), we just need to add an
2993 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
2994 * one.
2995 */
2996static unsigned int
2997hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
2998{
2999 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
3000 return hdmi_mode->clock;
3001
3002 return cea_mode_alternate_clock(hdmi_mode);
3003}
3004
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003005static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3006 unsigned int clock_tolerance)
3007{
Jani Nikulad9278b42016-01-08 13:21:51 +02003008 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003009
3010 if (!to_match->clock)
3011 return 0;
3012
Jani Nikulad9278b42016-01-08 13:21:51 +02003013 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3014 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003015 unsigned int clock1, clock2;
3016
3017 /* Make sure to also match alternate clocks */
3018 clock1 = hdmi_mode->clock;
3019 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3020
3021 if (abs(to_match->clock - clock1) > clock_tolerance &&
3022 abs(to_match->clock - clock2) > clock_tolerance)
3023 continue;
3024
3025 if (drm_mode_equal_no_clocks(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02003026 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003027 }
3028
3029 return 0;
3030}
3031
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003032/*
3033 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3034 * @to_match: display mode
3035 *
3036 * An HDMI mode is one defined in the HDMI vendor specific block.
3037 *
3038 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3039 */
3040static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3041{
Jani Nikulad9278b42016-01-08 13:21:51 +02003042 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003043
3044 if (!to_match->clock)
3045 return 0;
3046
Jani Nikulad9278b42016-01-08 13:21:51 +02003047 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3048 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003049 unsigned int clock1, clock2;
3050
3051 /* Make sure to also match alternate clocks */
3052 clock1 = hdmi_mode->clock;
3053 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3054
3055 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3056 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01003057 drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02003058 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003059 }
3060 return 0;
3061}
3062
Jani Nikulad9278b42016-01-08 13:21:51 +02003063static bool drm_valid_hdmi_vic(u8 vic)
3064{
3065 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3066}
3067
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003068static int
3069add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3070{
3071 struct drm_device *dev = connector->dev;
3072 struct drm_display_mode *mode, *tmp;
3073 LIST_HEAD(list);
3074 int modes = 0;
3075
3076 /* Don't add CEA modes if the CEA extension block is missing */
3077 if (!drm_find_cea_extension(edid))
3078 return 0;
3079
3080 /*
3081 * Go through all probed modes and create a new mode
3082 * with the alternate clock for certain CEA modes.
3083 */
3084 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003085 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003086 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003087 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003088 unsigned int clock1, clock2;
3089
Jani Nikulad9278b42016-01-08 13:21:51 +02003090 if (drm_valid_cea_vic(vic)) {
3091 cea_mode = &edid_cea_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003092 clock2 = cea_mode_alternate_clock(cea_mode);
3093 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003094 vic = drm_match_hdmi_mode(mode);
3095 if (drm_valid_hdmi_vic(vic)) {
3096 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003097 clock2 = hdmi_mode_alternate_clock(cea_mode);
3098 }
3099 }
3100
3101 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003102 continue;
3103
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003104 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003105
3106 if (clock1 == clock2)
3107 continue;
3108
3109 if (mode->clock != clock1 && mode->clock != clock2)
3110 continue;
3111
3112 newmode = drm_mode_duplicate(dev, cea_mode);
3113 if (!newmode)
3114 continue;
3115
Damien Lespiau27130212013-09-25 16:45:28 +01003116 /* Carry over the stereo flags */
3117 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3118
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003119 /*
3120 * The current mode could be either variant. Make
3121 * sure to pick the "other" clock for the new mode.
3122 */
3123 if (mode->clock != clock1)
3124 newmode->clock = clock1;
3125 else
3126 newmode->clock = clock2;
3127
3128 list_add_tail(&newmode->head, &list);
3129 }
3130
3131 list_for_each_entry_safe(mode, tmp, &list, head) {
3132 list_del(&mode->head);
3133 drm_mode_probed_add(connector, mode);
3134 modes++;
3135 }
3136
3137 return modes;
3138}
Stephane Marchesina4799032012-11-09 16:21:05 +00003139
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303140static u8 svd_to_vic(u8 svd)
3141{
3142 /* 0-6 bit vic, 7th bit native mode indicator */
3143 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3144 return svd & 127;
3145
3146 return svd;
3147}
3148
Thomas Woodaff04ac2013-11-29 15:33:27 +00003149static struct drm_display_mode *
3150drm_display_mode_from_vic_index(struct drm_connector *connector,
3151 const u8 *video_db, u8 video_len,
3152 u8 video_index)
3153{
3154 struct drm_device *dev = connector->dev;
3155 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003156 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003157
3158 if (video_db == NULL || video_index >= video_len)
3159 return NULL;
3160
3161 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303162 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003163 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003164 return NULL;
3165
Jani Nikulad9278b42016-01-08 13:21:51 +02003166 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00003167 if (!newmode)
3168 return NULL;
3169
Thomas Woodaff04ac2013-11-29 15:33:27 +00003170 newmode->vrefresh = 0;
3171
3172 return newmode;
3173}
3174
Shashank Sharma832d4f22017-07-14 16:03:46 +05303175/*
3176 * do_y420vdb_modes - Parse YCBCR 420 only modes
3177 * @connector: connector corresponding to the HDMI sink
3178 * @svds: start of the data block of CEA YCBCR 420 VDB
3179 * @len: length of the CEA YCBCR 420 VDB
3180 *
3181 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3182 * which contains modes which can be supported in YCBCR 420
3183 * output format only.
3184 */
3185static int do_y420vdb_modes(struct drm_connector *connector,
3186 const u8 *svds, u8 svds_len)
3187{
3188 int modes = 0, i;
3189 struct drm_device *dev = connector->dev;
3190 struct drm_display_info *info = &connector->display_info;
3191 struct drm_hdmi_info *hdmi = &info->hdmi;
3192
3193 for (i = 0; i < svds_len; i++) {
3194 u8 vic = svd_to_vic(svds[i]);
3195 struct drm_display_mode *newmode;
3196
3197 if (!drm_valid_cea_vic(vic))
3198 continue;
3199
3200 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3201 if (!newmode)
3202 break;
3203 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3204 drm_mode_probed_add(connector, newmode);
3205 modes++;
3206 }
3207
3208 if (modes > 0)
3209 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3210 return modes;
3211}
3212
3213/*
3214 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3215 * @connector: connector corresponding to the HDMI sink
3216 * @vic: CEA vic for the video mode to be added in the map
3217 *
3218 * Makes an entry for a videomode in the YCBCR 420 bitmap
3219 */
3220static void
3221drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3222{
3223 u8 vic = svd_to_vic(svd);
3224 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3225
3226 if (!drm_valid_cea_vic(vic))
3227 return;
3228
3229 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3230}
3231
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003232static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003233do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003234{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003235 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303236 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003237
Thomas Woodaff04ac2013-11-29 15:33:27 +00003238 for (i = 0; i < len; i++) {
3239 struct drm_display_mode *mode;
3240 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3241 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303242 /*
3243 * YCBCR420 capability block contains a bitmap which
3244 * gives the index of CEA modes from CEA VDB, which
3245 * can support YCBCR 420 sampling output also (apart
3246 * from RGB/YCBCR444 etc).
3247 * For example, if the bit 0 in bitmap is set,
3248 * first mode in VDB can support YCBCR420 output too.
3249 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3250 */
3251 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3252 drm_add_cmdb_modes(connector, db[i]);
3253
Thomas Woodaff04ac2013-11-29 15:33:27 +00003254 drm_mode_probed_add(connector, mode);
3255 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003256 }
3257 }
3258
3259 return modes;
3260}
3261
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003262struct stereo_mandatory_mode {
3263 int width, height, vrefresh;
3264 unsigned int flags;
3265};
3266
3267static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003268 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3269 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003270 { 1920, 1080, 50,
3271 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3272 { 1920, 1080, 60,
3273 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003274 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3275 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3276 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3277 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003278};
3279
3280static bool
3281stereo_match_mandatory(const struct drm_display_mode *mode,
3282 const struct stereo_mandatory_mode *stereo_mode)
3283{
3284 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3285
3286 return mode->hdisplay == stereo_mode->width &&
3287 mode->vdisplay == stereo_mode->height &&
3288 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3289 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3290}
3291
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003292static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3293{
3294 struct drm_device *dev = connector->dev;
3295 const struct drm_display_mode *mode;
3296 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003297 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003298
3299 INIT_LIST_HEAD(&stereo_modes);
3300
3301 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003302 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3303 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003304 struct drm_display_mode *new_mode;
3305
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003306 if (!stereo_match_mandatory(mode,
3307 &stereo_mandatory_modes[i]))
3308 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003309
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003310 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003311 new_mode = drm_mode_duplicate(dev, mode);
3312 if (!new_mode)
3313 continue;
3314
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003315 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003316 list_add_tail(&new_mode->head, &stereo_modes);
3317 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003318 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003319 }
3320
3321 list_splice_tail(&stereo_modes, &connector->probed_modes);
3322
3323 return modes;
3324}
3325
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003326static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3327{
3328 struct drm_device *dev = connector->dev;
3329 struct drm_display_mode *newmode;
3330
Jani Nikulad9278b42016-01-08 13:21:51 +02003331 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003332 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3333 return 0;
3334 }
3335
3336 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3337 if (!newmode)
3338 return 0;
3339
3340 drm_mode_probed_add(connector, newmode);
3341
3342 return 1;
3343}
3344
Thomas Woodfbf46022013-10-16 15:58:50 +01003345static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3346 const u8 *video_db, u8 video_len, u8 video_index)
3347{
Thomas Woodfbf46022013-10-16 15:58:50 +01003348 struct drm_display_mode *newmode;
3349 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003350
3351 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003352 newmode = drm_display_mode_from_vic_index(connector, video_db,
3353 video_len,
3354 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003355 if (newmode) {
3356 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3357 drm_mode_probed_add(connector, newmode);
3358 modes++;
3359 }
3360 }
3361 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003362 newmode = drm_display_mode_from_vic_index(connector, video_db,
3363 video_len,
3364 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003365 if (newmode) {
3366 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3367 drm_mode_probed_add(connector, newmode);
3368 modes++;
3369 }
3370 }
3371 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003372 newmode = drm_display_mode_from_vic_index(connector, video_db,
3373 video_len,
3374 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003375 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003376 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003377 drm_mode_probed_add(connector, newmode);
3378 modes++;
3379 }
3380 }
3381
3382 return modes;
3383}
3384
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003385/*
3386 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3387 * @connector: connector corresponding to the HDMI sink
3388 * @db: start of the CEA vendor specific block
3389 * @len: length of the CEA block payload, ie. one can access up to db[len]
3390 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003391 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3392 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003393 */
3394static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003395do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3396 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003397{
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003398 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003399 u8 vic_len, hdmi_3d_len = 0;
3400 u16 mask;
3401 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003402
3403 if (len < 8)
3404 goto out;
3405
3406 /* no HDMI_Video_Present */
3407 if (!(db[8] & (1 << 5)))
3408 goto out;
3409
3410 /* Latency_Fields_Present */
3411 if (db[8] & (1 << 7))
3412 offset += 2;
3413
3414 /* I_Latency_Fields_Present */
3415 if (db[8] & (1 << 6))
3416 offset += 2;
3417
3418 /* the declared length is not long enough for the 2 first bytes
3419 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003420 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003421 goto out;
3422
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003423 /* 3D_Present */
3424 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003425 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003426 modes += add_hdmi_mandatory_stereo_modes(connector);
3427
Thomas Woodfbf46022013-10-16 15:58:50 +01003428 /* 3D_Multi_present */
3429 multi_present = (db[8 + offset] & 0x60) >> 5;
3430 }
3431
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003432 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003433 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003434 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003435
3436 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003437 u8 vic;
3438
3439 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003440 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003441 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003442 offset += 1 + vic_len;
3443
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003444 if (multi_present == 1)
3445 multi_len = 2;
3446 else if (multi_present == 2)
3447 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003448 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003449 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003450
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003451 if (len < (8 + offset + hdmi_3d_len - 1))
3452 goto out;
3453
3454 if (hdmi_3d_len < multi_len)
3455 goto out;
3456
3457 if (multi_present == 1 || multi_present == 2) {
3458 /* 3D_Structure_ALL */
3459 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3460
3461 /* check if 3D_MASK is present */
3462 if (multi_present == 2)
3463 mask = (db[10 + offset] << 8) | db[11 + offset];
3464 else
3465 mask = 0xffff;
3466
3467 for (i = 0; i < 16; i++) {
3468 if (mask & (1 << i))
3469 modes += add_3d_struct_modes(connector,
3470 structure_all,
3471 video_db,
3472 video_len, i);
3473 }
3474 }
3475
3476 offset += multi_len;
3477
3478 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3479 int vic_index;
3480 struct drm_display_mode *newmode = NULL;
3481 unsigned int newflag = 0;
3482 bool detail_present;
3483
3484 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3485
3486 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3487 break;
3488
3489 /* 2D_VIC_order_X */
3490 vic_index = db[8 + offset + i] >> 4;
3491
3492 /* 3D_Structure_X */
3493 switch (db[8 + offset + i] & 0x0f) {
3494 case 0:
3495 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3496 break;
3497 case 6:
3498 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3499 break;
3500 case 8:
3501 /* 3D_Detail_X */
3502 if ((db[9 + offset + i] >> 4) == 1)
3503 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3504 break;
3505 }
3506
3507 if (newflag != 0) {
3508 newmode = drm_display_mode_from_vic_index(connector,
3509 video_db,
3510 video_len,
3511 vic_index);
3512
3513 if (newmode) {
3514 newmode->flags |= newflag;
3515 drm_mode_probed_add(connector, newmode);
3516 modes++;
3517 }
3518 }
3519
3520 if (detail_present)
3521 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003522 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003523
3524out:
3525 return modes;
3526}
3527
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003528static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003529cea_db_payload_len(const u8 *db)
3530{
3531 return db[0] & 0x1f;
3532}
3533
3534static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05303535cea_db_extended_tag(const u8 *db)
3536{
3537 return db[1];
3538}
3539
3540static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003541cea_db_tag(const u8 *db)
3542{
3543 return db[0] >> 5;
3544}
3545
3546static int
3547cea_revision(const u8 *cea)
3548{
3549 return cea[1];
3550}
3551
3552static int
3553cea_db_offsets(const u8 *cea, int *start, int *end)
3554{
3555 /* Data block offset in CEA extension block */
3556 *start = 4;
3557 *end = cea[2];
3558 if (*end == 0)
3559 *end = 127;
3560 if (*end < 4 || *end > 127)
3561 return -ERANGE;
3562 return 0;
3563}
3564
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003565static bool cea_db_is_hdmi_vsdb(const u8 *db)
3566{
3567 int hdmi_id;
3568
3569 if (cea_db_tag(db) != VENDOR_BLOCK)
3570 return false;
3571
3572 if (cea_db_payload_len(db) < 5)
3573 return false;
3574
3575 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3576
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003577 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003578}
3579
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303580static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3581{
3582 unsigned int oui;
3583
3584 if (cea_db_tag(db) != VENDOR_BLOCK)
3585 return false;
3586
3587 if (cea_db_payload_len(db) < 7)
3588 return false;
3589
3590 oui = db[3] << 16 | db[2] << 8 | db[1];
3591
3592 return oui == HDMI_FORUM_IEEE_OUI;
3593}
3594
Shashank Sharma832d4f22017-07-14 16:03:46 +05303595static bool cea_db_is_y420cmdb(const u8 *db)
3596{
3597 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3598 return false;
3599
3600 if (!cea_db_payload_len(db))
3601 return false;
3602
3603 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3604 return false;
3605
3606 return true;
3607}
3608
3609static bool cea_db_is_y420vdb(const u8 *db)
3610{
3611 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3612 return false;
3613
3614 if (!cea_db_payload_len(db))
3615 return false;
3616
3617 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3618 return false;
3619
3620 return true;
3621}
3622
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003623#define for_each_cea_db(cea, i, start, end) \
3624 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3625
Shashank Sharma832d4f22017-07-14 16:03:46 +05303626static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3627 const u8 *db)
3628{
3629 struct drm_display_info *info = &connector->display_info;
3630 struct drm_hdmi_info *hdmi = &info->hdmi;
3631 u8 map_len = cea_db_payload_len(db) - 1;
3632 u8 count;
3633 u64 map = 0;
3634
3635 if (map_len == 0) {
3636 /* All CEA modes support ycbcr420 sampling also.*/
3637 hdmi->y420_cmdb_map = U64_MAX;
3638 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3639 return;
3640 }
3641
3642 /*
3643 * This map indicates which of the existing CEA block modes
3644 * from VDB can support YCBCR420 output too. So if bit=0 is
3645 * set, first mode from VDB can support YCBCR420 output too.
3646 * We will parse and keep this map, before parsing VDB itself
3647 * to avoid going through the same block again and again.
3648 *
3649 * Spec is not clear about max possible size of this block.
3650 * Clamping max bitmap block size at 8 bytes. Every byte can
3651 * address 8 CEA modes, in this way this map can address
3652 * 8*8 = first 64 SVDs.
3653 */
3654 if (WARN_ON_ONCE(map_len > 8))
3655 map_len = 8;
3656
3657 for (count = 0; count < map_len; count++)
3658 map |= (u64)db[2 + count] << (8 * count);
3659
3660 if (map)
3661 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3662
3663 hdmi->y420_cmdb_map = map;
3664}
3665
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003666static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003667add_cea_modes(struct drm_connector *connector, struct edid *edid)
3668{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003669 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003670 const u8 *db, *hdmi = NULL, *video = NULL;
3671 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003672 int modes = 0;
3673
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003674 if (cea && cea_revision(cea) >= 3) {
3675 int i, start, end;
3676
3677 if (cea_db_offsets(cea, &start, &end))
3678 return 0;
3679
3680 for_each_cea_db(cea, i, start, end) {
3681 db = &cea[i];
3682 dbl = cea_db_payload_len(db);
3683
Thomas Woodfbf46022013-10-16 15:58:50 +01003684 if (cea_db_tag(db) == VIDEO_BLOCK) {
3685 video = db + 1;
3686 video_len = dbl;
3687 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05303688 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003689 hdmi = db;
3690 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303691 } else if (cea_db_is_y420vdb(db)) {
3692 const u8 *vdb420 = &db[2];
3693
3694 /* Add 4:2:0(only) modes present in EDID */
3695 modes += do_y420vdb_modes(connector,
3696 vdb420,
3697 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003698 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003699 }
3700 }
3701
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003702 /*
3703 * We parse the HDMI VSDB after having added the cea modes as we will
3704 * be patching their flags when the sink supports stereo 3D.
3705 */
3706 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003707 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3708 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003709
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003710 return modes;
3711}
3712
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003713static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3714{
3715 const struct drm_display_mode *cea_mode;
3716 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02003717 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003718 const char *type;
3719
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003720 /*
3721 * allow 5kHz clock difference either way to account for
3722 * the 10kHz clock resolution limit of detailed timings.
3723 */
Jani Nikulad9278b42016-01-08 13:21:51 +02003724 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
3725 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003726 type = "CEA";
Jani Nikulad9278b42016-01-08 13:21:51 +02003727 cea_mode = &edid_cea_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003728 clock1 = cea_mode->clock;
3729 clock2 = cea_mode_alternate_clock(cea_mode);
3730 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003731 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
3732 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003733 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02003734 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003735 clock1 = cea_mode->clock;
3736 clock2 = hdmi_mode_alternate_clock(cea_mode);
3737 } else {
3738 return;
3739 }
3740 }
3741
3742 /* pick whichever is closest */
3743 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
3744 clock = clock1;
3745 else
3746 clock = clock2;
3747
3748 if (mode->clock == clock)
3749 return;
3750
3751 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02003752 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003753 mode->clock = clock;
3754}
3755
Wu Fengguang76adaa342011-09-05 14:23:20 +08003756static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003757drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003758{
Ville Syrjälä85040722012-08-16 14:55:05 +00003759 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003760
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003761 if (len >= 6)
Ville Syrjälä85040722012-08-16 14:55:05 +00003762 connector->eld[5] |= (db[6] >> 7) << 1; /* Supports_AI */
Ville Syrjälä85040722012-08-16 14:55:05 +00003763 if (len >= 8) {
3764 connector->latency_present[0] = db[8] >> 7;
3765 connector->latency_present[1] = (db[8] >> 6) & 1;
3766 }
3767 if (len >= 9)
3768 connector->video_latency[0] = db[9];
3769 if (len >= 10)
3770 connector->audio_latency[0] = db[10];
3771 if (len >= 11)
3772 connector->video_latency[1] = db[11];
3773 if (len >= 12)
3774 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003775
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003776 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
3777 "video latency %d %d, "
3778 "audio latency %d %d\n",
3779 connector->latency_present[0],
3780 connector->latency_present[1],
3781 connector->video_latency[0],
3782 connector->video_latency[1],
3783 connector->audio_latency[0],
3784 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003785}
3786
3787static void
3788monitor_name(struct detailed_timing *t, void *data)
3789{
3790 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
3791 *(u8 **)data = t->data.other_data.data.str.str;
3792}
3793
Jim Bride59f7c0f2016-04-14 10:18:35 -07003794static int get_monitor_name(struct edid *edid, char name[13])
3795{
3796 char *edid_name = NULL;
3797 int mnl;
3798
3799 if (!edid || !name)
3800 return 0;
3801
3802 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
3803 for (mnl = 0; edid_name && mnl < 13; mnl++) {
3804 if (edid_name[mnl] == 0x0a)
3805 break;
3806
3807 name[mnl] = edid_name[mnl];
3808 }
3809
3810 return mnl;
3811}
3812
3813/**
3814 * drm_edid_get_monitor_name - fetch the monitor name from the edid
3815 * @edid: monitor EDID information
3816 * @name: pointer to a character array to hold the name of the monitor
3817 * @bufsize: The size of the name buffer (should be at least 14 chars.)
3818 *
3819 */
3820void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
3821{
3822 int name_length;
3823 char buf[13];
3824
3825 if (bufsize <= 0)
3826 return;
3827
3828 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
3829 memcpy(name, buf, name_length);
3830 name[name_length] = '\0';
3831}
3832EXPORT_SYMBOL(drm_edid_get_monitor_name);
3833
Wu Fengguang76adaa342011-09-05 14:23:20 +08003834/**
3835 * drm_edid_to_eld - build ELD from EDID
3836 * @connector: connector corresponding to the HDMI/DP sink
3837 * @edid: EDID to parse
3838 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003839 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
3840 * Conn_Type, HDCP and Port_ID ELD fields are left for the graphics driver to
3841 * fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003842 */
3843void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
3844{
3845 uint8_t *eld = connector->eld;
3846 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003847 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02003848 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003849 int mnl;
3850 int dbl;
3851
3852 memset(eld, 0, sizeof(connector->eld));
3853
Ville Syrjälä85c91582016-09-28 16:51:34 +03003854 connector->latency_present[0] = false;
3855 connector->latency_present[1] = false;
3856 connector->video_latency[0] = 0;
3857 connector->audio_latency[0] = 0;
3858 connector->video_latency[1] = 0;
3859 connector->audio_latency[1] = 0;
3860
Jani Nikulae9bd0b82017-02-17 17:20:52 +02003861 if (!edid)
3862 return;
3863
Wu Fengguang76adaa342011-09-05 14:23:20 +08003864 cea = drm_find_cea_extension(edid);
3865 if (!cea) {
3866 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3867 return;
3868 }
3869
Jim Bride59f7c0f2016-04-14 10:18:35 -07003870 mnl = get_monitor_name(edid, eld + 20);
3871
Wu Fengguang76adaa342011-09-05 14:23:20 +08003872 eld[4] = (cea[1] << 5) | mnl;
3873 DRM_DEBUG_KMS("ELD monitor %s\n", eld + 20);
3874
3875 eld[0] = 2 << 3; /* ELD version: 2 */
3876
3877 eld[16] = edid->mfg_id[0];
3878 eld[17] = edid->mfg_id[1];
3879 eld[18] = edid->prod_code[0];
3880 eld[19] = edid->prod_code[1];
3881
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003882 if (cea_revision(cea) >= 3) {
3883 int i, start, end;
3884
3885 if (cea_db_offsets(cea, &start, &end)) {
3886 start = 0;
3887 end = 0;
3888 }
3889
3890 for_each_cea_db(cea, i, start, end) {
3891 db = &cea[i];
3892 dbl = cea_db_payload_len(db);
3893
3894 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02003895 int sad_count;
3896
Christian Schmidta0ab7342011-12-19 20:03:38 +01003897 case AUDIO_BLOCK:
3898 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02003899 sad_count = min(dbl / 3, 15 - total_sad_count);
3900 if (sad_count >= 1)
3901 memcpy(eld + 20 + mnl + total_sad_count * 3,
3902 &db[1], sad_count * 3);
3903 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01003904 break;
3905 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003906 /* Speaker Allocation Data Block */
3907 if (dbl >= 1)
3908 eld[7] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01003909 break;
3910 case VENDOR_BLOCK:
3911 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003912 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003913 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01003914 break;
3915 default:
3916 break;
3917 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003918 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003919 }
Ville Syrjälä7c018782016-03-09 22:07:46 +02003920 eld[5] |= total_sad_count << 4;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003921
Jani Nikula938fd8a2014-10-28 16:20:48 +02003922 eld[DRM_ELD_BASELINE_ELD_LEN] =
3923 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
3924
3925 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02003926 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003927}
3928EXPORT_SYMBOL(drm_edid_to_eld);
3929
3930/**
Rafał Miłeckife214162013-04-19 19:01:25 +02003931 * drm_edid_to_sad - extracts SADs from EDID
3932 * @edid: EDID to parse
3933 * @sads: pointer that will be set to the extracted SADs
3934 *
3935 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02003936 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003937 * Note: The returned pointer needs to be freed using kfree().
3938 *
3939 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02003940 */
3941int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
3942{
3943 int count = 0;
3944 int i, start, end, dbl;
3945 u8 *cea;
3946
3947 cea = drm_find_cea_extension(edid);
3948 if (!cea) {
3949 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3950 return -ENOENT;
3951 }
3952
3953 if (cea_revision(cea) < 3) {
3954 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3955 return -ENOTSUPP;
3956 }
3957
3958 if (cea_db_offsets(cea, &start, &end)) {
3959 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3960 return -EPROTO;
3961 }
3962
3963 for_each_cea_db(cea, i, start, end) {
3964 u8 *db = &cea[i];
3965
3966 if (cea_db_tag(db) == AUDIO_BLOCK) {
3967 int j;
3968 dbl = cea_db_payload_len(db);
3969
3970 count = dbl / 3; /* SAD is 3B */
3971 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
3972 if (!*sads)
3973 return -ENOMEM;
3974 for (j = 0; j < count; j++) {
3975 u8 *sad = &db[1 + j * 3];
3976
3977 (*sads)[j].format = (sad[0] & 0x78) >> 3;
3978 (*sads)[j].channels = sad[0] & 0x7;
3979 (*sads)[j].freq = sad[1] & 0x7F;
3980 (*sads)[j].byte2 = sad[2];
3981 }
3982 break;
3983 }
3984 }
3985
3986 return count;
3987}
3988EXPORT_SYMBOL(drm_edid_to_sad);
3989
3990/**
Alex Deucherd105f472013-07-25 15:55:32 -04003991 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
3992 * @edid: EDID to parse
3993 * @sadb: pointer to the speaker block
3994 *
3995 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04003996 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003997 * Note: The returned pointer needs to be freed using kfree().
3998 *
3999 * Return: The number of found Speaker Allocation Blocks or negative number on
4000 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004001 */
4002int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4003{
4004 int count = 0;
4005 int i, start, end, dbl;
4006 const u8 *cea;
4007
4008 cea = drm_find_cea_extension(edid);
4009 if (!cea) {
4010 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4011 return -ENOENT;
4012 }
4013
4014 if (cea_revision(cea) < 3) {
4015 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
4016 return -ENOTSUPP;
4017 }
4018
4019 if (cea_db_offsets(cea, &start, &end)) {
4020 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4021 return -EPROTO;
4022 }
4023
4024 for_each_cea_db(cea, i, start, end) {
4025 const u8 *db = &cea[i];
4026
4027 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4028 dbl = cea_db_payload_len(db);
4029
4030 /* Speaker Allocation Data Block */
4031 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004032 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004033 if (!*sadb)
4034 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004035 count = dbl;
4036 break;
4037 }
4038 }
4039 }
4040
4041 return count;
4042}
4043EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4044
4045/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004046 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004047 * @connector: connector associated with the HDMI/DP sink
4048 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004049 *
4050 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4051 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004052 */
4053int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004054 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004055{
4056 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4057 int a, v;
4058
4059 if (!connector->latency_present[0])
4060 return 0;
4061 if (!connector->latency_present[1])
4062 i = 0;
4063
4064 a = connector->audio_latency[i];
4065 v = connector->video_latency[i];
4066
4067 /*
4068 * HDMI/DP sink doesn't support audio or video?
4069 */
4070 if (a == 255 || v == 255)
4071 return 0;
4072
4073 /*
4074 * Convert raw EDID values to millisecond.
4075 * Treat unknown latency as 0ms.
4076 */
4077 if (a)
4078 a = min(2 * (a - 1), 500);
4079 if (v)
4080 v = min(2 * (v - 1), 500);
4081
4082 return max(v - a, 0);
4083}
4084EXPORT_SYMBOL(drm_av_sync_delay);
4085
4086/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004087 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004088 * @edid: monitor EDID information
4089 *
4090 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004091 *
4092 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004093 */
4094bool drm_detect_hdmi_monitor(struct edid *edid)
4095{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004096 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004097 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004098 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004099
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004100 edid_ext = drm_find_cea_extension(edid);
4101 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004102 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004103
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004104 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004105 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004106
4107 /*
4108 * Because HDMI identifier is in Vendor Specific Block,
4109 * search it from all data blocks of CEA extension.
4110 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004111 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004112 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4113 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004114 }
4115
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004116 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004117}
4118EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4119
Dave Airlief453ba02008-11-07 14:05:41 -08004120/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004121 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004122 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004123 *
4124 * Monitor should have CEA extension block.
4125 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4126 * audio' only. If there is any audio extension block and supported
4127 * audio format, assume at least 'basic audio' support, even if 'basic
4128 * audio' is not defined in EDID.
4129 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004130 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004131 */
4132bool drm_detect_monitor_audio(struct edid *edid)
4133{
4134 u8 *edid_ext;
4135 int i, j;
4136 bool has_audio = false;
4137 int start_offset, end_offset;
4138
4139 edid_ext = drm_find_cea_extension(edid);
4140 if (!edid_ext)
4141 goto end;
4142
4143 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4144
4145 if (has_audio) {
4146 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4147 goto end;
4148 }
4149
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004150 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4151 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004152
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004153 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4154 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004155 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004156 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004157 DRM_DEBUG_KMS("CEA audio format %d\n",
4158 (edid_ext[i + j] >> 3) & 0xf);
4159 goto end;
4160 }
4161 }
4162end:
4163 return has_audio;
4164}
4165EXPORT_SYMBOL(drm_detect_monitor_audio);
4166
4167/**
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004168 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
Daniel Vetterfc668112014-01-21 12:02:26 +01004169 * @edid: EDID block to scan
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004170 *
4171 * Check whether the monitor reports the RGB quantization range selection
4172 * as supported. The AVI infoframe can then be used to inform the monitor
4173 * which quantization range (full or limited) is used.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004174 *
4175 * Return: True if the RGB quantization range is selectable, false otherwise.
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004176 */
4177bool drm_rgb_quant_range_selectable(struct edid *edid)
4178{
4179 u8 *edid_ext;
4180 int i, start, end;
4181
4182 edid_ext = drm_find_cea_extension(edid);
4183 if (!edid_ext)
4184 return false;
4185
4186 if (cea_db_offsets(edid_ext, &start, &end))
4187 return false;
4188
4189 for_each_cea_db(edid_ext, i, start, end) {
Shashank Sharma87563fc2017-07-13 21:03:10 +05304190 if (cea_db_tag(&edid_ext[i]) == USE_EXTENDED_TAG &&
4191 cea_db_payload_len(&edid_ext[i]) == 2 &&
4192 cea_db_extended_tag(&edid_ext[i]) ==
4193 EXT_VIDEO_CAPABILITY_BLOCK) {
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004194 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
4195 return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
4196 }
4197 }
4198
4199 return false;
4200}
4201EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
4202
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004203/**
4204 * drm_default_rgb_quant_range - default RGB quantization range
4205 * @mode: display mode
4206 *
4207 * Determine the default RGB quantization range for the mode,
4208 * as specified in CEA-861.
4209 *
4210 * Return: The default RGB quantization range for the mode
4211 */
4212enum hdmi_quantization_range
4213drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4214{
4215 /* All CEA modes other than VIC 1 use limited quantization range. */
4216 return drm_match_cea_mode(mode) > 1 ?
4217 HDMI_QUANTIZATION_RANGE_LIMITED :
4218 HDMI_QUANTIZATION_RANGE_FULL;
4219}
4220EXPORT_SYMBOL(drm_default_rgb_quant_range);
4221
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304222static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4223 const u8 *db)
4224{
4225 u8 dc_mask;
4226 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4227
4228 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
4229 hdmi->y420_dc_modes |= dc_mask;
4230}
4231
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304232static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4233 const u8 *hf_vsdb)
4234{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304235 struct drm_display_info *display = &connector->display_info;
4236 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304237
4238 if (hf_vsdb[6] & 0x80) {
4239 hdmi->scdc.supported = true;
4240 if (hf_vsdb[6] & 0x40)
4241 hdmi->scdc.read_request = true;
4242 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304243
4244 /*
4245 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4246 * And as per the spec, three factors confirm this:
4247 * * Availability of a HF-VSDB block in EDID (check)
4248 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4249 * * SCDC support available (let's check)
4250 * Lets check it out.
4251 */
4252
4253 if (hf_vsdb[5]) {
4254 /* max clock is 5000 KHz times block value */
4255 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4256 struct drm_scdc *scdc = &hdmi->scdc;
4257
4258 if (max_tmds_clock > 340000) {
4259 display->max_tmds_clock = max_tmds_clock;
4260 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4261 display->max_tmds_clock);
4262 }
4263
4264 if (scdc->supported) {
4265 scdc->scrambling.supported = true;
4266
4267 /* Few sinks support scrambling for cloks < 340M */
4268 if ((hf_vsdb[6] & 0x8))
4269 scdc->scrambling.low_rates = true;
4270 }
4271 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304272
4273 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304274}
4275
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004276static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4277 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01004278{
Ville Syrjälä18267502016-09-28 16:51:38 +03004279 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004280 unsigned int dc_bpc = 0;
4281
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004282 /* HDMI supports at least 8 bpc */
4283 info->bpc = 8;
4284
4285 if (cea_db_payload_len(hdmi) < 6)
4286 return;
4287
4288 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4289 dc_bpc = 10;
4290 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4291 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4292 connector->name);
4293 }
4294
4295 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4296 dc_bpc = 12;
4297 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4298 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4299 connector->name);
4300 }
4301
4302 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4303 dc_bpc = 16;
4304 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4305 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4306 connector->name);
4307 }
4308
4309 if (dc_bpc == 0) {
4310 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4311 connector->name);
4312 return;
4313 }
4314
4315 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4316 connector->name, dc_bpc);
4317 info->bpc = dc_bpc;
4318
4319 /*
4320 * Deep color support mandates RGB444 support for all video
4321 * modes and forbids YCRCB422 support for all video modes per
4322 * HDMI 1.3 spec.
4323 */
4324 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4325
4326 /* YCRCB444 is optional according to spec. */
4327 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4328 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4329 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4330 connector->name);
4331 }
4332
4333 /*
4334 * Spec says that if any deep color mode is supported at all,
4335 * then deep color 36 bit must be supported.
4336 */
4337 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4338 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4339 connector->name);
4340 }
4341}
4342
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004343static void
4344drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4345{
4346 struct drm_display_info *info = &connector->display_info;
4347 u8 len = cea_db_payload_len(db);
4348
4349 if (len >= 6)
4350 info->dvi_dual = db[6] & 1;
4351 if (len >= 7)
4352 info->max_tmds_clock = db[7] * 5000;
4353
4354 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4355 "max TMDS clock %d kHz\n",
4356 info->dvi_dual,
4357 info->max_tmds_clock);
4358
4359 drm_parse_hdmi_deep_color_info(connector, db);
4360}
4361
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004362static void drm_parse_cea_ext(struct drm_connector *connector,
4363 struct edid *edid)
4364{
4365 struct drm_display_info *info = &connector->display_info;
4366 const u8 *edid_ext;
4367 int i, start, end;
4368
Mario Kleinerd0c94692014-03-27 19:59:39 +01004369 edid_ext = drm_find_cea_extension(edid);
4370 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004371 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004372
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004373 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004374
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004375 /* The existence of a CEA block should imply RGB support */
4376 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4377 if (edid_ext[3] & EDID_CEA_YCRCB444)
4378 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4379 if (edid_ext[3] & EDID_CEA_YCRCB422)
4380 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004381
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004382 if (cea_db_offsets(edid_ext, &start, &end))
4383 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01004384
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004385 for_each_cea_db(edid_ext, i, start, end) {
4386 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01004387
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004388 if (cea_db_is_hdmi_vsdb(db))
4389 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304390 if (cea_db_is_hdmi_forum_vsdb(db))
4391 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304392 if (cea_db_is_y420cmdb(db))
4393 drm_parse_y420cmdb_bitmap(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004394 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01004395}
4396
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004397static void drm_add_display_info(struct drm_connector *connector,
Dave Airlie66660d42017-10-16 05:08:09 +01004398 struct edid *edid, u32 quirks)
Jesse Barnes3b112282011-04-15 12:49:23 -07004399{
Ville Syrjälä18267502016-09-28 16:51:38 +03004400 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07004401
Jesse Barnes3b112282011-04-15 12:49:23 -07004402 info->width_mm = edid->width_cm * 10;
4403 info->height_mm = edid->height_cm * 10;
4404
4405 /* driver figures it out in this case */
4406 info->bpc = 0;
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004407 info->color_formats = 0;
Ville Syrjälä011acce2016-09-28 16:51:40 +03004408 info->cea_rev = 0;
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004409 info->max_tmds_clock = 0;
4410 info->dvi_dual = false;
Jesse Barnes3b112282011-04-15 12:49:23 -07004411
Dave Airlie66660d42017-10-16 05:08:09 +01004412 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4413
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004414 if (edid->revision < 3)
Jesse Barnes3b112282011-04-15 12:49:23 -07004415 return;
4416
4417 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
4418 return;
4419
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004420 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004421
Mario Kleiner210a0212016-07-06 12:05:48 +02004422 /*
4423 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4424 *
4425 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4426 * tells us to assume 8 bpc color depth if the EDID doesn't have
4427 * extensions which tell otherwise.
4428 */
4429 if ((info->bpc == 0) && (edid->revision < 4) &&
4430 (edid->input & DRM_EDID_DIGITAL_TYPE_DVI)) {
4431 info->bpc = 8;
4432 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4433 connector->name, info->bpc);
4434 }
4435
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004436 /* Only defined for 1.4 with digital displays */
4437 if (edid->revision < 4)
4438 return;
4439
Jesse Barnes3b112282011-04-15 12:49:23 -07004440 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4441 case DRM_EDID_DIGITAL_DEPTH_6:
4442 info->bpc = 6;
4443 break;
4444 case DRM_EDID_DIGITAL_DEPTH_8:
4445 info->bpc = 8;
4446 break;
4447 case DRM_EDID_DIGITAL_DEPTH_10:
4448 info->bpc = 10;
4449 break;
4450 case DRM_EDID_DIGITAL_DEPTH_12:
4451 info->bpc = 12;
4452 break;
4453 case DRM_EDID_DIGITAL_DEPTH_14:
4454 info->bpc = 14;
4455 break;
4456 case DRM_EDID_DIGITAL_DEPTH_16:
4457 info->bpc = 16;
4458 break;
4459 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4460 default:
4461 info->bpc = 0;
4462 break;
4463 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004464
Mario Kleinerd0c94692014-03-27 19:59:39 +01004465 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004466 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004467
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004468 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004469 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4470 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4471 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4472 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Jesse Barnes3b112282011-04-15 12:49:23 -07004473}
4474
Dave Airliec97291772016-05-03 15:38:37 +10004475static int validate_displayid(u8 *displayid, int length, int idx)
4476{
4477 int i;
4478 u8 csum = 0;
4479 struct displayid_hdr *base;
4480
4481 base = (struct displayid_hdr *)&displayid[idx];
4482
4483 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4484 base->rev, base->bytes, base->prod_id, base->ext_count);
4485
4486 if (base->bytes + 5 > length - idx)
4487 return -EINVAL;
4488 for (i = idx; i <= base->bytes + 5; i++) {
4489 csum += displayid[i];
4490 }
4491 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004492 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004493 return -EINVAL;
4494 }
4495 return 0;
4496}
4497
Dave Airliea39ed682016-05-02 08:35:05 +10004498static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4499 struct displayid_detailed_timings_1 *timings)
4500{
4501 struct drm_display_mode *mode;
4502 unsigned pixel_clock = (timings->pixel_clock[0] |
4503 (timings->pixel_clock[1] << 8) |
4504 (timings->pixel_clock[2] << 16));
4505 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4506 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4507 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4508 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4509 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4510 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4511 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4512 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4513 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4514 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4515 mode = drm_mode_create(dev);
4516 if (!mode)
4517 return NULL;
4518
4519 mode->clock = pixel_clock * 10;
4520 mode->hdisplay = hactive;
4521 mode->hsync_start = mode->hdisplay + hsync;
4522 mode->hsync_end = mode->hsync_start + hsync_width;
4523 mode->htotal = mode->hdisplay + hblank;
4524
4525 mode->vdisplay = vactive;
4526 mode->vsync_start = mode->vdisplay + vsync;
4527 mode->vsync_end = mode->vsync_start + vsync_width;
4528 mode->vtotal = mode->vdisplay + vblank;
4529
4530 mode->flags = 0;
4531 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4532 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4533 mode->type = DRM_MODE_TYPE_DRIVER;
4534
4535 if (timings->flags & 0x80)
4536 mode->type |= DRM_MODE_TYPE_PREFERRED;
4537 mode->vrefresh = drm_mode_vrefresh(mode);
4538 drm_mode_set_name(mode);
4539
4540 return mode;
4541}
4542
4543static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4544 struct displayid_block *block)
4545{
4546 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4547 int i;
4548 int num_timings;
4549 struct drm_display_mode *newmode;
4550 int num_modes = 0;
4551 /* blocks must be multiple of 20 bytes length */
4552 if (block->num_bytes % 20)
4553 return 0;
4554
4555 num_timings = block->num_bytes / 20;
4556 for (i = 0; i < num_timings; i++) {
4557 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4558
4559 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4560 if (!newmode)
4561 continue;
4562
4563 drm_mode_probed_add(connector, newmode);
4564 num_modes++;
4565 }
4566 return num_modes;
4567}
4568
4569static int add_displayid_detailed_modes(struct drm_connector *connector,
4570 struct edid *edid)
4571{
4572 u8 *displayid;
4573 int ret;
4574 int idx = 1;
4575 int length = EDID_LENGTH;
4576 struct displayid_block *block;
4577 int num_modes = 0;
4578
4579 displayid = drm_find_displayid_extension(edid);
4580 if (!displayid)
4581 return 0;
4582
4583 ret = validate_displayid(displayid, length, idx);
4584 if (ret)
4585 return 0;
4586
4587 idx += sizeof(struct displayid_hdr);
4588 while (block = (struct displayid_block *)&displayid[idx],
4589 idx + sizeof(struct displayid_block) <= length &&
4590 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
4591 block->num_bytes > 0) {
4592 idx += block->num_bytes + sizeof(struct displayid_block);
4593 switch (block->tag) {
4594 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4595 num_modes += add_displayid_detailed_1_modes(connector, block);
4596 break;
4597 }
4598 }
4599 return num_modes;
4600}
4601
Jesse Barnes3b112282011-04-15 12:49:23 -07004602/**
Dave Airlief453ba02008-11-07 14:05:41 -08004603 * drm_add_edid_modes - add modes from EDID data, if available
4604 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004605 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004606 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004607 * Add the specified modes to the connector's mode list. Also fills out the
4608 * &drm_display_info structure in @connector with any information which can be
4609 * derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004610 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004611 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004612 */
4613int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4614{
4615 int num_modes = 0;
4616 u32 quirks;
4617
4618 if (edid == NULL) {
4619 return 0;
4620 }
Alex Deucher3c537882010-02-05 04:21:19 -05004621 if (!drm_edid_is_valid(edid)) {
Jordan Crousedcdb1672010-05-27 13:40:25 -06004622 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004623 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004624 return 0;
4625 }
4626
4627 quirks = edid_get_quirks(edid);
4628
Adam Jacksonc867df72010-03-29 21:43:21 +00004629 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304630 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4631 * To avoid multiple parsing of same block, lets parse that map
4632 * from sink info, before parsing CEA modes.
4633 */
Dave Airlie66660d42017-10-16 05:08:09 +01004634 drm_add_display_info(connector, edid, quirks);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05304635
4636 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00004637 * EDID spec says modes should be preferred in this order:
4638 * - preferred detailed mode
4639 * - other detailed modes from base block
4640 * - detailed modes from extension blocks
4641 * - CVT 3-byte code modes
4642 * - standard timing codes
4643 * - established timing codes
4644 * - modes inferred from GTF or CVT range information
4645 *
Adam Jackson13931572010-08-03 14:38:19 -04004646 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00004647 *
4648 * XXX order for additional mode types in extension blocks?
4649 */
Adam Jackson13931572010-08-03 14:38:19 -04004650 num_modes += add_detailed_modes(connector, edid, quirks);
4651 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00004652 num_modes += add_standard_modes(connector, edid);
4653 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004654 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03004655 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10004656 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03004657 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
4658 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08004659
4660 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
4661 edid_fixup_preferred(connector, quirks);
4662
Mario Kleinere10aec62016-07-06 12:05:44 +02004663 if (quirks & EDID_QUIRK_FORCE_6BPC)
4664 connector->display_info.bpc = 6;
4665
Rafał Miłecki49d45a312013-12-07 13:22:42 +01004666 if (quirks & EDID_QUIRK_FORCE_8BPC)
4667 connector->display_info.bpc = 8;
4668
Mario Kleinere345da82017-04-21 17:05:08 +02004669 if (quirks & EDID_QUIRK_FORCE_10BPC)
4670 connector->display_info.bpc = 10;
4671
Mario Kleinerbc5b9642014-05-23 21:40:55 +02004672 if (quirks & EDID_QUIRK_FORCE_12BPC)
4673 connector->display_info.bpc = 12;
4674
Dave Airlief453ba02008-11-07 14:05:41 -08004675 return num_modes;
4676}
4677EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004678
4679/**
4680 * drm_add_modes_noedid - add modes for the connectors without EDID
4681 * @connector: connector we're probing
4682 * @hdisplay: the horizontal display limit
4683 * @vdisplay: the vertical display limit
4684 *
4685 * Add the specified modes to the connector's mode list. Only when the
4686 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4687 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004688 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004689 */
4690int drm_add_modes_noedid(struct drm_connector *connector,
4691 int hdisplay, int vdisplay)
4692{
4693 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004694 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004695 struct drm_device *dev = connector->dev;
4696
Daniel Vetterfbb40b22015-08-10 11:55:37 +02004697 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004698 if (hdisplay < 0)
4699 hdisplay = 0;
4700 if (vdisplay < 0)
4701 vdisplay = 0;
4702
4703 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004704 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004705 if (hdisplay && vdisplay) {
4706 /*
4707 * Only when two are valid, they will be used to check
4708 * whether the mode should be added to the mode list of
4709 * the connector.
4710 */
4711 if (ptr->hdisplay > hdisplay ||
4712 ptr->vdisplay > vdisplay)
4713 continue;
4714 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05004715 if (drm_mode_vrefresh(ptr) > 61)
4716 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004717 mode = drm_mode_duplicate(dev, ptr);
4718 if (mode) {
4719 drm_mode_probed_add(connector, mode);
4720 num_modes++;
4721 }
4722 }
4723 return num_modes;
4724}
4725EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01004726
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004727/**
4728 * drm_set_preferred_mode - Sets the preferred mode of a connector
4729 * @connector: connector whose mode list should be processed
4730 * @hpref: horizontal resolution of preferred mode
4731 * @vpref: vertical resolution of preferred mode
4732 *
4733 * Marks a mode as preferred if it matches the resolution specified by @hpref
4734 * and @vpref.
4735 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004736void drm_set_preferred_mode(struct drm_connector *connector,
4737 int hpref, int vpref)
4738{
4739 struct drm_display_mode *mode;
4740
4741 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004742 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01004743 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004744 mode->type |= DRM_MODE_TYPE_PREFERRED;
4745 }
4746}
4747EXPORT_SYMBOL(drm_set_preferred_mode);
4748
Thierry Reding10a85122012-11-21 15:31:35 +01004749/**
4750 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
4751 * data from a DRM display mode
4752 * @frame: HDMI AVI infoframe
4753 * @mode: DRM display mode
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304754 * @is_hdmi2_sink: Sink is HDMI 2.0 compliant
Thierry Reding10a85122012-11-21 15:31:35 +01004755 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004756 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01004757 */
4758int
4759drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304760 const struct drm_display_mode *mode,
4761 bool is_hdmi2_sink)
Thierry Reding10a85122012-11-21 15:31:35 +01004762{
4763 int err;
4764
4765 if (!frame || !mode)
4766 return -EINVAL;
4767
4768 err = hdmi_avi_infoframe_init(frame);
4769 if (err < 0)
4770 return err;
4771
Damien Lespiaubf02db92013-08-06 20:32:22 +01004772 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
4773 frame->pixel_repeat = 1;
4774
Thierry Reding10a85122012-11-21 15:31:35 +01004775 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01004776
Shashank Sharma0c1f5282017-07-13 21:03:07 +05304777 /*
4778 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
4779 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
4780 * have to make sure we dont break HDMI 1.4 sinks.
4781 */
4782 if (!is_hdmi2_sink && frame->video_code > 64)
4783 frame->video_code = 0;
4784
4785 /*
4786 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
4787 * we should send its VIC in vendor infoframes, else send the
4788 * VIC in AVI infoframes. Lets check if this mode is present in
4789 * HDMI 1.4b 4K modes
4790 */
4791 if (frame->video_code) {
4792 u8 vendor_if_vic = drm_match_hdmi_mode(mode);
4793 bool is_s3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
4794
4795 if (drm_valid_hdmi_vic(vendor_if_vic) && !is_s3d)
4796 frame->video_code = 0;
4797 }
4798
Thierry Reding10a85122012-11-21 15:31:35 +01004799 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304800
Vandana Kannan69ab6d32014-06-05 14:45:29 +05304801 /*
4802 * Populate picture aspect ratio from either
4803 * user input (if specified) or from the CEA mode list.
4804 */
4805 if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
4806 mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
4807 frame->picture_aspect = mode->picture_aspect_ratio;
4808 else if (frame->video_code > 0)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304809 frame->picture_aspect = drm_get_cea_aspect_ratio(
4810 frame->video_code);
4811
Thierry Reding10a85122012-11-21 15:31:35 +01004812 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06004813 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01004814
4815 return 0;
4816}
4817EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004818
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004819/**
4820 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
4821 * quantization range information
4822 * @frame: HDMI AVI infoframe
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004823 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004824 * @rgb_quant_range: RGB quantization range (Q)
4825 * @rgb_quant_range_selectable: Sink support selectable RGB quantization range (QS)
4826 */
4827void
4828drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004829 const struct drm_display_mode *mode,
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004830 enum hdmi_quantization_range rgb_quant_range,
4831 bool rgb_quant_range_selectable)
4832{
4833 /*
4834 * CEA-861:
4835 * "A Source shall not send a non-zero Q value that does not correspond
4836 * to the default RGB Quantization Range for the transmitted Picture
4837 * unless the Sink indicates support for the Q bit in a Video
4838 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004839 *
4840 * HDMI 2.0 recommends sending non-zero Q when it does match the
4841 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004842 */
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004843 if (rgb_quant_range_selectable ||
4844 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004845 frame->quantization_range = rgb_quant_range;
4846 else
4847 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004848
4849 /*
4850 * CEA-861-F:
4851 * "When transmitting any RGB colorimetry, the Source should set the
4852 * YQ-field to match the RGB Quantization Range being transmitted
4853 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
4854 * set YQ=1) and the Sink shall ignore the YQ-field."
4855 */
4856 if (rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
4857 frame->ycc_quantization_range =
4858 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
4859 else
4860 frame->ycc_quantization_range =
4861 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004862}
4863EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
4864
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004865static enum hdmi_3d_structure
4866s3d_structure_from_display_mode(const struct drm_display_mode *mode)
4867{
4868 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
4869
4870 switch (layout) {
4871 case DRM_MODE_FLAG_3D_FRAME_PACKING:
4872 return HDMI_3D_STRUCTURE_FRAME_PACKING;
4873 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
4874 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
4875 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
4876 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
4877 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
4878 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
4879 case DRM_MODE_FLAG_3D_L_DEPTH:
4880 return HDMI_3D_STRUCTURE_L_DEPTH;
4881 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
4882 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
4883 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
4884 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
4885 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
4886 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
4887 default:
4888 return HDMI_3D_STRUCTURE_INVALID;
4889 }
4890}
4891
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004892/**
4893 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
4894 * data from a DRM display mode
4895 * @frame: HDMI vendor infoframe
4896 * @mode: DRM display mode
4897 *
4898 * Note that there's is a need to send HDMI vendor infoframes only when using a
4899 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
4900 * function will return -EINVAL, error that can be safely ignored.
4901 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004902 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004903 */
4904int
4905drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
4906 const struct drm_display_mode *mode)
4907{
4908 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004909 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004910 u8 vic;
4911
4912 if (!frame || !mode)
4913 return -EINVAL;
4914
4915 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004916 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
4917
4918 if (!vic && !s3d_flags)
4919 return -EINVAL;
4920
4921 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004922 return -EINVAL;
4923
4924 err = hdmi_vendor_infoframe_init(frame);
4925 if (err < 0)
4926 return err;
4927
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004928 if (vic)
4929 frame->vic = vic;
4930 else
4931 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004932
4933 return 0;
4934}
4935EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10004936
Dave Airlie5e546cd2016-05-03 15:31:12 +10004937static int drm_parse_tiled_block(struct drm_connector *connector,
4938 struct displayid_block *block)
4939{
4940 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
4941 u16 w, h;
4942 u8 tile_v_loc, tile_h_loc;
4943 u8 num_v_tile, num_h_tile;
4944 struct drm_tile_group *tg;
4945
4946 w = tile->tile_size[0] | tile->tile_size[1] << 8;
4947 h = tile->tile_size[2] | tile->tile_size[3] << 8;
4948
4949 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
4950 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
4951 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
4952 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
4953
4954 connector->has_tile = true;
4955 if (tile->tile_cap & 0x80)
4956 connector->tile_is_single_monitor = true;
4957
4958 connector->num_h_tile = num_h_tile + 1;
4959 connector->num_v_tile = num_v_tile + 1;
4960 connector->tile_h_loc = tile_h_loc;
4961 connector->tile_v_loc = tile_v_loc;
4962 connector->tile_h_size = w + 1;
4963 connector->tile_v_size = h + 1;
4964
4965 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
4966 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
4967 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
4968 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
4969 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
4970
4971 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
4972 if (!tg) {
4973 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
4974 }
4975 if (!tg)
4976 return -ENOMEM;
4977
4978 if (connector->tile_group != tg) {
4979 /* if we haven't got a pointer,
4980 take the reference, drop ref to old tile group */
4981 if (connector->tile_group) {
4982 drm_mode_put_tile_group(connector->dev, connector->tile_group);
4983 }
4984 connector->tile_group = tg;
4985 } else
4986 /* if same tile group, then release the ref we just took. */
4987 drm_mode_put_tile_group(connector->dev, tg);
4988 return 0;
4989}
4990
Dave Airlie40d9b042014-10-20 16:29:33 +10004991static int drm_parse_display_id(struct drm_connector *connector,
4992 u8 *displayid, int length,
4993 bool is_edid_extension)
4994{
4995 /* if this is an EDID extension the first byte will be 0x70 */
4996 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10004997 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10004998 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10004999
5000 if (is_edid_extension)
5001 idx = 1;
5002
Dave Airliec97291772016-05-03 15:38:37 +10005003 ret = validate_displayid(displayid, length, idx);
5004 if (ret)
5005 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10005006
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005007 idx += sizeof(struct displayid_hdr);
5008 while (block = (struct displayid_block *)&displayid[idx],
5009 idx + sizeof(struct displayid_block) <= length &&
5010 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
5011 block->num_bytes > 0) {
5012 idx += block->num_bytes + sizeof(struct displayid_block);
5013 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5014 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10005015
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005016 switch (block->tag) {
5017 case DATA_BLOCK_TILED_DISPLAY:
5018 ret = drm_parse_tiled_block(connector, block);
5019 if (ret)
5020 return ret;
5021 break;
Dave Airliea39ed682016-05-02 08:35:05 +10005022 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5023 /* handled in mode gathering code. */
5024 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02005025 default:
5026 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5027 break;
5028 }
Dave Airlie40d9b042014-10-20 16:29:33 +10005029 }
5030 return 0;
5031}
5032
5033static void drm_get_displayid(struct drm_connector *connector,
5034 struct edid *edid)
5035{
5036 void *displayid = NULL;
5037 int ret;
5038 connector->has_tile = false;
5039 displayid = drm_find_displayid_extension(edid);
5040 if (!displayid) {
5041 /* drop reference to any tile group we had */
5042 goto out_drop_ref;
5043 }
5044
5045 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5046 if (ret < 0)
5047 goto out_drop_ref;
5048 if (!connector->has_tile)
5049 goto out_drop_ref;
5050 return;
5051out_drop_ref:
5052 if (connector->tile_group) {
5053 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5054 connector->tile_group = NULL;
5055 }
5056 return;
5057}