blob: 99144f879a4f26fc39fbbad3d76f09234726a82e [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)
Alex Deucher3c537882010-02-05 04:21:19 -050083
Adam Jackson13931572010-08-03 14:38:19 -040084struct detailed_mode_closure {
85 struct drm_connector *connector;
86 struct edid *edid;
87 bool preferred;
88 u32 quirks;
89 int modes;
90};
Dave Airlief453ba02008-11-07 14:05:41 -080091
Zhao Yakui5c612592009-06-22 13:17:10 +080092#define LEVEL_DMT 0
93#define LEVEL_GTF 1
Adam Jackson7a374352010-03-29 21:43:30 +000094#define LEVEL_GTF2 2
95#define LEVEL_CVT 3
Zhao Yakui5c612592009-06-22 13:17:10 +080096
Jani Nikula23c4cfb2016-12-28 13:06:26 +020097static const struct edid_quirk {
Ian Pilcherc51a3fd62012-04-22 11:40:26 -050098 char vendor[4];
Dave Airlief453ba02008-11-07 14:05:41 -080099 int product_id;
100 u32 quirks;
101} edid_quirk_list[] = {
102 /* Acer AL1706 */
103 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
104 /* Acer F51 */
105 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
106 /* Unknown Acer */
107 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
108
Mario Kleinere10aec62016-07-06 12:05:44 +0200109 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
110 { "AEO", 0, EDID_QUIRK_FORCE_6BPC },
111
Dave Airlief453ba02008-11-07 14:05:41 -0800112 /* Belinea 10 15 55 */
113 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
114 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
115
116 /* Envision Peripherals, Inc. EN-7100e */
117 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
Adam Jacksonba1163d2010-04-06 16:11:00 +0000118 /* Envision EN2028 */
119 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
Dave Airlief453ba02008-11-07 14:05:41 -0800120
121 /* Funai Electronics PM36B */
122 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
123 EDID_QUIRK_DETAILED_IN_CM },
124
125 /* LG Philips LCD LP154W01-A5 */
126 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
127 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
128
129 /* Philips 107p5 CRT */
130 { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
131
132 /* Proview AY765C */
133 { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
134
135 /* Samsung SyncMaster 205BW. Note: irony */
136 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
137 /* Samsung SyncMaster 22[5-6]BW */
138 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
139 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400140
Mario Kleinerbc5b9642014-05-23 21:40:55 +0200141 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
142 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
143
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400144 /* ViewSonic VA2026w */
145 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
Alex Deucher118bdbd2013-08-12 11:04:29 -0400146
147 /* Medion MD 30217 PG */
148 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100149
150 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
151 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
Dave Airlief453ba02008-11-07 14:05:41 -0800152};
153
Thierry Redinga6b21832012-11-23 15:01:42 +0100154/*
155 * Autogenerated from the DMT spec.
156 * This table is copied from xfree86/modes/xf86EdidModes.c.
157 */
158static const struct drm_display_mode drm_dmt_modes[] = {
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300159 /* 0x01 - 640x350@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100160 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
161 736, 832, 0, 350, 382, 385, 445, 0,
162 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300163 /* 0x02 - 640x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100164 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
165 736, 832, 0, 400, 401, 404, 445, 0,
166 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300167 /* 0x03 - 720x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100168 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
169 828, 936, 0, 400, 401, 404, 446, 0,
170 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300171 /* 0x04 - 640x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100172 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300173 752, 800, 0, 480, 490, 492, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100174 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300175 /* 0x05 - 640x480@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100176 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
177 704, 832, 0, 480, 489, 492, 520, 0,
178 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300179 /* 0x06 - 640x480@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100180 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
181 720, 840, 0, 480, 481, 484, 500, 0,
182 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300183 /* 0x07 - 640x480@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100184 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
185 752, 832, 0, 480, 481, 484, 509, 0,
186 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300187 /* 0x08 - 800x600@56Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100188 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
189 896, 1024, 0, 600, 601, 603, 625, 0,
190 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300191 /* 0x09 - 800x600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100192 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
193 968, 1056, 0, 600, 601, 605, 628, 0,
194 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300195 /* 0x0a - 800x600@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100196 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
197 976, 1040, 0, 600, 637, 643, 666, 0,
198 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300199 /* 0x0b - 800x600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100200 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
201 896, 1056, 0, 600, 601, 604, 625, 0,
202 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300203 /* 0x0c - 800x600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100204 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
205 896, 1048, 0, 600, 601, 604, 631, 0,
206 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300207 /* 0x0d - 800x600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100208 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
209 880, 960, 0, 600, 603, 607, 636, 0,
210 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300211 /* 0x0e - 848x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100212 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
213 976, 1088, 0, 480, 486, 494, 517, 0,
214 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300215 /* 0x0f - 1024x768@43Hz, interlace */
Thierry Redinga6b21832012-11-23 15:01:42 +0100216 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
Paul Parsons735b1002016-04-04 20:36:34 +0100217 1208, 1264, 0, 768, 768, 776, 817, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100218 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300219 DRM_MODE_FLAG_INTERLACE) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300220 /* 0x10 - 1024x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100221 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
222 1184, 1344, 0, 768, 771, 777, 806, 0,
223 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300224 /* 0x11 - 1024x768@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100225 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
226 1184, 1328, 0, 768, 771, 777, 806, 0,
227 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300228 /* 0x12 - 1024x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100229 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
230 1136, 1312, 0, 768, 769, 772, 800, 0,
231 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300232 /* 0x13 - 1024x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100233 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
234 1168, 1376, 0, 768, 769, 772, 808, 0,
235 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300236 /* 0x14 - 1024x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100237 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
238 1104, 1184, 0, 768, 771, 775, 813, 0,
239 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300240 /* 0x15 - 1152x864@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100241 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
242 1344, 1600, 0, 864, 865, 868, 900, 0,
243 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300244 /* 0x55 - 1280x720@60Hz */
245 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
246 1430, 1650, 0, 720, 725, 730, 750, 0,
247 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300248 /* 0x16 - 1280x768@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100249 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
250 1360, 1440, 0, 768, 771, 778, 790, 0,
251 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300252 /* 0x17 - 1280x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100253 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
254 1472, 1664, 0, 768, 771, 778, 798, 0,
255 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300256 /* 0x18 - 1280x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100257 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
258 1488, 1696, 0, 768, 771, 778, 805, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300259 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300260 /* 0x19 - 1280x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100261 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
262 1496, 1712, 0, 768, 771, 778, 809, 0,
263 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300264 /* 0x1a - 1280x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100265 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
266 1360, 1440, 0, 768, 771, 778, 813, 0,
267 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300268 /* 0x1b - 1280x800@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100269 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
270 1360, 1440, 0, 800, 803, 809, 823, 0,
271 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300272 /* 0x1c - 1280x800@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100273 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
274 1480, 1680, 0, 800, 803, 809, 831, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300275 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300276 /* 0x1d - 1280x800@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100277 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
278 1488, 1696, 0, 800, 803, 809, 838, 0,
279 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300280 /* 0x1e - 1280x800@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100281 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
282 1496, 1712, 0, 800, 803, 809, 843, 0,
283 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300284 /* 0x1f - 1280x800@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100285 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
286 1360, 1440, 0, 800, 803, 809, 847, 0,
287 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300288 /* 0x20 - 1280x960@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100289 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
290 1488, 1800, 0, 960, 961, 964, 1000, 0,
291 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300292 /* 0x21 - 1280x960@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100293 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
294 1504, 1728, 0, 960, 961, 964, 1011, 0,
295 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300296 /* 0x22 - 1280x960@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100297 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
298 1360, 1440, 0, 960, 963, 967, 1017, 0,
299 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300300 /* 0x23 - 1280x1024@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100301 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
302 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
303 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300304 /* 0x24 - 1280x1024@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100305 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
306 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
307 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300308 /* 0x25 - 1280x1024@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100309 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
310 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
311 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300312 /* 0x26 - 1280x1024@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100313 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
314 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
315 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300316 /* 0x27 - 1360x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100317 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
318 1536, 1792, 0, 768, 771, 777, 795, 0,
319 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300320 /* 0x28 - 1360x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100321 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
322 1440, 1520, 0, 768, 771, 776, 813, 0,
323 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300324 /* 0x51 - 1366x768@60Hz */
325 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
326 1579, 1792, 0, 768, 771, 774, 798, 0,
327 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
328 /* 0x56 - 1366x768@60Hz */
329 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
330 1436, 1500, 0, 768, 769, 772, 800, 0,
331 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300332 /* 0x29 - 1400x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100333 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
334 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
335 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300336 /* 0x2a - 1400x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100337 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
338 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
339 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300340 /* 0x2b - 1400x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100341 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
342 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
343 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300344 /* 0x2c - 1400x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100345 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
346 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
347 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300348 /* 0x2d - 1400x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100349 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
350 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
351 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300352 /* 0x2e - 1440x900@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100353 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
354 1520, 1600, 0, 900, 903, 909, 926, 0,
355 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300356 /* 0x2f - 1440x900@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100357 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
358 1672, 1904, 0, 900, 903, 909, 934, 0,
359 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300360 /* 0x30 - 1440x900@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100361 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
362 1688, 1936, 0, 900, 903, 909, 942, 0,
363 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300364 /* 0x31 - 1440x900@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100365 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
366 1696, 1952, 0, 900, 903, 909, 948, 0,
367 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300368 /* 0x32 - 1440x900@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100369 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
370 1520, 1600, 0, 900, 903, 909, 953, 0,
371 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300372 /* 0x53 - 1600x900@60Hz */
373 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
374 1704, 1800, 0, 900, 901, 904, 1000, 0,
375 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300376 /* 0x33 - 1600x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100377 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
378 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
379 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300380 /* 0x34 - 1600x1200@65Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100381 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
382 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
383 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300384 /* 0x35 - 1600x1200@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100385 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
386 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
387 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300388 /* 0x36 - 1600x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100389 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
390 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
391 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300392 /* 0x37 - 1600x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100393 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
394 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
395 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300396 /* 0x38 - 1600x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100397 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
398 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
399 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300400 /* 0x39 - 1680x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100401 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
402 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
403 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300404 /* 0x3a - 1680x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100405 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
406 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
407 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300408 /* 0x3b - 1680x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100409 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
410 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
411 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300412 /* 0x3c - 1680x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100413 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
414 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
415 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300416 /* 0x3d - 1680x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100417 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
418 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
419 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300420 /* 0x3e - 1792x1344@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100421 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
422 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
423 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300424 /* 0x3f - 1792x1344@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100425 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
426 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
427 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300428 /* 0x40 - 1792x1344@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100429 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
430 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
431 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300432 /* 0x41 - 1856x1392@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100433 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
434 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
435 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300436 /* 0x42 - 1856x1392@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100437 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300438 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100439 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300440 /* 0x43 - 1856x1392@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100441 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
442 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
443 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300444 /* 0x52 - 1920x1080@60Hz */
445 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
446 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
447 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300448 /* 0x44 - 1920x1200@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100449 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
450 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
451 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300452 /* 0x45 - 1920x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100453 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
454 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
455 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300456 /* 0x46 - 1920x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100457 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
458 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
459 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300460 /* 0x47 - 1920x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100461 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
462 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
463 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300464 /* 0x48 - 1920x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100465 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
466 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
467 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300468 /* 0x49 - 1920x1440@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100469 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
470 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
471 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300472 /* 0x4a - 1920x1440@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100473 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
474 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
475 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300476 /* 0x4b - 1920x1440@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100477 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
478 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
479 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300480 /* 0x54 - 2048x1152@60Hz */
481 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
482 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
483 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300484 /* 0x4c - 2560x1600@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100485 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
486 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
487 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300488 /* 0x4d - 2560x1600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100489 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
490 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
491 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300492 /* 0x4e - 2560x1600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100493 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
494 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
495 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300496 /* 0x4f - 2560x1600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100497 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
498 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
499 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300500 /* 0x50 - 2560x1600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100501 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
502 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
503 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300504 /* 0x57 - 4096x2160@60Hz RB */
505 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
506 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
507 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
508 /* 0x58 - 4096x2160@59.94Hz RB */
509 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
510 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
511 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Thierry Redinga6b21832012-11-23 15:01:42 +0100512};
513
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300514/*
515 * These more or less come from the DMT spec. The 720x400 modes are
516 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
517 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
518 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
519 * mode.
520 *
521 * The DMT modes have been fact-checked; the rest are mild guesses.
522 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100523static const struct drm_display_mode edid_est_modes[] = {
524 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
525 968, 1056, 0, 600, 601, 605, 628, 0,
526 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
527 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
528 896, 1024, 0, 600, 601, 603, 625, 0,
529 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
530 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
531 720, 840, 0, 480, 481, 484, 500, 0,
532 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
533 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
Paul Parsons87707cf2016-04-02 11:08:06 +0100534 704, 832, 0, 480, 489, 492, 520, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100535 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
536 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
537 768, 864, 0, 480, 483, 486, 525, 0,
538 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100539 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Thierry Redinga6b21832012-11-23 15:01:42 +0100540 752, 800, 0, 480, 490, 492, 525, 0,
541 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
542 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
543 846, 900, 0, 400, 421, 423, 449, 0,
544 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
545 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
546 846, 900, 0, 400, 412, 414, 449, 0,
547 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
548 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
549 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
550 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100551 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
Thierry Redinga6b21832012-11-23 15:01:42 +0100552 1136, 1312, 0, 768, 769, 772, 800, 0,
553 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
554 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
555 1184, 1328, 0, 768, 771, 777, 806, 0,
556 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
557 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
558 1184, 1344, 0, 768, 771, 777, 806, 0,
559 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
560 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
561 1208, 1264, 0, 768, 768, 776, 817, 0,
562 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
563 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
564 928, 1152, 0, 624, 625, 628, 667, 0,
565 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
566 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
567 896, 1056, 0, 600, 601, 604, 625, 0,
568 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
569 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
570 976, 1040, 0, 600, 637, 643, 666, 0,
571 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
572 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
573 1344, 1600, 0, 864, 865, 868, 900, 0,
574 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
575};
576
577struct minimode {
578 short w;
579 short h;
580 short r;
581 short rb;
582};
583
584static const struct minimode est3_modes[] = {
585 /* byte 6 */
586 { 640, 350, 85, 0 },
587 { 640, 400, 85, 0 },
588 { 720, 400, 85, 0 },
589 { 640, 480, 85, 0 },
590 { 848, 480, 60, 0 },
591 { 800, 600, 85, 0 },
592 { 1024, 768, 85, 0 },
593 { 1152, 864, 75, 0 },
594 /* byte 7 */
595 { 1280, 768, 60, 1 },
596 { 1280, 768, 60, 0 },
597 { 1280, 768, 75, 0 },
598 { 1280, 768, 85, 0 },
599 { 1280, 960, 60, 0 },
600 { 1280, 960, 85, 0 },
601 { 1280, 1024, 60, 0 },
602 { 1280, 1024, 85, 0 },
603 /* byte 8 */
604 { 1360, 768, 60, 0 },
605 { 1440, 900, 60, 1 },
606 { 1440, 900, 60, 0 },
607 { 1440, 900, 75, 0 },
608 { 1440, 900, 85, 0 },
609 { 1400, 1050, 60, 1 },
610 { 1400, 1050, 60, 0 },
611 { 1400, 1050, 75, 0 },
612 /* byte 9 */
613 { 1400, 1050, 85, 0 },
614 { 1680, 1050, 60, 1 },
615 { 1680, 1050, 60, 0 },
616 { 1680, 1050, 75, 0 },
617 { 1680, 1050, 85, 0 },
618 { 1600, 1200, 60, 0 },
619 { 1600, 1200, 65, 0 },
620 { 1600, 1200, 70, 0 },
621 /* byte 10 */
622 { 1600, 1200, 75, 0 },
623 { 1600, 1200, 85, 0 },
624 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300625 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100626 { 1856, 1392, 60, 0 },
627 { 1856, 1392, 75, 0 },
628 { 1920, 1200, 60, 1 },
629 { 1920, 1200, 60, 0 },
630 /* byte 11 */
631 { 1920, 1200, 75, 0 },
632 { 1920, 1200, 85, 0 },
633 { 1920, 1440, 60, 0 },
634 { 1920, 1440, 75, 0 },
635};
636
637static const struct minimode extra_modes[] = {
638 { 1024, 576, 60, 0 },
639 { 1366, 768, 60, 0 },
640 { 1600, 900, 60, 0 },
641 { 1680, 945, 60, 0 },
642 { 1920, 1080, 60, 0 },
643 { 2048, 1152, 60, 0 },
644 { 2048, 1536, 60, 0 },
645};
646
647/*
648 * Probably taken from CEA-861 spec.
649 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
Jani Nikulad9278b42016-01-08 13:21:51 +0200650 *
651 * Index using the VIC.
Thierry Redinga6b21832012-11-23 15:01:42 +0100652 */
653static const struct drm_display_mode edid_cea_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +0200654 /* 0 - dummy, VICs start at 1 */
655 { },
Thierry Redinga6b21832012-11-23 15:01:42 +0100656 /* 1 - 640x480@60Hz */
657 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
658 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300659 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530660 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100661 /* 2 - 720x480@60Hz */
662 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
663 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300664 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530665 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100666 /* 3 - 720x480@60Hz */
667 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
668 798, 858, 0, 480, 489, 495, 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_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100671 /* 4 - 1280x720@60Hz */
672 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
673 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300674 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530675 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100676 /* 5 - 1920x1080i@60Hz */
677 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
678 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
679 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300680 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530681 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700682 /* 6 - 720(1440)x480i@60Hz */
683 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
684 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100685 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300686 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530687 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700688 /* 7 - 720(1440)x480i@60Hz */
689 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
690 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100691 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300692 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530693 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700694 /* 8 - 720(1440)x240@60Hz */
695 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
696 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100697 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300698 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530699 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700700 /* 9 - 720(1440)x240@60Hz */
701 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
702 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100703 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300704 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530705 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100706 /* 10 - 2880x480i@60Hz */
707 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
708 3204, 3432, 0, 480, 488, 494, 525, 0,
709 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300710 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530711 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100712 /* 11 - 2880x480i@60Hz */
713 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
714 3204, 3432, 0, 480, 488, 494, 525, 0,
715 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300716 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530717 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100718 /* 12 - 2880x240@60Hz */
719 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
720 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300721 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530722 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100723 /* 13 - 2880x240@60Hz */
724 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
725 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300726 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530727 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100728 /* 14 - 1440x480@60Hz */
729 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
730 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300731 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530732 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100733 /* 15 - 1440x480@60Hz */
734 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
735 1596, 1716, 0, 480, 489, 495, 525, 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 /* 16 - 1920x1080@60Hz */
739 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
740 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300741 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530742 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100743 /* 17 - 720x576@50Hz */
744 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
745 796, 864, 0, 576, 581, 586, 625, 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 = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100748 /* 18 - 720x576@50Hz */
749 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
750 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300751 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530752 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100753 /* 19 - 1280x720@50Hz */
754 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
755 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300756 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530757 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100758 /* 20 - 1920x1080i@50Hz */
759 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
760 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
761 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300762 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530763 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700764 /* 21 - 720(1440)x576i@50Hz */
765 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
766 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100767 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300768 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530769 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700770 /* 22 - 720(1440)x576i@50Hz */
771 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
772 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100773 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300774 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530775 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700776 /* 23 - 720(1440)x288@50Hz */
777 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
778 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100779 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300780 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530781 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700782 /* 24 - 720(1440)x288@50Hz */
783 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
784 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100785 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300786 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530787 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100788 /* 25 - 2880x576i@50Hz */
789 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
790 3180, 3456, 0, 576, 580, 586, 625, 0,
791 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300792 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530793 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100794 /* 26 - 2880x576i@50Hz */
795 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
796 3180, 3456, 0, 576, 580, 586, 625, 0,
797 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300798 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530799 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100800 /* 27 - 2880x288@50Hz */
801 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
802 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300803 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530804 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100805 /* 28 - 2880x288@50Hz */
806 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
807 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300808 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530809 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100810 /* 29 - 1440x576@50Hz */
811 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
812 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300813 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530814 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100815 /* 30 - 1440x576@50Hz */
816 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
817 1592, 1728, 0, 576, 581, 586, 625, 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 /* 31 - 1920x1080@50Hz */
821 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
822 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300823 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530824 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100825 /* 32 - 1920x1080@24Hz */
826 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
827 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300828 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530829 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100830 /* 33 - 1920x1080@25Hz */
831 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 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 = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100835 /* 34 - 1920x1080@30Hz */
836 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
837 2052, 2200, 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 = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100840 /* 35 - 2880x480@60Hz */
841 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
842 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300843 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530844 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100845 /* 36 - 2880x480@60Hz */
846 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
847 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300848 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530849 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100850 /* 37 - 2880x576@50Hz */
851 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
852 3184, 3456, 0, 576, 581, 586, 625, 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 = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100855 /* 38 - 2880x576@50Hz */
856 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
857 3184, 3456, 0, 576, 581, 586, 625, 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 = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100860 /* 39 - 1920x1080i@50Hz */
861 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
862 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
863 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300864 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530865 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100866 /* 40 - 1920x1080i@100Hz */
867 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
868 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
869 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300870 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530871 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100872 /* 41 - 1280x720@100Hz */
873 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
874 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300875 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530876 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100877 /* 42 - 720x576@100Hz */
878 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
879 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300880 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530881 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100882 /* 43 - 720x576@100Hz */
883 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
884 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300885 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530886 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700887 /* 44 - 720(1440)x576i@100Hz */
888 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
889 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100890 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700891 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530892 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700893 /* 45 - 720(1440)x576i@100Hz */
894 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
895 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100896 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700897 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530898 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100899 /* 46 - 1920x1080i@120Hz */
900 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
901 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
902 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300903 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530904 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100905 /* 47 - 1280x720@120Hz */
906 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
907 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300908 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530909 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100910 /* 48 - 720x480@120Hz */
911 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
912 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300913 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530914 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100915 /* 49 - 720x480@120Hz */
916 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
917 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300918 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530919 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700920 /* 50 - 720(1440)x480i@120Hz */
921 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
922 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100923 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300924 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530925 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700926 /* 51 - 720(1440)x480i@120Hz */
927 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
928 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100929 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300930 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530931 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100932 /* 52 - 720x576@200Hz */
933 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
934 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300935 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530936 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100937 /* 53 - 720x576@200Hz */
938 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
939 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300940 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530941 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700942 /* 54 - 720(1440)x576i@200Hz */
943 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
944 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100945 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300946 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530947 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700948 /* 55 - 720(1440)x576i@200Hz */
949 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
950 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100951 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300952 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530953 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100954 /* 56 - 720x480@240Hz */
955 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
956 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300957 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530958 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100959 /* 57 - 720x480@240Hz */
960 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
961 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300962 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530963 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200964 /* 58 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700965 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
966 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100967 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300968 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530969 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjäläe5878032016-11-03 14:53:28 +0200970 /* 59 - 720(1440)x480i@240Hz */
Clint Taylorfb01d282014-09-02 17:03:35 -0700971 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
972 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100973 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300974 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530975 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100976 /* 60 - 1280x720@24Hz */
977 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
978 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300979 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530980 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100981 /* 61 - 1280x720@25Hz */
982 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
983 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300984 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530985 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100986 /* 62 - 1280x720@30Hz */
987 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 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 = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100991 /* 63 - 1920x1080@120Hz */
992 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
993 2052, 2200, 0, 1080, 1084, 1089, 1125, 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 = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100996 /* 64 - 1920x1080@100Hz */
997 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -0700998 2492, 2640, 0, 1080, 1084, 1089, 1125, 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 = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001001};
1002
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001003/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001004 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001005 */
1006static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001007 /* 0 - dummy, VICs start at 1 */
1008 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001009 /* 1 - 3840x2160@30Hz */
1010 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1011 3840, 4016, 4104, 4400, 0,
1012 2160, 2168, 2178, 2250, 0,
1013 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1014 .vrefresh = 30, },
1015 /* 2 - 3840x2160@25Hz */
1016 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1017 3840, 4896, 4984, 5280, 0,
1018 2160, 2168, 2178, 2250, 0,
1019 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1020 .vrefresh = 25, },
1021 /* 3 - 3840x2160@24Hz */
1022 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1023 3840, 5116, 5204, 5500, 0,
1024 2160, 2168, 2178, 2250, 0,
1025 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1026 .vrefresh = 24, },
1027 /* 4 - 4096x2160@24Hz (SMPTE) */
1028 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1029 4096, 5116, 5204, 5500, 0,
1030 2160, 2168, 2178, 2250, 0,
1031 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1032 .vrefresh = 24, },
1033};
1034
Adam Jackson61e57a82010-03-29 21:43:18 +00001035/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001036
Adam Jackson083ae052009-09-23 17:30:45 -04001037static const u8 edid_header[] = {
1038 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1039};
Dave Airlief453ba02008-11-07 14:05:41 -08001040
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001041/**
1042 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1043 * @raw_edid: pointer to raw base EDID block
1044 *
1045 * Sanity check the header of the base EDID block.
1046 *
1047 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001048 */
1049int drm_edid_header_is_valid(const u8 *raw_edid)
1050{
1051 int i, score = 0;
1052
1053 for (i = 0; i < sizeof(edid_header); i++)
1054 if (raw_edid[i] == edid_header[i])
1055 score++;
1056
1057 return score;
1058}
1059EXPORT_SYMBOL(drm_edid_header_is_valid);
1060
Adam Jackson47819ba2012-05-30 16:42:39 -04001061static int edid_fixup __read_mostly = 6;
1062module_param_named(edid_fixup, edid_fixup, int, 0400);
1063MODULE_PARM_DESC(edid_fixup,
1064 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001065
Dave Airlie40d9b042014-10-20 16:29:33 +10001066static void drm_get_displayid(struct drm_connector *connector,
1067 struct edid *edid);
Dave Airlieda9df2f2014-12-11 10:12:57 +10001068
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001069static int drm_edid_block_checksum(const u8 *raw_edid)
1070{
1071 int i;
1072 u8 csum = 0;
1073 for (i = 0; i < EDID_LENGTH; i++)
1074 csum += raw_edid[i];
1075
1076 return csum;
1077}
1078
Stefan Brünsd6885d62014-11-30 19:57:41 +01001079static bool drm_edid_is_zero(const u8 *in_edid, int length)
1080{
1081 if (memchr_inv(in_edid, 0, length))
1082 return false;
1083
1084 return true;
1085}
1086
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001087/**
1088 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1089 * @raw_edid: pointer to raw EDID block
1090 * @block: type of block to validate (0 for base, extension otherwise)
1091 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001092 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001093 *
1094 * Validate a base or extension EDID block and optionally dump bad blocks to
1095 * the console.
1096 *
1097 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001098 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001099bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1100 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001101{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001102 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001103 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001104
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001105 if (WARN_ON(!raw_edid))
1106 return false;
1107
Adam Jackson47819ba2012-05-30 16:42:39 -04001108 if (edid_fixup > 8 || edid_fixup < 0)
1109 edid_fixup = 6;
1110
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001111 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001112 int score = drm_edid_header_is_valid(raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07001113 if (score == 8) {
1114 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001115 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001116 } else if (score >= edid_fixup) {
1117 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1118 * The corrupt flag needs to be set here otherwise, the
1119 * fix-up code here will correct the problem, the
1120 * checksum is correct and the test fails
1121 */
1122 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001123 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001124 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1125 memcpy(raw_edid, edid_header, sizeof(edid_header));
1126 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001127 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001128 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001129 goto bad;
1130 }
1131 }
Dave Airlief453ba02008-11-07 14:05:41 -08001132
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001133 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001134 if (csum) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001135 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001136 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001137
Adam Jackson4a638b42010-05-25 16:33:09 -04001138 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001139 if (raw_edid[0] == CEA_EXT) {
1140 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1141 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1142 } else {
1143 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001144 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001145
Adam Jackson4a638b42010-05-25 16:33:09 -04001146 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001147 }
Dave Airlief453ba02008-11-07 14:05:41 -08001148 }
1149
Adam Jackson61e57a82010-03-29 21:43:18 +00001150 /* per-block-type checks */
1151 switch (raw_edid[0]) {
1152 case 0: /* base */
1153 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001154 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001155 goto bad;
1156 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001157
Adam Jackson61e57a82010-03-29 21:43:18 +00001158 if (edid->revision > 4)
1159 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1160 break;
1161
1162 default:
1163 break;
1164 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001165
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001166 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001167
1168bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001169 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001170 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001171 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001172 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001173 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001174 print_hex_dump(KERN_NOTICE,
1175 " \t", DUMP_PREFIX_NONE, 16, 1,
1176 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001177 }
Dave Airlief453ba02008-11-07 14:05:41 -08001178 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001179 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001180}
Carsten Emdeda0df922012-03-18 22:37:33 +01001181EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001182
1183/**
1184 * drm_edid_is_valid - sanity check EDID data
1185 * @edid: EDID data
1186 *
1187 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001188 *
1189 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001190 */
1191bool drm_edid_is_valid(struct edid *edid)
1192{
1193 int i;
1194 u8 *raw = (u8 *)edid;
1195
1196 if (!edid)
1197 return false;
1198
1199 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001200 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001201 return false;
1202
1203 return true;
1204}
Alex Deucher3c537882010-02-05 04:21:19 -05001205EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001206
Adam Jackson61e57a82010-03-29 21:43:18 +00001207#define DDC_SEGMENT_ADDR 0x30
1208/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001209 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001210 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001211 * @buf: EDID data buffer to be filled
1212 * @block: 128 byte EDID block to start fetching from
1213 * @len: EDID data buffer length to fetch
1214 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001215 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001216 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001217 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001218 */
1219static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001220drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001221{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001222 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001223 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001224 unsigned char segment = block >> 1;
1225 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001226 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001227
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001228 /*
1229 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001230 * adapter reports EAGAIN. However, we find that bit-banging transfers
1231 * are susceptible to errors under a heavily loaded machine and
1232 * generate spurious NAKs and timeouts. Retrying the transfer
1233 * of the individual block a few times seems to overcome this.
1234 */
1235 do {
1236 struct i2c_msg msgs[] = {
1237 {
Shirish Scd004b32012-08-30 07:04:06 +00001238 .addr = DDC_SEGMENT_ADDR,
1239 .flags = 0,
1240 .len = 1,
1241 .buf = &segment,
1242 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001243 .addr = DDC_ADDR,
1244 .flags = 0,
1245 .len = 1,
1246 .buf = &start,
1247 }, {
1248 .addr = DDC_ADDR,
1249 .flags = I2C_M_RD,
1250 .len = len,
1251 .buf = buf,
1252 }
1253 };
Shirish Scd004b32012-08-30 07:04:06 +00001254
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001255 /*
1256 * Avoid sending the segment addr to not upset non-compliant
1257 * DDC monitors.
1258 */
Shirish Scd004b32012-08-30 07:04:06 +00001259 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1260
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001261 if (ret == -ENXIO) {
1262 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1263 adapter->name);
1264 break;
1265 }
Shirish Scd004b32012-08-30 07:04:06 +00001266 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001267
Shirish Scd004b32012-08-30 07:04:06 +00001268 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001269}
1270
Chris Wilson14544d02016-10-24 12:38:21 +01001271static void connector_bad_edid(struct drm_connector *connector,
1272 u8 *edid, int num_blocks)
1273{
1274 int i;
1275
1276 if (connector->bad_edid_counter++ && !(drm_debug & DRM_UT_KMS))
1277 return;
1278
1279 dev_warn(connector->dev->dev,
1280 "%s: EDID is invalid:\n",
1281 connector->name);
1282 for (i = 0; i < num_blocks; i++) {
1283 u8 *block = edid + i * EDID_LENGTH;
1284 char prefix[20];
1285
1286 if (drm_edid_is_zero(block, EDID_LENGTH))
1287 sprintf(prefix, "\t[%02x] ZERO ", i);
1288 else if (!drm_edid_block_valid(block, i, false, NULL))
1289 sprintf(prefix, "\t[%02x] BAD ", i);
1290 else
1291 sprintf(prefix, "\t[%02x] GOOD ", i);
1292
1293 print_hex_dump(KERN_WARNING,
1294 prefix, DUMP_PREFIX_NONE, 16, 1,
1295 block, EDID_LENGTH, false);
1296 }
1297}
1298
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001299/**
1300 * drm_do_get_edid - get EDID data using a custom EDID block read function
1301 * @connector: connector we're probing
1302 * @get_edid_block: EDID block read function
1303 * @data: private data passed to the block read function
1304 *
1305 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1306 * exposes a different interface to read EDID blocks this function can be used
1307 * to get EDID data using a custom block read function.
1308 *
1309 * As in the general case the DDC bus is accessible by the kernel at the I2C
1310 * level, drivers must make all reasonable efforts to expose it as an I2C
1311 * adapter and use drm_get_edid() instead of abusing this function.
1312 *
1313 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1314 */
1315struct edid *drm_do_get_edid(struct drm_connector *connector,
1316 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1317 size_t len),
1318 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001319{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001320 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001321 u8 *edid, *new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001322
Chris Wilsonf14f3682016-10-17 09:35:12 +01001323 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
Adam Jackson61e57a82010-03-29 21:43:18 +00001324 return NULL;
1325
1326 /* base block fetch */
1327 for (i = 0; i < 4; i++) {
Chris Wilsonf14f3682016-10-17 09:35:12 +01001328 if (get_edid_block(data, edid, 0, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001329 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001330 if (drm_edid_block_valid(edid, 0, false,
Todd Previte6ba2bd32015-04-21 11:09:41 -07001331 &connector->edid_corrupt))
Adam Jackson61e57a82010-03-29 21:43:18 +00001332 break;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001333 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001334 connector->null_edid_counter++;
1335 goto carp;
1336 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001337 }
1338 if (i == 4)
1339 goto carp;
1340
1341 /* if there's no extensions, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001342 valid_extensions = edid[0x7e];
1343 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001344 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001345
Chris Wilson14544d02016-10-24 12:38:21 +01001346 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00001347 if (!new)
1348 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001349 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001350
Chris Wilsonf14f3682016-10-17 09:35:12 +01001351 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01001352 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01001353
Adam Jackson61e57a82010-03-29 21:43:18 +00001354 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01001355 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001356 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001357 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001358 break;
1359 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001360
Chris Wilson14544d02016-10-24 12:38:21 +01001361 if (i == 4)
1362 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001363 }
1364
Chris Wilsonf14f3682016-10-17 09:35:12 +01001365 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01001366 u8 *base;
1367
1368 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1369
Chris Wilsonf14f3682016-10-17 09:35:12 +01001370 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
1371 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01001372
1373 new = kmalloc((valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01001374 if (!new)
1375 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01001376
1377 base = new;
1378 for (i = 0; i <= edid[0x7e]; i++) {
1379 u8 *block = edid + i * EDID_LENGTH;
1380
1381 if (!drm_edid_block_valid(block, i, false, NULL))
1382 continue;
1383
1384 memcpy(base, block, EDID_LENGTH);
1385 base += EDID_LENGTH;
1386 }
1387
1388 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01001389 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001390 }
1391
Chris Wilsonf14f3682016-10-17 09:35:12 +01001392 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001393
1394carp:
Chris Wilson14544d02016-10-24 12:38:21 +01001395 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001396out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01001397 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001398 return NULL;
1399}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001400EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001401
1402/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001403 * drm_probe_ddc() - probe DDC presence
1404 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001405 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001406 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001407 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001408bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001409drm_probe_ddc(struct i2c_adapter *adapter)
1410{
1411 unsigned char out;
1412
1413 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1414}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001415EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001416
1417/**
1418 * drm_get_edid - get EDID data, if available
1419 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001420 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001421 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001422 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001423 * attach it to the connector.
1424 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001425 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001426 */
1427struct edid *drm_get_edid(struct drm_connector *connector,
1428 struct i2c_adapter *adapter)
1429{
Dave Airlie40d9b042014-10-20 16:29:33 +10001430 struct edid *edid;
1431
Jani Nikula15f080f2017-02-17 17:20:53 +02001432 if (connector->force == DRM_FORCE_OFF)
1433 return NULL;
1434
1435 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001436 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001437
Dave Airlie40d9b042014-10-20 16:29:33 +10001438 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1439 if (edid)
1440 drm_get_displayid(connector, edid);
1441 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001442}
1443EXPORT_SYMBOL(drm_get_edid);
1444
Jani Nikula51f8da52013-09-27 15:08:27 +03001445/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01001446 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1447 * @connector: connector we're probing
1448 * @adapter: I2C adapter to use for DDC
1449 *
1450 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1451 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1452 * switch DDC to the GPU which is retrieving EDID.
1453 *
1454 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1455 */
1456struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1457 struct i2c_adapter *adapter)
1458{
1459 struct pci_dev *pdev = connector->dev->pdev;
1460 struct edid *edid;
1461
1462 vga_switcheroo_lock_ddc(pdev);
1463 edid = drm_get_edid(connector, adapter);
1464 vga_switcheroo_unlock_ddc(pdev);
1465
1466 return edid;
1467}
1468EXPORT_SYMBOL(drm_get_edid_switcheroo);
1469
1470/**
Jani Nikula51f8da52013-09-27 15:08:27 +03001471 * drm_edid_duplicate - duplicate an EDID and the extensions
1472 * @edid: EDID to duplicate
1473 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001474 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001475 */
1476struct edid *drm_edid_duplicate(const struct edid *edid)
1477{
1478 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1479}
1480EXPORT_SYMBOL(drm_edid_duplicate);
1481
Adam Jackson61e57a82010-03-29 21:43:18 +00001482/*** EDID parsing ***/
1483
Dave Airlief453ba02008-11-07 14:05:41 -08001484/**
1485 * edid_vendor - match a string against EDID's obfuscated vendor field
1486 * @edid: EDID to match
1487 * @vendor: vendor string
1488 *
1489 * Returns true if @vendor is in @edid, false otherwise
1490 */
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001491static bool edid_vendor(struct edid *edid, const char *vendor)
Dave Airlief453ba02008-11-07 14:05:41 -08001492{
1493 char edid_vendor[3];
1494
1495 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1496 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1497 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001498 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001499
1500 return !strncmp(edid_vendor, vendor, 3);
1501}
1502
1503/**
1504 * edid_get_quirks - return quirk flags for a given EDID
1505 * @edid: EDID to process
1506 *
1507 * This tells subsequent routines what fixes they need to apply.
1508 */
1509static u32 edid_get_quirks(struct edid *edid)
1510{
Jani Nikula23c4cfb2016-12-28 13:06:26 +02001511 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08001512 int i;
1513
1514 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1515 quirk = &edid_quirk_list[i];
1516
1517 if (edid_vendor(edid, quirk->vendor) &&
1518 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1519 return quirk->quirks;
1520 }
1521
1522 return 0;
1523}
1524
1525#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001526#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001527
Dave Airlief453ba02008-11-07 14:05:41 -08001528/**
1529 * edid_fixup_preferred - set preferred modes based on quirk list
1530 * @connector: has mode list to fix up
1531 * @quirks: quirks list
1532 *
1533 * Walk the mode list for @connector, clearing the preferred status
1534 * on existing modes and setting it anew for the right mode ala @quirks.
1535 */
1536static void edid_fixup_preferred(struct drm_connector *connector,
1537 u32 quirks)
1538{
1539 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001540 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001541 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001542
1543 if (list_empty(&connector->probed_modes))
1544 return;
1545
1546 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1547 target_refresh = 60;
1548 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1549 target_refresh = 75;
1550
1551 preferred_mode = list_first_entry(&connector->probed_modes,
1552 struct drm_display_mode, head);
1553
1554 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1555 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1556
1557 if (cur_mode == preferred_mode)
1558 continue;
1559
1560 /* Largest mode is preferred */
1561 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1562 preferred_mode = cur_mode;
1563
Alex Deucher339d2022013-08-15 11:42:14 -04001564 cur_vrefresh = cur_mode->vrefresh ?
1565 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1566 preferred_vrefresh = preferred_mode->vrefresh ?
1567 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08001568 /* At a given size, try to get closest to target refresh */
1569 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04001570 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1571 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08001572 preferred_mode = cur_mode;
1573 }
1574 }
1575
1576 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1577}
1578
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001579static bool
1580mode_is_rb(const struct drm_display_mode *mode)
1581{
1582 return (mode->htotal - mode->hdisplay == 160) &&
1583 (mode->hsync_end - mode->hdisplay == 80) &&
1584 (mode->hsync_end - mode->hsync_start == 32) &&
1585 (mode->vsync_start - mode->vdisplay == 3);
1586}
1587
Adam Jackson33c75312012-04-13 16:33:29 -04001588/*
1589 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1590 * @dev: Device to duplicate against
1591 * @hsize: Mode width
1592 * @vsize: Mode height
1593 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001594 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04001595 *
1596 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001597 *
1598 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04001599 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001600struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001601 int hsize, int vsize, int fresh,
1602 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08001603{
Adam Jackson07a5e632009-12-03 17:44:38 -05001604 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08001605
Thierry Redinga6b21832012-11-23 15:01:42 +01001606 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001607 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001608 if (hsize != ptr->hdisplay)
1609 continue;
1610 if (vsize != ptr->vdisplay)
1611 continue;
1612 if (fresh != drm_mode_vrefresh(ptr))
1613 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001614 if (rb != mode_is_rb(ptr))
1615 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001616
1617 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08001618 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001619
1620 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08001621}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001622EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04001623
Adam Jacksond1ff6402010-03-29 21:43:26 +00001624typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1625
1626static void
Adam Jackson4d76a222010-08-03 14:38:17 -04001627cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1628{
1629 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001630 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04001631 u8 *det_base = ext + d;
1632
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001633 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04001634 for (i = 0; i < n; i++)
1635 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1636}
1637
1638static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001639vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1640{
1641 unsigned int i, n = min((int)ext[0x02], 6);
1642 u8 *det_base = ext + 5;
1643
1644 if (ext[0x01] != 1)
1645 return; /* unknown version */
1646
1647 for (i = 0; i < n; i++)
1648 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1649}
1650
1651static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00001652drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1653{
1654 int i;
1655 struct edid *edid = (struct edid *)raw_edid;
1656
1657 if (edid == NULL)
1658 return;
1659
1660 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1661 cb(&(edid->detailed_timings[i]), closure);
1662
Adam Jackson4d76a222010-08-03 14:38:17 -04001663 for (i = 1; i <= raw_edid[0x7e]; i++) {
1664 u8 *ext = raw_edid + (i * EDID_LENGTH);
1665 switch (*ext) {
1666 case CEA_EXT:
1667 cea_for_each_detailed_block(ext, cb, closure);
1668 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001669 case VTB_EXT:
1670 vtb_for_each_detailed_block(ext, cb, closure);
1671 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04001672 default:
1673 break;
1674 }
1675 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00001676}
1677
1678static void
1679is_rb(struct detailed_timing *t, void *data)
1680{
1681 u8 *r = (u8 *)t;
1682 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
1683 if (r[15] & 0x10)
1684 *(bool *)data = true;
1685}
1686
1687/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1688static bool
1689drm_monitor_supports_rb(struct edid *edid)
1690{
1691 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02001692 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00001693 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
1694 return ret;
1695 }
1696
1697 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
1698}
1699
Adam Jackson7a374352010-03-29 21:43:30 +00001700static void
1701find_gtf2(struct detailed_timing *t, void *data)
1702{
1703 u8 *r = (u8 *)t;
1704 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
1705 *(u8 **)data = r;
1706}
1707
1708/* Secondary GTF curve kicks in above some break frequency */
1709static int
1710drm_gtf2_hbreak(struct edid *edid)
1711{
1712 u8 *r = NULL;
1713 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1714 return r ? (r[12] * 2) : 0;
1715}
1716
1717static int
1718drm_gtf2_2c(struct edid *edid)
1719{
1720 u8 *r = NULL;
1721 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1722 return r ? r[13] : 0;
1723}
1724
1725static int
1726drm_gtf2_m(struct edid *edid)
1727{
1728 u8 *r = NULL;
1729 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1730 return r ? (r[15] << 8) + r[14] : 0;
1731}
1732
1733static int
1734drm_gtf2_k(struct edid *edid)
1735{
1736 u8 *r = NULL;
1737 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1738 return r ? r[16] : 0;
1739}
1740
1741static int
1742drm_gtf2_2j(struct edid *edid)
1743{
1744 u8 *r = NULL;
1745 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1746 return r ? r[17] : 0;
1747}
1748
1749/**
1750 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
1751 * @edid: EDID block to scan
1752 */
1753static int standard_timing_level(struct edid *edid)
1754{
1755 if (edid->revision >= 2) {
1756 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
1757 return LEVEL_CVT;
1758 if (drm_gtf2_hbreak(edid))
1759 return LEVEL_GTF2;
1760 return LEVEL_GTF;
1761 }
1762 return LEVEL_DMT;
1763}
1764
Adam Jackson23425ca2009-09-23 17:30:58 -04001765/*
1766 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
1767 * monitors fill with ascii space (0x20) instead.
1768 */
1769static int
1770bad_std_timing(u8 a, u8 b)
1771{
1772 return (a == 0x00 && b == 0x00) ||
1773 (a == 0x01 && b == 0x01) ||
1774 (a == 0x20 && b == 0x20);
1775}
1776
Dave Airlief453ba02008-11-07 14:05:41 -08001777/**
1778 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01001779 * @connector: connector of for the EDID block
1780 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08001781 * @t: standard timing params
1782 *
1783 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08001784 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08001785 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001786static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00001787drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02001788 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08001789{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001790 struct drm_device *dev = connector->dev;
1791 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08001792 int hsize, vsize;
1793 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001794 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
1795 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08001796 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
1797 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00001798 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001799
Adam Jackson23425ca2009-09-23 17:30:58 -04001800 if (bad_std_timing(t->hsize, t->vfreq_aspect))
1801 return NULL;
1802
Zhao Yakui5c612592009-06-22 13:17:10 +08001803 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
1804 hsize = t->hsize * 8 + 248;
1805 /* vrefresh_rate = vfreq + 60 */
1806 vrefresh_rate = vfreq + 60;
1807 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04001808 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02001809 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04001810 vsize = hsize;
1811 else
1812 vsize = (hsize * 10) / 16;
1813 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08001814 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001815 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08001816 vsize = (hsize * 4) / 5;
1817 else
1818 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00001819
1820 /* HDTV hack, part 1 */
1821 if (vrefresh_rate == 60 &&
1822 ((hsize == 1360 && vsize == 765) ||
1823 (hsize == 1368 && vsize == 769))) {
1824 hsize = 1366;
1825 vsize = 768;
1826 }
1827
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001828 /*
1829 * If this connector already has a mode for this size and refresh
1830 * rate (because it came from detailed or CVT info), use that
1831 * instead. This way we don't have to guess at interlace or
1832 * reduced blanking.
1833 */
Adam Jackson522032d2010-04-09 16:52:49 +00001834 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001835 if (m->hdisplay == hsize && m->vdisplay == vsize &&
1836 drm_mode_vrefresh(m) == vrefresh_rate)
1837 return NULL;
1838
Adam Jacksona0910c82010-03-29 21:43:28 +00001839 /* HDTV hack, part 2 */
1840 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
1841 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10001842 false);
Zhao Yakui559ee212009-09-03 09:33:47 +08001843 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10001844 mode->hsync_start = mode->hsync_start - 1;
1845 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08001846 return mode;
1847 }
Adam Jacksona0910c82010-03-29 21:43:28 +00001848
Zhao Yakui559ee212009-09-03 09:33:47 +08001849 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001850 if (drm_monitor_supports_rb(edid)) {
1851 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
1852 true);
1853 if (mode)
1854 return mode;
1855 }
1856 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08001857 if (mode)
1858 return mode;
1859
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001860 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08001861 switch (timing_level) {
1862 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08001863 break;
1864 case LEVEL_GTF:
1865 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
1866 break;
Adam Jackson7a374352010-03-29 21:43:30 +00001867 case LEVEL_GTF2:
1868 /*
1869 * This is potentially wrong if there's ever a monitor with
1870 * more than one ranges section, each claiming a different
1871 * secondary GTF curve. Please don't do that.
1872 */
1873 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01001874 if (!mode)
1875 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00001876 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01001877 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00001878 mode = drm_gtf_mode_complex(dev, hsize, vsize,
1879 vrefresh_rate, 0, 0,
1880 drm_gtf2_m(edid),
1881 drm_gtf2_2c(edid),
1882 drm_gtf2_k(edid),
1883 drm_gtf2_2j(edid));
1884 }
1885 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08001886 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10001887 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
1888 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08001889 break;
1890 }
Dave Airlief453ba02008-11-07 14:05:41 -08001891 return mode;
1892}
1893
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001894/*
1895 * EDID is delightfully ambiguous about how interlaced modes are to be
1896 * encoded. Our internal representation is of frame height, but some
1897 * HDTV detailed timings are encoded as field height.
1898 *
1899 * The format list here is from CEA, in frame size. Technically we
1900 * should be checking refresh rate too. Whatever.
1901 */
1902static void
1903drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
1904 struct detailed_pixel_timing *pt)
1905{
1906 int i;
1907 static const struct {
1908 int w, h;
1909 } cea_interlaced[] = {
1910 { 1920, 1080 },
1911 { 720, 480 },
1912 { 1440, 480 },
1913 { 2880, 480 },
1914 { 720, 576 },
1915 { 1440, 576 },
1916 { 2880, 576 },
1917 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001918
1919 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
1920 return;
1921
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04001922 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001923 if ((mode->hdisplay == cea_interlaced[i].w) &&
1924 (mode->vdisplay == cea_interlaced[i].h / 2)) {
1925 mode->vdisplay *= 2;
1926 mode->vsync_start *= 2;
1927 mode->vsync_end *= 2;
1928 mode->vtotal *= 2;
1929 mode->vtotal |= 1;
1930 }
1931 }
1932
1933 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1934}
1935
Dave Airlief453ba02008-11-07 14:05:41 -08001936/**
1937 * drm_mode_detailed - create a new mode from an EDID detailed timing section
1938 * @dev: DRM device (needed to create new mode)
1939 * @edid: EDID block
1940 * @timing: EDID detailed timing info
1941 * @quirks: quirks to apply
1942 *
1943 * An EDID detailed timing block contains enough info for us to create and
1944 * return a new struct drm_display_mode.
1945 */
1946static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
1947 struct edid *edid,
1948 struct detailed_timing *timing,
1949 u32 quirks)
1950{
1951 struct drm_display_mode *mode;
1952 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001953 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
1954 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
1955 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
1956 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02001957 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
1958 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 +01001959 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 +02001960 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 -08001961
Adam Jacksonfc438962009-06-04 10:20:34 +10001962 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02001963 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10001964 return NULL;
1965
Michel Dänzer0454bea2009-06-15 16:56:07 +02001966 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02001967 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08001968 return NULL;
1969 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02001970 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02001971 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08001972 }
1973
Zhao Yakuifcb45612009-10-14 09:11:25 +08001974 /* it is incorrect if hsync/vsync width is zero */
1975 if (!hsync_pulse_width || !vsync_pulse_width) {
1976 DRM_DEBUG_KMS("Incorrect Detailed timing. "
1977 "Wrong Hsync/Vsync pulse width\n");
1978 return NULL;
1979 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001980
1981 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
1982 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
1983 if (!mode)
1984 return NULL;
1985
1986 goto set_size;
1987 }
1988
Dave Airlief453ba02008-11-07 14:05:41 -08001989 mode = drm_mode_create(dev);
1990 if (!mode)
1991 return NULL;
1992
Dave Airlief453ba02008-11-07 14:05:41 -08001993 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02001994 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08001995
Michel Dänzer0454bea2009-06-15 16:56:07 +02001996 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08001997
Michel Dänzer0454bea2009-06-15 16:56:07 +02001998 mode->hdisplay = hactive;
1999 mode->hsync_start = mode->hdisplay + hsync_offset;
2000 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2001 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002002
Michel Dänzer0454bea2009-06-15 16:56:07 +02002003 mode->vdisplay = vactive;
2004 mode->vsync_start = mode->vdisplay + vsync_offset;
2005 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2006 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002007
Jesse Barnes7064fef2009-11-05 10:12:54 -08002008 /* Some EDIDs have bogus h/vtotal values */
2009 if (mode->hsync_end > mode->htotal)
2010 mode->htotal = mode->hsync_end + 1;
2011 if (mode->vsync_end > mode->vtotal)
2012 mode->vtotal = mode->vsync_end + 1;
2013
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002014 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002015
2016 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002017 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002018 }
2019
Michel Dänzer0454bea2009-06-15 16:56:07 +02002020 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2021 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2022 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2023 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002024
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002025set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002026 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2027 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002028
2029 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2030 mode->width_mm *= 10;
2031 mode->height_mm *= 10;
2032 }
2033
2034 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2035 mode->width_mm = edid->width_cm * 10;
2036 mode->height_mm = edid->height_cm * 10;
2037 }
2038
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002039 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01002040 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002041 drm_mode_set_name(mode);
2042
Dave Airlief453ba02008-11-07 14:05:41 -08002043 return mode;
2044}
2045
Adam Jackson07a5e632009-12-03 17:44:38 -05002046static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002047mode_in_hsync_range(const struct drm_display_mode *mode,
2048 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002049{
2050 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002051
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002052 hmin = t[7];
2053 if (edid->revision >= 4)
2054 hmin += ((t[4] & 0x04) ? 255 : 0);
2055 hmax = t[8];
2056 if (edid->revision >= 4)
2057 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002058 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002059
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002060 return (hsync <= hmax && hsync >= hmin);
2061}
2062
2063static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002064mode_in_vsync_range(const struct drm_display_mode *mode,
2065 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002066{
2067 int vsync, vmin, vmax;
2068
2069 vmin = t[5];
2070 if (edid->revision >= 4)
2071 vmin += ((t[4] & 0x01) ? 255 : 0);
2072 vmax = t[6];
2073 if (edid->revision >= 4)
2074 vmax += ((t[4] & 0x02) ? 255 : 0);
2075 vsync = drm_mode_vrefresh(mode);
2076
2077 return (vsync <= vmax && vsync >= vmin);
2078}
2079
2080static u32
2081range_pixel_clock(struct edid *edid, u8 *t)
2082{
2083 /* unspecified */
2084 if (t[9] == 0 || t[9] == 255)
2085 return 0;
2086
2087 /* 1.4 with CVT support gives us real precision, yay */
2088 if (edid->revision >= 4 && t[10] == 0x04)
2089 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2090
2091 /* 1.3 is pathetic, so fuzz up a bit */
2092 return t[9] * 10000 + 5001;
2093}
2094
Adam Jackson07a5e632009-12-03 17:44:38 -05002095static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002096mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002097 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002098{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002099 u32 max_clock;
2100 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002101
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002102 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002103 return false;
2104
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002105 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002106 return false;
2107
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002108 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002109 if (mode->clock > max_clock)
2110 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002111
2112 /* 1.4 max horizontal check */
2113 if (edid->revision >= 4 && t[10] == 0x04)
2114 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2115 return false;
2116
2117 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2118 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002119
2120 return true;
2121}
2122
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002123static bool valid_inferred_mode(const struct drm_connector *connector,
2124 const struct drm_display_mode *mode)
2125{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002126 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002127 bool ok = false;
2128
2129 list_for_each_entry(m, &connector->probed_modes, head) {
2130 if (mode->hdisplay == m->hdisplay &&
2131 mode->vdisplay == m->vdisplay &&
2132 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2133 return false; /* duplicated */
2134 if (mode->hdisplay <= m->hdisplay &&
2135 mode->vdisplay <= m->vdisplay)
2136 ok = true;
2137 }
2138 return ok;
2139}
2140
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002141static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002142drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002143 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002144{
2145 int i, modes = 0;
2146 struct drm_display_mode *newmode;
2147 struct drm_device *dev = connector->dev;
2148
Thierry Redinga6b21832012-11-23 15:01:42 +01002149 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002150 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2151 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002152 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2153 if (newmode) {
2154 drm_mode_probed_add(connector, newmode);
2155 modes++;
2156 }
2157 }
2158 }
2159
2160 return modes;
2161}
2162
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002163/* fix up 1366x768 mode from 1368x768;
2164 * GFT/CVT can't express 1366 width which isn't dividable by 8
2165 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002166void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002167{
2168 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2169 mode->hdisplay = 1366;
2170 mode->hsync_start--;
2171 mode->hsync_end--;
2172 drm_mode_set_name(mode);
2173 }
2174}
2175
Adam Jacksonb309bd32012-04-13 16:33:40 -04002176static int
2177drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2178 struct detailed_timing *timing)
2179{
2180 int i, modes = 0;
2181 struct drm_display_mode *newmode;
2182 struct drm_device *dev = connector->dev;
2183
Thierry Redinga6b21832012-11-23 15:01:42 +01002184 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002185 const struct minimode *m = &extra_modes[i];
2186 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002187 if (!newmode)
2188 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002189
Takashi Iwai969218f2017-01-17 17:43:29 +01002190 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002191 if (!mode_in_range(newmode, edid, timing) ||
2192 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002193 drm_mode_destroy(dev, newmode);
2194 continue;
2195 }
2196
2197 drm_mode_probed_add(connector, newmode);
2198 modes++;
2199 }
2200
2201 return modes;
2202}
2203
2204static int
2205drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2206 struct detailed_timing *timing)
2207{
2208 int i, modes = 0;
2209 struct drm_display_mode *newmode;
2210 struct drm_device *dev = connector->dev;
2211 bool rb = drm_monitor_supports_rb(edid);
2212
Thierry Redinga6b21832012-11-23 15:01:42 +01002213 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002214 const struct minimode *m = &extra_modes[i];
2215 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002216 if (!newmode)
2217 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002218
Takashi Iwai969218f2017-01-17 17:43:29 +01002219 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002220 if (!mode_in_range(newmode, edid, timing) ||
2221 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002222 drm_mode_destroy(dev, newmode);
2223 continue;
2224 }
2225
2226 drm_mode_probed_add(connector, newmode);
2227 modes++;
2228 }
2229
2230 return modes;
2231}
2232
Adam Jackson13931572010-08-03 14:38:19 -04002233static void
2234do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002235{
Adam Jackson13931572010-08-03 14:38:19 -04002236 struct detailed_mode_closure *closure = c;
2237 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002238 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002239
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002240 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2241 return;
2242
2243 closure->modes += drm_dmt_modes_for_range(closure->connector,
2244 closure->edid,
2245 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002246
2247 if (!version_greater(closure->edid, 1, 1))
2248 return; /* GTF not defined yet */
2249
2250 switch (range->flags) {
2251 case 0x02: /* secondary gtf, XXX could do more */
2252 case 0x00: /* default gtf */
2253 closure->modes += drm_gtf_modes_for_range(closure->connector,
2254 closure->edid,
2255 timing);
2256 break;
2257 case 0x04: /* cvt, only in 1.4+ */
2258 if (!version_greater(closure->edid, 1, 3))
2259 break;
2260
2261 closure->modes += drm_cvt_modes_for_range(closure->connector,
2262 closure->edid,
2263 timing);
2264 break;
2265 case 0x01: /* just the ranges, no formula */
2266 default:
2267 break;
2268 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002269}
2270
Adam Jackson13931572010-08-03 14:38:19 -04002271static int
2272add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2273{
2274 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002275 .connector = connector,
2276 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002277 };
2278
2279 if (version_greater(edid, 1, 0))
2280 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2281 &closure);
2282
2283 return closure.modes;
2284}
2285
Adam Jackson2255be12010-03-29 21:43:22 +00002286static int
2287drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2288{
2289 int i, j, m, modes = 0;
2290 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00002291 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00002292
2293 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002294 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002295 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002296 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002297 break;
2298 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002299 mode = drm_mode_find_dmt(connector->dev,
2300 est3_modes[m].w,
2301 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002302 est3_modes[m].r,
2303 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002304 if (mode) {
2305 drm_mode_probed_add(connector, mode);
2306 modes++;
2307 }
2308 }
2309 }
2310 }
2311
2312 return modes;
2313}
2314
Adam Jackson13931572010-08-03 14:38:19 -04002315static void
2316do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002317{
Adam Jackson13931572010-08-03 14:38:19 -04002318 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002319 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002320
2321 if (data->type == EDID_DETAIL_EST_TIMINGS)
2322 closure->modes += drm_est3_modes(closure->connector, timing);
2323}
2324
2325/**
2326 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002327 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002328 * @edid: EDID block to scan
2329 *
2330 * Each EDID block contains a bitmap of the supported "established modes" list
2331 * (defined above). Tease them out and add them to the global modes list.
2332 */
2333static int
2334add_established_modes(struct drm_connector *connector, struct edid *edid)
2335{
Adam Jackson9cf00972009-12-03 17:44:36 -05002336 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002337 unsigned long est_bits = edid->established_timings.t1 |
2338 (edid->established_timings.t2 << 8) |
2339 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2340 int i, modes = 0;
2341 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002342 .connector = connector,
2343 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002344 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002345
Adam Jackson13931572010-08-03 14:38:19 -04002346 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2347 if (est_bits & (1<<i)) {
2348 struct drm_display_mode *newmode;
2349 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2350 if (newmode) {
2351 drm_mode_probed_add(connector, newmode);
2352 modes++;
2353 }
2354 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002355 }
2356
Adam Jackson13931572010-08-03 14:38:19 -04002357 if (version_greater(edid, 1, 0))
2358 drm_for_each_detailed_block((u8 *)edid,
2359 do_established_modes, &closure);
2360
2361 return modes + closure.modes;
2362}
2363
2364static void
2365do_standard_modes(struct detailed_timing *timing, void *c)
2366{
2367 struct detailed_mode_closure *closure = c;
2368 struct detailed_non_pixel *data = &timing->data.other_data;
2369 struct drm_connector *connector = closure->connector;
2370 struct edid *edid = closure->edid;
2371
2372 if (data->type == EDID_DETAIL_STD_MODES) {
2373 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002374 for (i = 0; i < 6; i++) {
2375 struct std_timing *std;
2376 struct drm_display_mode *newmode;
2377
2378 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002379 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002380 if (newmode) {
2381 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002382 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002383 }
2384 }
Adam Jackson13931572010-08-03 14:38:19 -04002385 }
2386}
2387
2388/**
2389 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002390 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002391 * @edid: EDID block to scan
2392 *
2393 * Standard modes can be calculated using the appropriate standard (DMT,
2394 * GTF or CVT. Grab them from @edid and add them to the list.
2395 */
2396static int
2397add_standard_modes(struct drm_connector *connector, struct edid *edid)
2398{
2399 int i, modes = 0;
2400 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002401 .connector = connector,
2402 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002403 };
2404
2405 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2406 struct drm_display_mode *newmode;
2407
2408 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002409 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002410 if (newmode) {
2411 drm_mode_probed_add(connector, newmode);
2412 modes++;
2413 }
2414 }
2415
2416 if (version_greater(edid, 1, 0))
2417 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2418 &closure);
2419
2420 /* XXX should also look for standard codes in VTB blocks */
2421
2422 return modes + closure.modes;
2423}
2424
Dave Airlief453ba02008-11-07 14:05:41 -08002425static int drm_cvt_modes(struct drm_connector *connector,
2426 struct detailed_timing *timing)
2427{
2428 int i, j, modes = 0;
2429 struct drm_display_mode *newmode;
2430 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002431 struct cvt_timing *cvt;
2432 const int rates[] = { 60, 85, 75, 60, 50 };
2433 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002434
2435 for (i = 0; i < 4; i++) {
2436 int uninitialized_var(width), height;
2437 cvt = &(timing->data.other_data.data.cvt[i]);
2438
2439 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002440 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002441
2442 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002443 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002444 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002445 width = height * 4 / 3;
2446 break;
2447 case 0x04:
2448 width = height * 16 / 9;
2449 break;
2450 case 0x08:
2451 width = height * 16 / 10;
2452 break;
2453 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002454 width = height * 15 / 9;
2455 break;
2456 }
2457
2458 for (j = 1; j < 5; j++) {
2459 if (cvt->code[2] & (1 << j)) {
2460 newmode = drm_cvt_mode(dev, width, height,
2461 rates[j], j == 0,
2462 false, false);
2463 if (newmode) {
2464 drm_mode_probed_add(connector, newmode);
2465 modes++;
2466 }
2467 }
2468 }
2469 }
2470
2471 return modes;
2472}
2473
Adam Jackson13931572010-08-03 14:38:19 -04002474static void
2475do_cvt_mode(struct detailed_timing *timing, void *c)
2476{
2477 struct detailed_mode_closure *closure = c;
2478 struct detailed_non_pixel *data = &timing->data.other_data;
2479
2480 if (data->type == EDID_DETAIL_CVT_3BYTE)
2481 closure->modes += drm_cvt_modes(closure->connector, timing);
2482}
Adam Jackson9cf00972009-12-03 17:44:36 -05002483
2484static int
Adam Jackson13931572010-08-03 14:38:19 -04002485add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2486{
2487 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002488 .connector = connector,
2489 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002490 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002491
Adam Jackson13931572010-08-03 14:38:19 -04002492 if (version_greater(edid, 1, 2))
2493 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002494
Adam Jackson13931572010-08-03 14:38:19 -04002495 /* XXX should also look for CVT codes in VTB blocks */
2496
2497 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002498}
2499
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002500static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2501
Adam Jackson13931572010-08-03 14:38:19 -04002502static void
2503do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002504{
Adam Jackson13931572010-08-03 14:38:19 -04002505 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002506 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002507
2508 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002509 newmode = drm_mode_detailed(closure->connector->dev,
2510 closure->edid, timing,
2511 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002512 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002513 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002514
Adam Jackson13931572010-08-03 14:38:19 -04002515 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002516 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2517
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03002518 /*
2519 * Detailed modes are limited to 10kHz pixel clock resolution,
2520 * so fix up anything that looks like CEA/HDMI mode, but the clock
2521 * is just slightly off.
2522 */
2523 fixup_detailed_cea_mode_clock(newmode);
2524
Adam Jackson13931572010-08-03 14:38:19 -04002525 drm_mode_probed_add(closure->connector, newmode);
2526 closure->modes++;
2527 closure->preferred = 0;
Zhao Yakui882f0212009-08-26 18:20:49 +08002528 }
Ma Ling167f3a02009-03-20 14:09:48 +08002529}
2530
Adam Jackson13931572010-08-03 14:38:19 -04002531/*
2532 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002533 * @connector: attached connector
2534 * @edid: EDID block to scan
2535 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002536 */
Adam Jackson13931572010-08-03 14:38:19 -04002537static int
2538add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2539 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002540{
Adam Jackson13931572010-08-03 14:38:19 -04002541 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002542 .connector = connector,
2543 .edid = edid,
2544 .preferred = 1,
2545 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002546 };
Dave Airlief453ba02008-11-07 14:05:41 -08002547
Adam Jackson13931572010-08-03 14:38:19 -04002548 if (closure.preferred && !version_greater(edid, 1, 3))
2549 closure.preferred =
2550 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002551
Adam Jackson13931572010-08-03 14:38:19 -04002552 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002553
Adam Jackson13931572010-08-03 14:38:19 -04002554 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002555}
Dave Airlief453ba02008-11-07 14:05:41 -08002556
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002557#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002558#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002559#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002560#define SPEAKER_BLOCK 0x04
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002561#define VIDEO_CAPABILITY_BLOCK 0x07
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002562#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02002563#define EDID_CEA_YCRCB444 (1 << 5)
2564#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002565#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002566
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002567/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002568 * Search EDID for CEA extension block.
2569 */
Dave Airlie40d9b042014-10-20 16:29:33 +10002570static u8 *drm_find_edid_extension(struct edid *edid, int ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002571{
2572 u8 *edid_ext = NULL;
2573 int i;
2574
2575 /* No EDID or EDID extensions */
2576 if (edid == NULL || edid->extensions == 0)
2577 return NULL;
2578
2579 /* Find CEA extension */
2580 for (i = 0; i < edid->extensions; i++) {
2581 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10002582 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002583 break;
2584 }
2585
2586 if (i == edid->extensions)
2587 return NULL;
2588
2589 return edid_ext;
2590}
2591
Dave Airlie40d9b042014-10-20 16:29:33 +10002592static u8 *drm_find_cea_extension(struct edid *edid)
2593{
2594 return drm_find_edid_extension(edid, CEA_EXT);
2595}
2596
2597static u8 *drm_find_displayid_extension(struct edid *edid)
2598{
2599 return drm_find_edid_extension(edid, DISPLAYID_EXT);
2600}
2601
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002602/*
2603 * Calculate the alternate clock for the CEA mode
2604 * (60Hz vs. 59.94Hz etc.)
2605 */
2606static unsigned int
2607cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2608{
2609 unsigned int clock = cea_mode->clock;
2610
2611 if (cea_mode->vrefresh % 6 != 0)
2612 return clock;
2613
2614 /*
2615 * edid_cea_modes contains the 59.94Hz
2616 * variant for 240 and 480 line modes,
2617 * and the 60Hz variant otherwise.
2618 */
2619 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002620 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002621 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03002622 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002623
2624 return clock;
2625}
2626
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002627static bool
2628cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
2629{
2630 /*
2631 * For certain VICs the spec allows the vertical
2632 * front porch to vary by one or two lines.
2633 *
2634 * cea_modes[] stores the variant with the shortest
2635 * vertical front porch. We can adjust the mode to
2636 * get the other variants by simply increasing the
2637 * vertical front porch length.
2638 */
2639 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
2640 edid_cea_modes[9].vtotal != 262 ||
2641 edid_cea_modes[12].vtotal != 262 ||
2642 edid_cea_modes[13].vtotal != 262 ||
2643 edid_cea_modes[23].vtotal != 312 ||
2644 edid_cea_modes[24].vtotal != 312 ||
2645 edid_cea_modes[27].vtotal != 312 ||
2646 edid_cea_modes[28].vtotal != 312);
2647
2648 if (((vic == 8 || vic == 9 ||
2649 vic == 12 || vic == 13) && mode->vtotal < 263) ||
2650 ((vic == 23 || vic == 24 ||
2651 vic == 27 || vic == 28) && mode->vtotal < 314)) {
2652 mode->vsync_start++;
2653 mode->vsync_end++;
2654 mode->vtotal++;
2655
2656 return true;
2657 }
2658
2659 return false;
2660}
2661
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002662static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
2663 unsigned int clock_tolerance)
2664{
Jani Nikulad9278b42016-01-08 13:21:51 +02002665 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002666
2667 if (!to_match->clock)
2668 return 0;
2669
Jani Nikulad9278b42016-01-08 13:21:51 +02002670 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002671 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002672 unsigned int clock1, clock2;
2673
2674 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002675 clock1 = cea_mode.clock;
2676 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002677
2678 if (abs(to_match->clock - clock1) > clock_tolerance &&
2679 abs(to_match->clock - clock2) > clock_tolerance)
2680 continue;
2681
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002682 do {
2683 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2684 return vic;
2685 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002686 }
2687
2688 return 0;
2689}
2690
Thierry Reding18316c82012-12-20 15:41:44 +01002691/**
2692 * drm_match_cea_mode - look for a CEA mode matching given mode
2693 * @to_match: display mode
2694 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002695 * 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 +01002696 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00002697 */
Thierry Reding18316c82012-12-20 15:41:44 +01002698u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00002699{
Jani Nikulad9278b42016-01-08 13:21:51 +02002700 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00002701
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002702 if (!to_match->clock)
2703 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00002704
Jani Nikulad9278b42016-01-08 13:21:51 +02002705 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002706 struct drm_display_mode cea_mode = edid_cea_modes[vic];
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002707 unsigned int clock1, clock2;
2708
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002709 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002710 clock1 = cea_mode.clock;
2711 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002712
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002713 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
2714 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
2715 continue;
2716
2717 do {
2718 if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
2719 return vic;
2720 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00002721 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02002722
Stephane Marchesina4799032012-11-09 16:21:05 +00002723 return 0;
2724}
2725EXPORT_SYMBOL(drm_match_cea_mode);
2726
Jani Nikulad9278b42016-01-08 13:21:51 +02002727static bool drm_valid_cea_vic(u8 vic)
2728{
2729 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
2730}
2731
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302732/**
2733 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2734 * the input VIC from the CEA mode list
2735 * @video_code: ID given to each of the CEA modes
2736 *
2737 * Returns picture aspect ratio
2738 */
2739enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
2740{
Jani Nikulad9278b42016-01-08 13:21:51 +02002741 return edid_cea_modes[video_code].picture_aspect_ratio;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302742}
2743EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
2744
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002745/*
2746 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
2747 * specific block).
2748 *
2749 * It's almost like cea_mode_alternate_clock(), we just need to add an
2750 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
2751 * one.
2752 */
2753static unsigned int
2754hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
2755{
2756 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
2757 return hdmi_mode->clock;
2758
2759 return cea_mode_alternate_clock(hdmi_mode);
2760}
2761
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002762static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
2763 unsigned int clock_tolerance)
2764{
Jani Nikulad9278b42016-01-08 13:21:51 +02002765 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002766
2767 if (!to_match->clock)
2768 return 0;
2769
Jani Nikulad9278b42016-01-08 13:21:51 +02002770 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
2771 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002772 unsigned int clock1, clock2;
2773
2774 /* Make sure to also match alternate clocks */
2775 clock1 = hdmi_mode->clock;
2776 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
2777
2778 if (abs(to_match->clock - clock1) > clock_tolerance &&
2779 abs(to_match->clock - clock2) > clock_tolerance)
2780 continue;
2781
2782 if (drm_mode_equal_no_clocks(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02002783 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02002784 }
2785
2786 return 0;
2787}
2788
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002789/*
2790 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
2791 * @to_match: display mode
2792 *
2793 * An HDMI mode is one defined in the HDMI vendor specific block.
2794 *
2795 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
2796 */
2797static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
2798{
Jani Nikulad9278b42016-01-08 13:21:51 +02002799 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002800
2801 if (!to_match->clock)
2802 return 0;
2803
Jani Nikulad9278b42016-01-08 13:21:51 +02002804 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
2805 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002806 unsigned int clock1, clock2;
2807
2808 /* Make sure to also match alternate clocks */
2809 clock1 = hdmi_mode->clock;
2810 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
2811
2812 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
2813 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01002814 drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
Jani Nikulad9278b42016-01-08 13:21:51 +02002815 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002816 }
2817 return 0;
2818}
2819
Jani Nikulad9278b42016-01-08 13:21:51 +02002820static bool drm_valid_hdmi_vic(u8 vic)
2821{
2822 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
2823}
2824
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002825static int
2826add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
2827{
2828 struct drm_device *dev = connector->dev;
2829 struct drm_display_mode *mode, *tmp;
2830 LIST_HEAD(list);
2831 int modes = 0;
2832
2833 /* Don't add CEA modes if the CEA extension block is missing */
2834 if (!drm_find_cea_extension(edid))
2835 return 0;
2836
2837 /*
2838 * Go through all probed modes and create a new mode
2839 * with the alternate clock for certain CEA modes.
2840 */
2841 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002842 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002843 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02002844 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002845 unsigned int clock1, clock2;
2846
Jani Nikulad9278b42016-01-08 13:21:51 +02002847 if (drm_valid_cea_vic(vic)) {
2848 cea_mode = &edid_cea_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002849 clock2 = cea_mode_alternate_clock(cea_mode);
2850 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02002851 vic = drm_match_hdmi_mode(mode);
2852 if (drm_valid_hdmi_vic(vic)) {
2853 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002854 clock2 = hdmi_mode_alternate_clock(cea_mode);
2855 }
2856 }
2857
2858 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002859 continue;
2860
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002861 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002862
2863 if (clock1 == clock2)
2864 continue;
2865
2866 if (mode->clock != clock1 && mode->clock != clock2)
2867 continue;
2868
2869 newmode = drm_mode_duplicate(dev, cea_mode);
2870 if (!newmode)
2871 continue;
2872
Damien Lespiau27130212013-09-25 16:45:28 +01002873 /* Carry over the stereo flags */
2874 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
2875
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002876 /*
2877 * The current mode could be either variant. Make
2878 * sure to pick the "other" clock for the new mode.
2879 */
2880 if (mode->clock != clock1)
2881 newmode->clock = clock1;
2882 else
2883 newmode->clock = clock2;
2884
2885 list_add_tail(&newmode->head, &list);
2886 }
2887
2888 list_for_each_entry_safe(mode, tmp, &list, head) {
2889 list_del(&mode->head);
2890 drm_mode_probed_add(connector, mode);
2891 modes++;
2892 }
2893
2894 return modes;
2895}
Stephane Marchesina4799032012-11-09 16:21:05 +00002896
Thomas Woodaff04ac2013-11-29 15:33:27 +00002897static struct drm_display_mode *
2898drm_display_mode_from_vic_index(struct drm_connector *connector,
2899 const u8 *video_db, u8 video_len,
2900 u8 video_index)
2901{
2902 struct drm_device *dev = connector->dev;
2903 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02002904 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00002905
2906 if (video_db == NULL || video_index >= video_len)
2907 return NULL;
2908
2909 /* CEA modes are numbered 1..127 */
Jani Nikulad9278b42016-01-08 13:21:51 +02002910 vic = (video_db[video_index] & 127);
2911 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00002912 return NULL;
2913
Jani Nikulad9278b42016-01-08 13:21:51 +02002914 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00002915 if (!newmode)
2916 return NULL;
2917
Thomas Woodaff04ac2013-11-29 15:33:27 +00002918 newmode->vrefresh = 0;
2919
2920 return newmode;
2921}
2922
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002923static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01002924do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002925{
Thomas Woodaff04ac2013-11-29 15:33:27 +00002926 int i, modes = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002927
Thomas Woodaff04ac2013-11-29 15:33:27 +00002928 for (i = 0; i < len; i++) {
2929 struct drm_display_mode *mode;
2930 mode = drm_display_mode_from_vic_index(connector, db, len, i);
2931 if (mode) {
2932 drm_mode_probed_add(connector, mode);
2933 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002934 }
2935 }
2936
2937 return modes;
2938}
2939
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002940struct stereo_mandatory_mode {
2941 int width, height, vrefresh;
2942 unsigned int flags;
2943};
2944
2945static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002946 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2947 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002948 { 1920, 1080, 50,
2949 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
2950 { 1920, 1080, 60,
2951 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002952 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2953 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
2954 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2955 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002956};
2957
2958static bool
2959stereo_match_mandatory(const struct drm_display_mode *mode,
2960 const struct stereo_mandatory_mode *stereo_mode)
2961{
2962 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
2963
2964 return mode->hdisplay == stereo_mode->width &&
2965 mode->vdisplay == stereo_mode->height &&
2966 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
2967 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
2968}
2969
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002970static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
2971{
2972 struct drm_device *dev = connector->dev;
2973 const struct drm_display_mode *mode;
2974 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002975 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002976
2977 INIT_LIST_HEAD(&stereo_modes);
2978
2979 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002980 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
2981 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002982 struct drm_display_mode *new_mode;
2983
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002984 if (!stereo_match_mandatory(mode,
2985 &stereo_mandatory_modes[i]))
2986 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002987
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002988 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002989 new_mode = drm_mode_duplicate(dev, mode);
2990 if (!new_mode)
2991 continue;
2992
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002993 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002994 list_add_tail(&new_mode->head, &stereo_modes);
2995 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002996 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002997 }
2998
2999 list_splice_tail(&stereo_modes, &connector->probed_modes);
3000
3001 return modes;
3002}
3003
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003004static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3005{
3006 struct drm_device *dev = connector->dev;
3007 struct drm_display_mode *newmode;
3008
Jani Nikulad9278b42016-01-08 13:21:51 +02003009 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003010 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3011 return 0;
3012 }
3013
3014 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3015 if (!newmode)
3016 return 0;
3017
3018 drm_mode_probed_add(connector, newmode);
3019
3020 return 1;
3021}
3022
Thomas Woodfbf46022013-10-16 15:58:50 +01003023static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3024 const u8 *video_db, u8 video_len, u8 video_index)
3025{
Thomas Woodfbf46022013-10-16 15:58:50 +01003026 struct drm_display_mode *newmode;
3027 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003028
3029 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003030 newmode = drm_display_mode_from_vic_index(connector, video_db,
3031 video_len,
3032 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003033 if (newmode) {
3034 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3035 drm_mode_probed_add(connector, newmode);
3036 modes++;
3037 }
3038 }
3039 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003040 newmode = drm_display_mode_from_vic_index(connector, video_db,
3041 video_len,
3042 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003043 if (newmode) {
3044 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3045 drm_mode_probed_add(connector, newmode);
3046 modes++;
3047 }
3048 }
3049 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003050 newmode = drm_display_mode_from_vic_index(connector, video_db,
3051 video_len,
3052 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003053 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003054 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003055 drm_mode_probed_add(connector, newmode);
3056 modes++;
3057 }
3058 }
3059
3060 return modes;
3061}
3062
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003063/*
3064 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3065 * @connector: connector corresponding to the HDMI sink
3066 * @db: start of the CEA vendor specific block
3067 * @len: length of the CEA block payload, ie. one can access up to db[len]
3068 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003069 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3070 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003071 */
3072static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003073do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3074 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003075{
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003076 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003077 u8 vic_len, hdmi_3d_len = 0;
3078 u16 mask;
3079 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003080
3081 if (len < 8)
3082 goto out;
3083
3084 /* no HDMI_Video_Present */
3085 if (!(db[8] & (1 << 5)))
3086 goto out;
3087
3088 /* Latency_Fields_Present */
3089 if (db[8] & (1 << 7))
3090 offset += 2;
3091
3092 /* I_Latency_Fields_Present */
3093 if (db[8] & (1 << 6))
3094 offset += 2;
3095
3096 /* the declared length is not long enough for the 2 first bytes
3097 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003098 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003099 goto out;
3100
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003101 /* 3D_Present */
3102 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003103 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003104 modes += add_hdmi_mandatory_stereo_modes(connector);
3105
Thomas Woodfbf46022013-10-16 15:58:50 +01003106 /* 3D_Multi_present */
3107 multi_present = (db[8 + offset] & 0x60) >> 5;
3108 }
3109
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003110 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003111 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01003112 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003113
3114 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003115 u8 vic;
3116
3117 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003118 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003119 }
Thomas Woodfbf46022013-10-16 15:58:50 +01003120 offset += 1 + vic_len;
3121
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003122 if (multi_present == 1)
3123 multi_len = 2;
3124 else if (multi_present == 2)
3125 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01003126 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003127 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003128
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003129 if (len < (8 + offset + hdmi_3d_len - 1))
3130 goto out;
3131
3132 if (hdmi_3d_len < multi_len)
3133 goto out;
3134
3135 if (multi_present == 1 || multi_present == 2) {
3136 /* 3D_Structure_ALL */
3137 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3138
3139 /* check if 3D_MASK is present */
3140 if (multi_present == 2)
3141 mask = (db[10 + offset] << 8) | db[11 + offset];
3142 else
3143 mask = 0xffff;
3144
3145 for (i = 0; i < 16; i++) {
3146 if (mask & (1 << i))
3147 modes += add_3d_struct_modes(connector,
3148 structure_all,
3149 video_db,
3150 video_len, i);
3151 }
3152 }
3153
3154 offset += multi_len;
3155
3156 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3157 int vic_index;
3158 struct drm_display_mode *newmode = NULL;
3159 unsigned int newflag = 0;
3160 bool detail_present;
3161
3162 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3163
3164 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3165 break;
3166
3167 /* 2D_VIC_order_X */
3168 vic_index = db[8 + offset + i] >> 4;
3169
3170 /* 3D_Structure_X */
3171 switch (db[8 + offset + i] & 0x0f) {
3172 case 0:
3173 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3174 break;
3175 case 6:
3176 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3177 break;
3178 case 8:
3179 /* 3D_Detail_X */
3180 if ((db[9 + offset + i] >> 4) == 1)
3181 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3182 break;
3183 }
3184
3185 if (newflag != 0) {
3186 newmode = drm_display_mode_from_vic_index(connector,
3187 video_db,
3188 video_len,
3189 vic_index);
3190
3191 if (newmode) {
3192 newmode->flags |= newflag;
3193 drm_mode_probed_add(connector, newmode);
3194 modes++;
3195 }
3196 }
3197
3198 if (detail_present)
3199 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01003200 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003201
3202out:
3203 return modes;
3204}
3205
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003206static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003207cea_db_payload_len(const u8 *db)
3208{
3209 return db[0] & 0x1f;
3210}
3211
3212static int
3213cea_db_tag(const u8 *db)
3214{
3215 return db[0] >> 5;
3216}
3217
3218static int
3219cea_revision(const u8 *cea)
3220{
3221 return cea[1];
3222}
3223
3224static int
3225cea_db_offsets(const u8 *cea, int *start, int *end)
3226{
3227 /* Data block offset in CEA extension block */
3228 *start = 4;
3229 *end = cea[2];
3230 if (*end == 0)
3231 *end = 127;
3232 if (*end < 4 || *end > 127)
3233 return -ERANGE;
3234 return 0;
3235}
3236
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003237static bool cea_db_is_hdmi_vsdb(const u8 *db)
3238{
3239 int hdmi_id;
3240
3241 if (cea_db_tag(db) != VENDOR_BLOCK)
3242 return false;
3243
3244 if (cea_db_payload_len(db) < 5)
3245 return false;
3246
3247 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3248
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01003249 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003250}
3251
Thierry Reding50dd1bd2017-03-13 16:54:00 +05303252static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3253{
3254 unsigned int oui;
3255
3256 if (cea_db_tag(db) != VENDOR_BLOCK)
3257 return false;
3258
3259 if (cea_db_payload_len(db) < 7)
3260 return false;
3261
3262 oui = db[3] << 16 | db[2] << 8 | db[1];
3263
3264 return oui == HDMI_FORUM_IEEE_OUI;
3265}
3266
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003267#define for_each_cea_db(cea, i, start, end) \
3268 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3269
3270static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003271add_cea_modes(struct drm_connector *connector, struct edid *edid)
3272{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003273 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01003274 const u8 *db, *hdmi = NULL, *video = NULL;
3275 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003276 int modes = 0;
3277
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003278 if (cea && cea_revision(cea) >= 3) {
3279 int i, start, end;
3280
3281 if (cea_db_offsets(cea, &start, &end))
3282 return 0;
3283
3284 for_each_cea_db(cea, i, start, end) {
3285 db = &cea[i];
3286 dbl = cea_db_payload_len(db);
3287
Thomas Woodfbf46022013-10-16 15:58:50 +01003288 if (cea_db_tag(db) == VIDEO_BLOCK) {
3289 video = db + 1;
3290 video_len = dbl;
3291 modes += do_cea_modes(connector, video, dbl);
3292 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003293 else if (cea_db_is_hdmi_vsdb(db)) {
3294 hdmi = db;
3295 hdmi_len = dbl;
3296 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003297 }
3298 }
3299
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003300 /*
3301 * We parse the HDMI VSDB after having added the cea modes as we will
3302 * be patching their flags when the sink supports stereo 3D.
3303 */
3304 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003305 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3306 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003307
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003308 return modes;
3309}
3310
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003311static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3312{
3313 const struct drm_display_mode *cea_mode;
3314 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02003315 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003316 const char *type;
3317
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003318 /*
3319 * allow 5kHz clock difference either way to account for
3320 * the 10kHz clock resolution limit of detailed timings.
3321 */
Jani Nikulad9278b42016-01-08 13:21:51 +02003322 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
3323 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003324 type = "CEA";
Jani Nikulad9278b42016-01-08 13:21:51 +02003325 cea_mode = &edid_cea_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003326 clock1 = cea_mode->clock;
3327 clock2 = cea_mode_alternate_clock(cea_mode);
3328 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003329 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
3330 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003331 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02003332 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003333 clock1 = cea_mode->clock;
3334 clock2 = hdmi_mode_alternate_clock(cea_mode);
3335 } else {
3336 return;
3337 }
3338 }
3339
3340 /* pick whichever is closest */
3341 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
3342 clock = clock1;
3343 else
3344 clock = clock2;
3345
3346 if (mode->clock == clock)
3347 return;
3348
3349 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02003350 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003351 mode->clock = clock;
3352}
3353
Wu Fengguang76adaa342011-09-05 14:23:20 +08003354static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003355drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003356{
Ville Syrjälä85040722012-08-16 14:55:05 +00003357 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003358
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003359 if (len >= 6)
Ville Syrjälä85040722012-08-16 14:55:05 +00003360 connector->eld[5] |= (db[6] >> 7) << 1; /* Supports_AI */
Ville Syrjälä85040722012-08-16 14:55:05 +00003361 if (len >= 8) {
3362 connector->latency_present[0] = db[8] >> 7;
3363 connector->latency_present[1] = (db[8] >> 6) & 1;
3364 }
3365 if (len >= 9)
3366 connector->video_latency[0] = db[9];
3367 if (len >= 10)
3368 connector->audio_latency[0] = db[10];
3369 if (len >= 11)
3370 connector->video_latency[1] = db[11];
3371 if (len >= 12)
3372 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003373
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003374 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
3375 "video latency %d %d, "
3376 "audio latency %d %d\n",
3377 connector->latency_present[0],
3378 connector->latency_present[1],
3379 connector->video_latency[0],
3380 connector->video_latency[1],
3381 connector->audio_latency[0],
3382 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003383}
3384
3385static void
3386monitor_name(struct detailed_timing *t, void *data)
3387{
3388 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
3389 *(u8 **)data = t->data.other_data.data.str.str;
3390}
3391
Jim Bride59f7c0f2016-04-14 10:18:35 -07003392static int get_monitor_name(struct edid *edid, char name[13])
3393{
3394 char *edid_name = NULL;
3395 int mnl;
3396
3397 if (!edid || !name)
3398 return 0;
3399
3400 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
3401 for (mnl = 0; edid_name && mnl < 13; mnl++) {
3402 if (edid_name[mnl] == 0x0a)
3403 break;
3404
3405 name[mnl] = edid_name[mnl];
3406 }
3407
3408 return mnl;
3409}
3410
3411/**
3412 * drm_edid_get_monitor_name - fetch the monitor name from the edid
3413 * @edid: monitor EDID information
3414 * @name: pointer to a character array to hold the name of the monitor
3415 * @bufsize: The size of the name buffer (should be at least 14 chars.)
3416 *
3417 */
3418void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
3419{
3420 int name_length;
3421 char buf[13];
3422
3423 if (bufsize <= 0)
3424 return;
3425
3426 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
3427 memcpy(name, buf, name_length);
3428 name[name_length] = '\0';
3429}
3430EXPORT_SYMBOL(drm_edid_get_monitor_name);
3431
Wu Fengguang76adaa342011-09-05 14:23:20 +08003432/**
3433 * drm_edid_to_eld - build ELD from EDID
3434 * @connector: connector corresponding to the HDMI/DP sink
3435 * @edid: EDID to parse
3436 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003437 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
3438 * Conn_Type, HDCP and Port_ID ELD fields are left for the graphics driver to
3439 * fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003440 */
3441void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
3442{
3443 uint8_t *eld = connector->eld;
3444 u8 *cea;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003445 u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02003446 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003447 int mnl;
3448 int dbl;
3449
3450 memset(eld, 0, sizeof(connector->eld));
3451
Ville Syrjälä85c91582016-09-28 16:51:34 +03003452 connector->latency_present[0] = false;
3453 connector->latency_present[1] = false;
3454 connector->video_latency[0] = 0;
3455 connector->audio_latency[0] = 0;
3456 connector->video_latency[1] = 0;
3457 connector->audio_latency[1] = 0;
3458
Jani Nikulae9bd0b82017-02-17 17:20:52 +02003459 if (!edid)
3460 return;
3461
Wu Fengguang76adaa342011-09-05 14:23:20 +08003462 cea = drm_find_cea_extension(edid);
3463 if (!cea) {
3464 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3465 return;
3466 }
3467
Jim Bride59f7c0f2016-04-14 10:18:35 -07003468 mnl = get_monitor_name(edid, eld + 20);
3469
Wu Fengguang76adaa342011-09-05 14:23:20 +08003470 eld[4] = (cea[1] << 5) | mnl;
3471 DRM_DEBUG_KMS("ELD monitor %s\n", eld + 20);
3472
3473 eld[0] = 2 << 3; /* ELD version: 2 */
3474
3475 eld[16] = edid->mfg_id[0];
3476 eld[17] = edid->mfg_id[1];
3477 eld[18] = edid->prod_code[0];
3478 eld[19] = edid->prod_code[1];
3479
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003480 if (cea_revision(cea) >= 3) {
3481 int i, start, end;
3482
3483 if (cea_db_offsets(cea, &start, &end)) {
3484 start = 0;
3485 end = 0;
3486 }
3487
3488 for_each_cea_db(cea, i, start, end) {
3489 db = &cea[i];
3490 dbl = cea_db_payload_len(db);
3491
3492 switch (cea_db_tag(db)) {
Ville Syrjälä7c018782016-03-09 22:07:46 +02003493 int sad_count;
3494
Christian Schmidta0ab7342011-12-19 20:03:38 +01003495 case AUDIO_BLOCK:
3496 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02003497 sad_count = min(dbl / 3, 15 - total_sad_count);
3498 if (sad_count >= 1)
3499 memcpy(eld + 20 + mnl + total_sad_count * 3,
3500 &db[1], sad_count * 3);
3501 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01003502 break;
3503 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003504 /* Speaker Allocation Data Block */
3505 if (dbl >= 1)
3506 eld[7] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01003507 break;
3508 case VENDOR_BLOCK:
3509 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003510 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003511 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01003512 break;
3513 default:
3514 break;
3515 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003516 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003517 }
Ville Syrjälä7c018782016-03-09 22:07:46 +02003518 eld[5] |= total_sad_count << 4;
Wu Fengguang76adaa342011-09-05 14:23:20 +08003519
Jani Nikula938fd8a2014-10-28 16:20:48 +02003520 eld[DRM_ELD_BASELINE_ELD_LEN] =
3521 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
3522
3523 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02003524 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003525}
3526EXPORT_SYMBOL(drm_edid_to_eld);
3527
3528/**
Rafał Miłeckife214162013-04-19 19:01:25 +02003529 * drm_edid_to_sad - extracts SADs from EDID
3530 * @edid: EDID to parse
3531 * @sads: pointer that will be set to the extracted SADs
3532 *
3533 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02003534 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003535 * Note: The returned pointer needs to be freed using kfree().
3536 *
3537 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02003538 */
3539int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
3540{
3541 int count = 0;
3542 int i, start, end, dbl;
3543 u8 *cea;
3544
3545 cea = drm_find_cea_extension(edid);
3546 if (!cea) {
3547 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3548 return -ENOENT;
3549 }
3550
3551 if (cea_revision(cea) < 3) {
3552 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3553 return -ENOTSUPP;
3554 }
3555
3556 if (cea_db_offsets(cea, &start, &end)) {
3557 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3558 return -EPROTO;
3559 }
3560
3561 for_each_cea_db(cea, i, start, end) {
3562 u8 *db = &cea[i];
3563
3564 if (cea_db_tag(db) == AUDIO_BLOCK) {
3565 int j;
3566 dbl = cea_db_payload_len(db);
3567
3568 count = dbl / 3; /* SAD is 3B */
3569 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
3570 if (!*sads)
3571 return -ENOMEM;
3572 for (j = 0; j < count; j++) {
3573 u8 *sad = &db[1 + j * 3];
3574
3575 (*sads)[j].format = (sad[0] & 0x78) >> 3;
3576 (*sads)[j].channels = sad[0] & 0x7;
3577 (*sads)[j].freq = sad[1] & 0x7F;
3578 (*sads)[j].byte2 = sad[2];
3579 }
3580 break;
3581 }
3582 }
3583
3584 return count;
3585}
3586EXPORT_SYMBOL(drm_edid_to_sad);
3587
3588/**
Alex Deucherd105f472013-07-25 15:55:32 -04003589 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
3590 * @edid: EDID to parse
3591 * @sadb: pointer to the speaker block
3592 *
3593 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04003594 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003595 * Note: The returned pointer needs to be freed using kfree().
3596 *
3597 * Return: The number of found Speaker Allocation Blocks or negative number on
3598 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04003599 */
3600int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
3601{
3602 int count = 0;
3603 int i, start, end, dbl;
3604 const u8 *cea;
3605
3606 cea = drm_find_cea_extension(edid);
3607 if (!cea) {
3608 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3609 return -ENOENT;
3610 }
3611
3612 if (cea_revision(cea) < 3) {
3613 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3614 return -ENOTSUPP;
3615 }
3616
3617 if (cea_db_offsets(cea, &start, &end)) {
3618 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3619 return -EPROTO;
3620 }
3621
3622 for_each_cea_db(cea, i, start, end) {
3623 const u8 *db = &cea[i];
3624
3625 if (cea_db_tag(db) == SPEAKER_BLOCK) {
3626 dbl = cea_db_payload_len(db);
3627
3628 /* Speaker Allocation Data Block */
3629 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02003630 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04003631 if (!*sadb)
3632 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04003633 count = dbl;
3634 break;
3635 }
3636 }
3637 }
3638
3639 return count;
3640}
3641EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
3642
3643/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003644 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08003645 * @connector: connector associated with the HDMI/DP sink
3646 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003647 *
3648 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
3649 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003650 */
3651int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03003652 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003653{
3654 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
3655 int a, v;
3656
3657 if (!connector->latency_present[0])
3658 return 0;
3659 if (!connector->latency_present[1])
3660 i = 0;
3661
3662 a = connector->audio_latency[i];
3663 v = connector->video_latency[i];
3664
3665 /*
3666 * HDMI/DP sink doesn't support audio or video?
3667 */
3668 if (a == 255 || v == 255)
3669 return 0;
3670
3671 /*
3672 * Convert raw EDID values to millisecond.
3673 * Treat unknown latency as 0ms.
3674 */
3675 if (a)
3676 a = min(2 * (a - 1), 500);
3677 if (v)
3678 v = min(2 * (v - 1), 500);
3679
3680 return max(v - a, 0);
3681}
3682EXPORT_SYMBOL(drm_av_sync_delay);
3683
3684/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003685 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08003686 * @edid: monitor EDID information
3687 *
3688 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003689 *
3690 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08003691 */
3692bool drm_detect_hdmi_monitor(struct edid *edid)
3693{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003694 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003695 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08003696 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08003697
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003698 edid_ext = drm_find_cea_extension(edid);
3699 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003700 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003701
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003702 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003703 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003704
3705 /*
3706 * Because HDMI identifier is in Vendor Specific Block,
3707 * search it from all data blocks of CEA extension.
3708 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003709 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003710 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
3711 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08003712 }
3713
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003714 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003715}
3716EXPORT_SYMBOL(drm_detect_hdmi_monitor);
3717
Dave Airlief453ba02008-11-07 14:05:41 -08003718/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003719 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01003720 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003721 *
3722 * Monitor should have CEA extension block.
3723 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
3724 * audio' only. If there is any audio extension block and supported
3725 * audio format, assume at least 'basic audio' support, even if 'basic
3726 * audio' is not defined in EDID.
3727 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003728 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003729 */
3730bool drm_detect_monitor_audio(struct edid *edid)
3731{
3732 u8 *edid_ext;
3733 int i, j;
3734 bool has_audio = false;
3735 int start_offset, end_offset;
3736
3737 edid_ext = drm_find_cea_extension(edid);
3738 if (!edid_ext)
3739 goto end;
3740
3741 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
3742
3743 if (has_audio) {
3744 DRM_DEBUG_KMS("Monitor has basic audio support\n");
3745 goto end;
3746 }
3747
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003748 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
3749 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003750
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003751 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
3752 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003753 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003754 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003755 DRM_DEBUG_KMS("CEA audio format %d\n",
3756 (edid_ext[i + j] >> 3) & 0xf);
3757 goto end;
3758 }
3759 }
3760end:
3761 return has_audio;
3762}
3763EXPORT_SYMBOL(drm_detect_monitor_audio);
3764
3765/**
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003766 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
Daniel Vetterfc668112014-01-21 12:02:26 +01003767 * @edid: EDID block to scan
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003768 *
3769 * Check whether the monitor reports the RGB quantization range selection
3770 * as supported. The AVI infoframe can then be used to inform the monitor
3771 * which quantization range (full or limited) is used.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003772 *
3773 * Return: True if the RGB quantization range is selectable, false otherwise.
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003774 */
3775bool drm_rgb_quant_range_selectable(struct edid *edid)
3776{
3777 u8 *edid_ext;
3778 int i, start, end;
3779
3780 edid_ext = drm_find_cea_extension(edid);
3781 if (!edid_ext)
3782 return false;
3783
3784 if (cea_db_offsets(edid_ext, &start, &end))
3785 return false;
3786
3787 for_each_cea_db(edid_ext, i, start, end) {
3788 if (cea_db_tag(&edid_ext[i]) == VIDEO_CAPABILITY_BLOCK &&
3789 cea_db_payload_len(&edid_ext[i]) == 2) {
3790 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
3791 return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
3792 }
3793 }
3794
3795 return false;
3796}
3797EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
3798
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02003799/**
3800 * drm_default_rgb_quant_range - default RGB quantization range
3801 * @mode: display mode
3802 *
3803 * Determine the default RGB quantization range for the mode,
3804 * as specified in CEA-861.
3805 *
3806 * Return: The default RGB quantization range for the mode
3807 */
3808enum hdmi_quantization_range
3809drm_default_rgb_quant_range(const struct drm_display_mode *mode)
3810{
3811 /* All CEA modes other than VIC 1 use limited quantization range. */
3812 return drm_match_cea_mode(mode) > 1 ?
3813 HDMI_QUANTIZATION_RANGE_LIMITED :
3814 HDMI_QUANTIZATION_RANGE_FULL;
3815}
3816EXPORT_SYMBOL(drm_default_rgb_quant_range);
3817
Shashank Sharmaafa1c762017-03-13 16:54:01 +05303818static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
3819 const u8 *hf_vsdb)
3820{
Shashank Sharma62c58af2017-03-13 16:54:02 +05303821 struct drm_display_info *display = &connector->display_info;
3822 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05303823
3824 if (hf_vsdb[6] & 0x80) {
3825 hdmi->scdc.supported = true;
3826 if (hf_vsdb[6] & 0x40)
3827 hdmi->scdc.read_request = true;
3828 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05303829
3830 /*
3831 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
3832 * And as per the spec, three factors confirm this:
3833 * * Availability of a HF-VSDB block in EDID (check)
3834 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
3835 * * SCDC support available (let's check)
3836 * Lets check it out.
3837 */
3838
3839 if (hf_vsdb[5]) {
3840 /* max clock is 5000 KHz times block value */
3841 u32 max_tmds_clock = hf_vsdb[5] * 5000;
3842 struct drm_scdc *scdc = &hdmi->scdc;
3843
3844 if (max_tmds_clock > 340000) {
3845 display->max_tmds_clock = max_tmds_clock;
3846 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
3847 display->max_tmds_clock);
3848 }
3849
3850 if (scdc->supported) {
3851 scdc->scrambling.supported = true;
3852
3853 /* Few sinks support scrambling for cloks < 340M */
3854 if ((hf_vsdb[6] & 0x8))
3855 scdc->scrambling.low_rates = true;
3856 }
3857 }
Shashank Sharmaafa1c762017-03-13 16:54:01 +05303858}
3859
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003860static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
3861 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01003862{
Ville Syrjälä18267502016-09-28 16:51:38 +03003863 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01003864 unsigned int dc_bpc = 0;
3865
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003866 /* HDMI supports at least 8 bpc */
3867 info->bpc = 8;
3868
3869 if (cea_db_payload_len(hdmi) < 6)
3870 return;
3871
3872 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
3873 dc_bpc = 10;
3874 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
3875 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
3876 connector->name);
3877 }
3878
3879 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
3880 dc_bpc = 12;
3881 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
3882 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
3883 connector->name);
3884 }
3885
3886 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
3887 dc_bpc = 16;
3888 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
3889 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
3890 connector->name);
3891 }
3892
3893 if (dc_bpc == 0) {
3894 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
3895 connector->name);
3896 return;
3897 }
3898
3899 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
3900 connector->name, dc_bpc);
3901 info->bpc = dc_bpc;
3902
3903 /*
3904 * Deep color support mandates RGB444 support for all video
3905 * modes and forbids YCRCB422 support for all video modes per
3906 * HDMI 1.3 spec.
3907 */
3908 info->color_formats = DRM_COLOR_FORMAT_RGB444;
3909
3910 /* YCRCB444 is optional according to spec. */
3911 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
3912 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3913 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
3914 connector->name);
3915 }
3916
3917 /*
3918 * Spec says that if any deep color mode is supported at all,
3919 * then deep color 36 bit must be supported.
3920 */
3921 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
3922 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
3923 connector->name);
3924 }
3925}
3926
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003927static void
3928drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
3929{
3930 struct drm_display_info *info = &connector->display_info;
3931 u8 len = cea_db_payload_len(db);
3932
3933 if (len >= 6)
3934 info->dvi_dual = db[6] & 1;
3935 if (len >= 7)
3936 info->max_tmds_clock = db[7] * 5000;
3937
3938 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
3939 "max TMDS clock %d kHz\n",
3940 info->dvi_dual,
3941 info->max_tmds_clock);
3942
3943 drm_parse_hdmi_deep_color_info(connector, db);
3944}
3945
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003946static void drm_parse_cea_ext(struct drm_connector *connector,
3947 struct edid *edid)
3948{
3949 struct drm_display_info *info = &connector->display_info;
3950 const u8 *edid_ext;
3951 int i, start, end;
3952
Mario Kleinerd0c94692014-03-27 19:59:39 +01003953 edid_ext = drm_find_cea_extension(edid);
3954 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003955 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01003956
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003957 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01003958
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003959 /* The existence of a CEA block should imply RGB support */
3960 info->color_formats = DRM_COLOR_FORMAT_RGB444;
3961 if (edid_ext[3] & EDID_CEA_YCRCB444)
3962 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3963 if (edid_ext[3] & EDID_CEA_YCRCB422)
3964 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01003965
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003966 if (cea_db_offsets(edid_ext, &start, &end))
3967 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01003968
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003969 for_each_cea_db(edid_ext, i, start, end) {
3970 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01003971
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003972 if (cea_db_is_hdmi_vsdb(db))
3973 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05303974 if (cea_db_is_hdmi_forum_vsdb(db))
3975 drm_parse_hdmi_forum_vsdb(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003976 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01003977}
3978
Ville Syrjälä1cea1462016-09-28 16:51:39 +03003979static void drm_add_display_info(struct drm_connector *connector,
3980 struct edid *edid)
Jesse Barnes3b112282011-04-15 12:49:23 -07003981{
Ville Syrjälä18267502016-09-28 16:51:38 +03003982 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07003983
Jesse Barnes3b112282011-04-15 12:49:23 -07003984 info->width_mm = edid->width_cm * 10;
3985 info->height_mm = edid->height_cm * 10;
3986
3987 /* driver figures it out in this case */
3988 info->bpc = 0;
Jesse Barnesda05a5a72011-04-15 13:48:57 -07003989 info->color_formats = 0;
Ville Syrjälä011acce2016-09-28 16:51:40 +03003990 info->cea_rev = 0;
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03003991 info->max_tmds_clock = 0;
3992 info->dvi_dual = false;
Jesse Barnes3b112282011-04-15 12:49:23 -07003993
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003994 if (edid->revision < 3)
Jesse Barnes3b112282011-04-15 12:49:23 -07003995 return;
3996
3997 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
3998 return;
3999
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004000 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004001
Mario Kleiner210a0212016-07-06 12:05:48 +02004002 /*
4003 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4004 *
4005 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4006 * tells us to assume 8 bpc color depth if the EDID doesn't have
4007 * extensions which tell otherwise.
4008 */
4009 if ((info->bpc == 0) && (edid->revision < 4) &&
4010 (edid->input & DRM_EDID_DIGITAL_TYPE_DVI)) {
4011 info->bpc = 8;
4012 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4013 connector->name, info->bpc);
4014 }
4015
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004016 /* Only defined for 1.4 with digital displays */
4017 if (edid->revision < 4)
4018 return;
4019
Jesse Barnes3b112282011-04-15 12:49:23 -07004020 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4021 case DRM_EDID_DIGITAL_DEPTH_6:
4022 info->bpc = 6;
4023 break;
4024 case DRM_EDID_DIGITAL_DEPTH_8:
4025 info->bpc = 8;
4026 break;
4027 case DRM_EDID_DIGITAL_DEPTH_10:
4028 info->bpc = 10;
4029 break;
4030 case DRM_EDID_DIGITAL_DEPTH_12:
4031 info->bpc = 12;
4032 break;
4033 case DRM_EDID_DIGITAL_DEPTH_14:
4034 info->bpc = 14;
4035 break;
4036 case DRM_EDID_DIGITAL_DEPTH_16:
4037 info->bpc = 16;
4038 break;
4039 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4040 default:
4041 info->bpc = 0;
4042 break;
4043 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07004044
Mario Kleinerd0c94692014-03-27 19:59:39 +01004045 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004046 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01004047
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02004048 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02004049 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4050 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4051 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4052 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Jesse Barnes3b112282011-04-15 12:49:23 -07004053}
4054
Dave Airliec97291772016-05-03 15:38:37 +10004055static int validate_displayid(u8 *displayid, int length, int idx)
4056{
4057 int i;
4058 u8 csum = 0;
4059 struct displayid_hdr *base;
4060
4061 base = (struct displayid_hdr *)&displayid[idx];
4062
4063 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4064 base->rev, base->bytes, base->prod_id, base->ext_count);
4065
4066 if (base->bytes + 5 > length - idx)
4067 return -EINVAL;
4068 for (i = idx; i <= base->bytes + 5; i++) {
4069 csum += displayid[i];
4070 }
4071 if (csum) {
Chris Wilson813a7872017-02-10 19:59:13 +00004072 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
Dave Airliec97291772016-05-03 15:38:37 +10004073 return -EINVAL;
4074 }
4075 return 0;
4076}
4077
Dave Airliea39ed682016-05-02 08:35:05 +10004078static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4079 struct displayid_detailed_timings_1 *timings)
4080{
4081 struct drm_display_mode *mode;
4082 unsigned pixel_clock = (timings->pixel_clock[0] |
4083 (timings->pixel_clock[1] << 8) |
4084 (timings->pixel_clock[2] << 16));
4085 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4086 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4087 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4088 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4089 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4090 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4091 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4092 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4093 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4094 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4095 mode = drm_mode_create(dev);
4096 if (!mode)
4097 return NULL;
4098
4099 mode->clock = pixel_clock * 10;
4100 mode->hdisplay = hactive;
4101 mode->hsync_start = mode->hdisplay + hsync;
4102 mode->hsync_end = mode->hsync_start + hsync_width;
4103 mode->htotal = mode->hdisplay + hblank;
4104
4105 mode->vdisplay = vactive;
4106 mode->vsync_start = mode->vdisplay + vsync;
4107 mode->vsync_end = mode->vsync_start + vsync_width;
4108 mode->vtotal = mode->vdisplay + vblank;
4109
4110 mode->flags = 0;
4111 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4112 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4113 mode->type = DRM_MODE_TYPE_DRIVER;
4114
4115 if (timings->flags & 0x80)
4116 mode->type |= DRM_MODE_TYPE_PREFERRED;
4117 mode->vrefresh = drm_mode_vrefresh(mode);
4118 drm_mode_set_name(mode);
4119
4120 return mode;
4121}
4122
4123static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4124 struct displayid_block *block)
4125{
4126 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4127 int i;
4128 int num_timings;
4129 struct drm_display_mode *newmode;
4130 int num_modes = 0;
4131 /* blocks must be multiple of 20 bytes length */
4132 if (block->num_bytes % 20)
4133 return 0;
4134
4135 num_timings = block->num_bytes / 20;
4136 for (i = 0; i < num_timings; i++) {
4137 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4138
4139 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4140 if (!newmode)
4141 continue;
4142
4143 drm_mode_probed_add(connector, newmode);
4144 num_modes++;
4145 }
4146 return num_modes;
4147}
4148
4149static int add_displayid_detailed_modes(struct drm_connector *connector,
4150 struct edid *edid)
4151{
4152 u8 *displayid;
4153 int ret;
4154 int idx = 1;
4155 int length = EDID_LENGTH;
4156 struct displayid_block *block;
4157 int num_modes = 0;
4158
4159 displayid = drm_find_displayid_extension(edid);
4160 if (!displayid)
4161 return 0;
4162
4163 ret = validate_displayid(displayid, length, idx);
4164 if (ret)
4165 return 0;
4166
4167 idx += sizeof(struct displayid_hdr);
4168 while (block = (struct displayid_block *)&displayid[idx],
4169 idx + sizeof(struct displayid_block) <= length &&
4170 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
4171 block->num_bytes > 0) {
4172 idx += block->num_bytes + sizeof(struct displayid_block);
4173 switch (block->tag) {
4174 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4175 num_modes += add_displayid_detailed_1_modes(connector, block);
4176 break;
4177 }
4178 }
4179 return num_modes;
4180}
4181
Jesse Barnes3b112282011-04-15 12:49:23 -07004182/**
Dave Airlief453ba02008-11-07 14:05:41 -08004183 * drm_add_edid_modes - add modes from EDID data, if available
4184 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004185 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08004186 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02004187 * Add the specified modes to the connector's mode list. Also fills out the
4188 * &drm_display_info structure in @connector with any information which can be
4189 * derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08004190 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004191 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08004192 */
4193int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4194{
4195 int num_modes = 0;
4196 u32 quirks;
4197
4198 if (edid == NULL) {
4199 return 0;
4200 }
Alex Deucher3c537882010-02-05 04:21:19 -05004201 if (!drm_edid_is_valid(edid)) {
Jordan Crousedcdb1672010-05-27 13:40:25 -06004202 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03004203 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08004204 return 0;
4205 }
4206
4207 quirks = edid_get_quirks(edid);
4208
Adam Jacksonc867df72010-03-29 21:43:21 +00004209 /*
4210 * EDID spec says modes should be preferred in this order:
4211 * - preferred detailed mode
4212 * - other detailed modes from base block
4213 * - detailed modes from extension blocks
4214 * - CVT 3-byte code modes
4215 * - standard timing codes
4216 * - established timing codes
4217 * - modes inferred from GTF or CVT range information
4218 *
Adam Jackson13931572010-08-03 14:38:19 -04004219 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00004220 *
4221 * XXX order for additional mode types in extension blocks?
4222 */
Adam Jackson13931572010-08-03 14:38:19 -04004223 num_modes += add_detailed_modes(connector, edid, quirks);
4224 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00004225 num_modes += add_standard_modes(connector, edid);
4226 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004227 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03004228 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10004229 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03004230 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
4231 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08004232
4233 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
4234 edid_fixup_preferred(connector, quirks);
4235
Ville Syrjälä1cea1462016-09-28 16:51:39 +03004236 drm_add_display_info(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08004237
Mario Kleinere10aec62016-07-06 12:05:44 +02004238 if (quirks & EDID_QUIRK_FORCE_6BPC)
4239 connector->display_info.bpc = 6;
4240
Rafał Miłecki49d45a312013-12-07 13:22:42 +01004241 if (quirks & EDID_QUIRK_FORCE_8BPC)
4242 connector->display_info.bpc = 8;
4243
Mario Kleinerbc5b9642014-05-23 21:40:55 +02004244 if (quirks & EDID_QUIRK_FORCE_12BPC)
4245 connector->display_info.bpc = 12;
4246
Dave Airlief453ba02008-11-07 14:05:41 -08004247 return num_modes;
4248}
4249EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004250
4251/**
4252 * drm_add_modes_noedid - add modes for the connectors without EDID
4253 * @connector: connector we're probing
4254 * @hdisplay: the horizontal display limit
4255 * @vdisplay: the vertical display limit
4256 *
4257 * Add the specified modes to the connector's mode list. Only when the
4258 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4259 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004260 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004261 */
4262int drm_add_modes_noedid(struct drm_connector *connector,
4263 int hdisplay, int vdisplay)
4264{
4265 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004266 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004267 struct drm_device *dev = connector->dev;
4268
Daniel Vetterfbb40b22015-08-10 11:55:37 +02004269 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004270 if (hdisplay < 0)
4271 hdisplay = 0;
4272 if (vdisplay < 0)
4273 vdisplay = 0;
4274
4275 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00004276 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004277 if (hdisplay && vdisplay) {
4278 /*
4279 * Only when two are valid, they will be used to check
4280 * whether the mode should be added to the mode list of
4281 * the connector.
4282 */
4283 if (ptr->hdisplay > hdisplay ||
4284 ptr->vdisplay > vdisplay)
4285 continue;
4286 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05004287 if (drm_mode_vrefresh(ptr) > 61)
4288 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08004289 mode = drm_mode_duplicate(dev, ptr);
4290 if (mode) {
4291 drm_mode_probed_add(connector, mode);
4292 num_modes++;
4293 }
4294 }
4295 return num_modes;
4296}
4297EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01004298
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004299/**
4300 * drm_set_preferred_mode - Sets the preferred mode of a connector
4301 * @connector: connector whose mode list should be processed
4302 * @hpref: horizontal resolution of preferred mode
4303 * @vpref: vertical resolution of preferred mode
4304 *
4305 * Marks a mode as preferred if it matches the resolution specified by @hpref
4306 * and @vpref.
4307 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004308void drm_set_preferred_mode(struct drm_connector *connector,
4309 int hpref, int vpref)
4310{
4311 struct drm_display_mode *mode;
4312
4313 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004314 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01004315 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02004316 mode->type |= DRM_MODE_TYPE_PREFERRED;
4317 }
4318}
4319EXPORT_SYMBOL(drm_set_preferred_mode);
4320
Thierry Reding10a85122012-11-21 15:31:35 +01004321/**
4322 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
4323 * data from a DRM display mode
4324 * @frame: HDMI AVI infoframe
4325 * @mode: DRM display mode
4326 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004327 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01004328 */
4329int
4330drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
4331 const struct drm_display_mode *mode)
4332{
4333 int err;
4334
4335 if (!frame || !mode)
4336 return -EINVAL;
4337
4338 err = hdmi_avi_infoframe_init(frame);
4339 if (err < 0)
4340 return err;
4341
Damien Lespiaubf02db92013-08-06 20:32:22 +01004342 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
4343 frame->pixel_repeat = 1;
4344
Thierry Reding10a85122012-11-21 15:31:35 +01004345 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01004346
4347 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304348
Vandana Kannan69ab6d32014-06-05 14:45:29 +05304349 /*
4350 * Populate picture aspect ratio from either
4351 * user input (if specified) or from the CEA mode list.
4352 */
4353 if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
4354 mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
4355 frame->picture_aspect = mode->picture_aspect_ratio;
4356 else if (frame->video_code > 0)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05304357 frame->picture_aspect = drm_get_cea_aspect_ratio(
4358 frame->video_code);
4359
Thierry Reding10a85122012-11-21 15:31:35 +01004360 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06004361 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01004362
4363 return 0;
4364}
4365EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004366
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004367/**
4368 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
4369 * quantization range information
4370 * @frame: HDMI AVI infoframe
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004371 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004372 * @rgb_quant_range: RGB quantization range (Q)
4373 * @rgb_quant_range_selectable: Sink support selectable RGB quantization range (QS)
4374 */
4375void
4376drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004377 const struct drm_display_mode *mode,
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004378 enum hdmi_quantization_range rgb_quant_range,
4379 bool rgb_quant_range_selectable)
4380{
4381 /*
4382 * CEA-861:
4383 * "A Source shall not send a non-zero Q value that does not correspond
4384 * to the default RGB Quantization Range for the transmitted Picture
4385 * unless the Sink indicates support for the Q bit in a Video
4386 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004387 *
4388 * HDMI 2.0 recommends sending non-zero Q when it does match the
4389 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004390 */
Ville Syrjälä779c4c22017-01-11 14:57:24 +02004391 if (rgb_quant_range_selectable ||
4392 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004393 frame->quantization_range = rgb_quant_range;
4394 else
4395 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02004396
4397 /*
4398 * CEA-861-F:
4399 * "When transmitting any RGB colorimetry, the Source should set the
4400 * YQ-field to match the RGB Quantization Range being transmitted
4401 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
4402 * set YQ=1) and the Sink shall ignore the YQ-field."
4403 */
4404 if (rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
4405 frame->ycc_quantization_range =
4406 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
4407 else
4408 frame->ycc_quantization_range =
4409 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02004410}
4411EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
4412
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004413static enum hdmi_3d_structure
4414s3d_structure_from_display_mode(const struct drm_display_mode *mode)
4415{
4416 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
4417
4418 switch (layout) {
4419 case DRM_MODE_FLAG_3D_FRAME_PACKING:
4420 return HDMI_3D_STRUCTURE_FRAME_PACKING;
4421 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
4422 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
4423 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
4424 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
4425 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
4426 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
4427 case DRM_MODE_FLAG_3D_L_DEPTH:
4428 return HDMI_3D_STRUCTURE_L_DEPTH;
4429 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
4430 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
4431 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
4432 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
4433 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
4434 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
4435 default:
4436 return HDMI_3D_STRUCTURE_INVALID;
4437 }
4438}
4439
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004440/**
4441 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
4442 * data from a DRM display mode
4443 * @frame: HDMI vendor infoframe
4444 * @mode: DRM display mode
4445 *
4446 * Note that there's is a need to send HDMI vendor infoframes only when using a
4447 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
4448 * function will return -EINVAL, error that can be safely ignored.
4449 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004450 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004451 */
4452int
4453drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
4454 const struct drm_display_mode *mode)
4455{
4456 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004457 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004458 u8 vic;
4459
4460 if (!frame || !mode)
4461 return -EINVAL;
4462
4463 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004464 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
4465
4466 if (!vic && !s3d_flags)
4467 return -EINVAL;
4468
4469 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004470 return -EINVAL;
4471
4472 err = hdmi_vendor_infoframe_init(frame);
4473 if (err < 0)
4474 return err;
4475
Damien Lespiau4eed4a02013-09-25 16:45:26 +01004476 if (vic)
4477 frame->vic = vic;
4478 else
4479 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01004480
4481 return 0;
4482}
4483EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10004484
Dave Airlie5e546cd2016-05-03 15:31:12 +10004485static int drm_parse_tiled_block(struct drm_connector *connector,
4486 struct displayid_block *block)
4487{
4488 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
4489 u16 w, h;
4490 u8 tile_v_loc, tile_h_loc;
4491 u8 num_v_tile, num_h_tile;
4492 struct drm_tile_group *tg;
4493
4494 w = tile->tile_size[0] | tile->tile_size[1] << 8;
4495 h = tile->tile_size[2] | tile->tile_size[3] << 8;
4496
4497 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
4498 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
4499 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
4500 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
4501
4502 connector->has_tile = true;
4503 if (tile->tile_cap & 0x80)
4504 connector->tile_is_single_monitor = true;
4505
4506 connector->num_h_tile = num_h_tile + 1;
4507 connector->num_v_tile = num_v_tile + 1;
4508 connector->tile_h_loc = tile_h_loc;
4509 connector->tile_v_loc = tile_v_loc;
4510 connector->tile_h_size = w + 1;
4511 connector->tile_v_size = h + 1;
4512
4513 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
4514 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
4515 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
4516 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
4517 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
4518
4519 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
4520 if (!tg) {
4521 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
4522 }
4523 if (!tg)
4524 return -ENOMEM;
4525
4526 if (connector->tile_group != tg) {
4527 /* if we haven't got a pointer,
4528 take the reference, drop ref to old tile group */
4529 if (connector->tile_group) {
4530 drm_mode_put_tile_group(connector->dev, connector->tile_group);
4531 }
4532 connector->tile_group = tg;
4533 } else
4534 /* if same tile group, then release the ref we just took. */
4535 drm_mode_put_tile_group(connector->dev, tg);
4536 return 0;
4537}
4538
Dave Airlie40d9b042014-10-20 16:29:33 +10004539static int drm_parse_display_id(struct drm_connector *connector,
4540 u8 *displayid, int length,
4541 bool is_edid_extension)
4542{
4543 /* if this is an EDID extension the first byte will be 0x70 */
4544 int idx = 0;
Dave Airlie40d9b042014-10-20 16:29:33 +10004545 struct displayid_block *block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10004546 int ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10004547
4548 if (is_edid_extension)
4549 idx = 1;
4550
Dave Airliec97291772016-05-03 15:38:37 +10004551 ret = validate_displayid(displayid, length, idx);
4552 if (ret)
4553 return ret;
Dave Airlie40d9b042014-10-20 16:29:33 +10004554
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02004555 idx += sizeof(struct displayid_hdr);
4556 while (block = (struct displayid_block *)&displayid[idx],
4557 idx + sizeof(struct displayid_block) <= length &&
4558 idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
4559 block->num_bytes > 0) {
4560 idx += block->num_bytes + sizeof(struct displayid_block);
4561 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
4562 block->tag, block->rev, block->num_bytes);
Dave Airlie40d9b042014-10-20 16:29:33 +10004563
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02004564 switch (block->tag) {
4565 case DATA_BLOCK_TILED_DISPLAY:
4566 ret = drm_parse_tiled_block(connector, block);
4567 if (ret)
4568 return ret;
4569 break;
Dave Airliea39ed682016-05-02 08:35:05 +10004570 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4571 /* handled in mode gathering code. */
4572 break;
Tomas Bzatek3a4a2ea2016-05-01 15:02:45 +02004573 default:
4574 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
4575 break;
4576 }
Dave Airlie40d9b042014-10-20 16:29:33 +10004577 }
4578 return 0;
4579}
4580
4581static void drm_get_displayid(struct drm_connector *connector,
4582 struct edid *edid)
4583{
4584 void *displayid = NULL;
4585 int ret;
4586 connector->has_tile = false;
4587 displayid = drm_find_displayid_extension(edid);
4588 if (!displayid) {
4589 /* drop reference to any tile group we had */
4590 goto out_drop_ref;
4591 }
4592
4593 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
4594 if (ret < 0)
4595 goto out_drop_ref;
4596 if (!connector->has_tile)
4597 goto out_drop_ref;
4598 return;
4599out_drop_ref:
4600 if (connector->tile_group) {
4601 drm_mode_put_tile_group(connector->dev, connector->tile_group);
4602 connector->tile_group = NULL;
4603 }
4604 return;
4605}