blob: 9b19eee0e1b420531ca82b0d306256e1519a16c6 [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright (c) 2006 Luc Verhaegen (quirks list)
3 * Copyright (c) 2007-2008 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
Adam Jackson61e57a82010-03-29 21:43:18 +00005 * Copyright 2010 Red Hat, Inc.
Dave Airlief453ba02008-11-07 14:05:41 -08006 *
7 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
8 * FB layer.
9 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sub license,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the
19 * next paragraph) shall be included in all copies or substantial portions
20 * of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 */
Jani Nikula9c79ede2019-05-06 12:52:48 +030030
Thierry Reding10a85122012-11-21 15:31:35 +010031#include <linux/hdmi.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/i2c.h>
Jani Nikula9c79ede2019-05-06 12:52:48 +030033#include <linux/kernel.h>
Adam Jackson47819ba2012-05-30 16:42:39 -040034#include <linux/module.h>
Thomas Zimmermann36b73b02021-01-18 14:14:15 +010035#include <linux/pci.h>
Jani Nikula9c79ede2019-05-06 12:52:48 +030036#include <linux/slab.h>
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +010037#include <linux/vga_switcheroo.h>
Jani Nikula9c79ede2019-05-06 12:52:48 +030038
39#include <drm/drm_displayid.h>
40#include <drm/drm_drv.h>
David Howells760285e2012-10-02 18:01:07 +010041#include <drm/drm_edid.h>
Laurent Pinchart93382032016-11-28 20:51:09 +020042#include <drm/drm_encoder.h>
Jani Nikula9c79ede2019-05-06 12:52:48 +030043#include <drm/drm_print.h>
Shashank Sharma62c58af2017-03-13 16:54:02 +053044#include <drm/drm_scdc_helper.h>
Dave Airlief453ba02008-11-07 14:05:41 -080045
Takashi Iwai969218f2017-01-17 17:43:29 +010046#include "drm_crtc_internal.h"
47
Adam Jackson13931572010-08-03 14:38:19 -040048#define version_greater(edid, maj, min) \
49 (((edid)->version > (maj)) || \
50 ((edid)->version == (maj) && (edid)->revision > (min)))
Dave Airlief453ba02008-11-07 14:05:41 -080051
Adam Jacksond1ff6402010-03-29 21:43:26 +000052#define EDID_EST_TIMINGS 16
53#define EDID_STD_TIMINGS 8
54#define EDID_DETAILED_TIMINGS 4
Dave Airlief453ba02008-11-07 14:05:41 -080055
56/*
57 * EDID blocks out in the wild have a variety of bugs, try to collect
58 * them here (note that userspace may work around broken monitors first,
59 * but fixes should make their way here so that the kernel "just works"
60 * on as many displays as possible).
61 */
62
63/* First detailed mode wrong, use largest 60Hz mode */
64#define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
65/* Reported 135MHz pixel clock is too high, needs adjustment */
66#define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
67/* Prefer the largest mode at 75 Hz */
68#define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
69/* Detail timing is in cm not mm */
70#define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
71/* Detailed timing descriptors have bogus size values, so just take the
72 * maximum size and use that.
73 */
74#define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
Dave Airlief453ba02008-11-07 14:05:41 -080075/* use +hsync +vsync for detailed mode */
76#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
Adam Jacksonbc42aab2012-05-23 16:26:54 -040077/* Force reduced-blanking timings for detailed modes */
78#define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
Rafał Miłecki49d45a312013-12-07 13:22:42 +010079/* Force 8bpc */
80#define EDID_QUIRK_FORCE_8BPC (1 << 8)
Mario Kleinerbc5b9642014-05-23 21:40:55 +020081/* Force 12bpc */
82#define EDID_QUIRK_FORCE_12BPC (1 << 9)
Mario Kleinere10aec62016-07-06 12:05:44 +020083/* Force 6bpc */
84#define EDID_QUIRK_FORCE_6BPC (1 << 10)
Mario Kleinere345da82017-04-21 17:05:08 +020085/* Force 10bpc */
86#define EDID_QUIRK_FORCE_10BPC (1 << 11)
Dave Airlie66660d42017-10-16 05:08:09 +010087/* Non desktop display (i.e. HMD) */
88#define EDID_QUIRK_NON_DESKTOP (1 << 12)
Alex Deucher3c537882010-02-05 04:21:19 -050089
Adam Jackson13931572010-08-03 14:38:19 -040090struct detailed_mode_closure {
91 struct drm_connector *connector;
92 struct edid *edid;
93 bool preferred;
94 u32 quirks;
95 int modes;
96};
Dave Airlief453ba02008-11-07 14:05:41 -080097
Zhao Yakui5c612592009-06-22 13:17:10 +080098#define LEVEL_DMT 0
99#define LEVEL_GTF 1
Adam Jackson7a374352010-03-29 21:43:30 +0000100#define LEVEL_GTF2 2
101#define LEVEL_CVT 3
Zhao Yakui5c612592009-06-22 13:17:10 +0800102
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700103#define EDID_QUIRK(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _quirks) \
Douglas Andersone8de4d52021-09-14 13:21:51 -0700104{ \
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700105 .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
106 product_id), \
Douglas Andersone8de4d52021-09-14 13:21:51 -0700107 .quirks = _quirks \
108}
109
Jani Nikula23c4cfb2016-12-28 13:06:26 +0200110static const struct edid_quirk {
Douglas Andersone8de4d52021-09-14 13:21:51 -0700111 u32 panel_id;
Dave Airlief453ba02008-11-07 14:05:41 -0800112 u32 quirks;
113} edid_quirk_list[] = {
114 /* Acer AL1706 */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700115 EDID_QUIRK('A', 'C', 'R', 44358, EDID_QUIRK_PREFER_LARGE_60),
Dave Airlief453ba02008-11-07 14:05:41 -0800116 /* Acer F51 */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700117 EDID_QUIRK('A', 'P', 'I', 0x7602, EDID_QUIRK_PREFER_LARGE_60),
Dave Airlief453ba02008-11-07 14:05:41 -0800118
Mario Kleinere10aec62016-07-06 12:05:44 +0200119 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700120 EDID_QUIRK('A', 'E', 'O', 0, EDID_QUIRK_FORCE_6BPC),
Mario Kleinere10aec62016-07-06 12:05:44 +0200121
Kai-Heng Feng0711a432018-10-02 23:29:11 +0800122 /* BOE model on HP Pavilion 15-n233sl reports 8 bpc, but is a 6 bpc panel */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700123 EDID_QUIRK('B', 'O', 'E', 0x78b, EDID_QUIRK_FORCE_6BPC),
Kai-Heng Feng0711a432018-10-02 23:29:11 +0800124
Kai-Heng Feng06998a752018-02-18 16:53:59 +0800125 /* CPT panel of Asus UX303LA reports 8 bpc, but is a 6 bpc panel */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700126 EDID_QUIRK('C', 'P', 'T', 0x17df, EDID_QUIRK_FORCE_6BPC),
Kai-Heng Feng06998a752018-02-18 16:53:59 +0800127
Kai-Heng Feng25da7502018-08-23 05:53:32 +0000128 /* SDC panel of Lenovo B50-80 reports 8 bpc, but is a 6 bpc panel */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700129 EDID_QUIRK('S', 'D', 'C', 0x3652, EDID_QUIRK_FORCE_6BPC),
Kai-Heng Feng25da7502018-08-23 05:53:32 +0000130
Lee, Shawn C922dcef2018-10-28 22:49:33 -0700131 /* BOE model 0x0771 reports 8 bpc, but is a 6 bpc panel */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700132 EDID_QUIRK('B', 'O', 'E', 0x0771, EDID_QUIRK_FORCE_6BPC),
Lee, Shawn C922dcef2018-10-28 22:49:33 -0700133
Dave Airlief453ba02008-11-07 14:05:41 -0800134 /* Belinea 10 15 55 */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700135 EDID_QUIRK('M', 'A', 'X', 1516, EDID_QUIRK_PREFER_LARGE_60),
136 EDID_QUIRK('M', 'A', 'X', 0x77e, EDID_QUIRK_PREFER_LARGE_60),
Dave Airlief453ba02008-11-07 14:05:41 -0800137
138 /* Envision Peripherals, Inc. EN-7100e */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700139 EDID_QUIRK('E', 'P', 'I', 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH),
Adam Jacksonba1163d2010-04-06 16:11:00 +0000140 /* Envision EN2028 */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700141 EDID_QUIRK('E', 'P', 'I', 8232, EDID_QUIRK_PREFER_LARGE_60),
Dave Airlief453ba02008-11-07 14:05:41 -0800142
143 /* Funai Electronics PM36B */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700144 EDID_QUIRK('F', 'C', 'M', 13600, EDID_QUIRK_PREFER_LARGE_75 |
Douglas Andersone8de4d52021-09-14 13:21:51 -0700145 EDID_QUIRK_DETAILED_IN_CM),
Dave Airlief453ba02008-11-07 14:05:41 -0800146
Mario Kleinere345da82017-04-21 17:05:08 +0200147 /* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700148 EDID_QUIRK('L', 'G', 'D', 764, EDID_QUIRK_FORCE_10BPC),
Mario Kleinere345da82017-04-21 17:05:08 +0200149
Dave Airlief453ba02008-11-07 14:05:41 -0800150 /* LG Philips LCD LP154W01-A5 */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700151 EDID_QUIRK('L', 'P', 'L', 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE),
152 EDID_QUIRK('L', 'P', 'L', 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE),
Dave Airlief453ba02008-11-07 14:05:41 -0800153
Dave Airlief453ba02008-11-07 14:05:41 -0800154 /* Samsung SyncMaster 205BW. Note: irony */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700155 EDID_QUIRK('S', 'A', 'M', 541, EDID_QUIRK_DETAILED_SYNC_PP),
Dave Airlief453ba02008-11-07 14:05:41 -0800156 /* Samsung SyncMaster 22[5-6]BW */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700157 EDID_QUIRK('S', 'A', 'M', 596, EDID_QUIRK_PREFER_LARGE_60),
158 EDID_QUIRK('S', 'A', 'M', 638, EDID_QUIRK_PREFER_LARGE_60),
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400159
Mario Kleinerbc5b9642014-05-23 21:40:55 +0200160 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700161 EDID_QUIRK('S', 'N', 'Y', 0x2541, EDID_QUIRK_FORCE_12BPC),
Mario Kleinerbc5b9642014-05-23 21:40:55 +0200162
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400163 /* ViewSonic VA2026w */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700164 EDID_QUIRK('V', 'S', 'C', 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING),
Alex Deucher118bdbd2013-08-12 11:04:29 -0400165
166 /* Medion MD 30217 PG */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700167 EDID_QUIRK('M', 'E', 'D', 0x7b8, EDID_QUIRK_PREFER_LARGE_75),
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100168
Kai-Heng Feng11bcf5f2019-04-02 11:30:37 +0800169 /* Lenovo G50 */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700170 EDID_QUIRK('S', 'D', 'C', 18514, EDID_QUIRK_FORCE_6BPC),
Kai-Heng Feng11bcf5f2019-04-02 11:30:37 +0800171
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100172 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700173 EDID_QUIRK('S', 'E', 'C', 0xd033, EDID_QUIRK_FORCE_8BPC),
Tomeu Vizoso36fc5792017-02-20 16:25:45 +0100174
175 /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700176 EDID_QUIRK('E', 'T', 'R', 13896, EDID_QUIRK_FORCE_8BPC),
Dave Airlieacb1d8e2017-10-16 05:26:19 +0100177
Andres Rodriguez30d62d42019-05-02 15:31:57 -0400178 /* Valve Index Headset */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700179 EDID_QUIRK('V', 'L', 'V', 0x91a8, EDID_QUIRK_NON_DESKTOP),
180 EDID_QUIRK('V', 'L', 'V', 0x91b0, EDID_QUIRK_NON_DESKTOP),
181 EDID_QUIRK('V', 'L', 'V', 0x91b1, EDID_QUIRK_NON_DESKTOP),
182 EDID_QUIRK('V', 'L', 'V', 0x91b2, EDID_QUIRK_NON_DESKTOP),
183 EDID_QUIRK('V', 'L', 'V', 0x91b3, EDID_QUIRK_NON_DESKTOP),
184 EDID_QUIRK('V', 'L', 'V', 0x91b4, EDID_QUIRK_NON_DESKTOP),
185 EDID_QUIRK('V', 'L', 'V', 0x91b5, EDID_QUIRK_NON_DESKTOP),
186 EDID_QUIRK('V', 'L', 'V', 0x91b6, EDID_QUIRK_NON_DESKTOP),
187 EDID_QUIRK('V', 'L', 'V', 0x91b7, EDID_QUIRK_NON_DESKTOP),
188 EDID_QUIRK('V', 'L', 'V', 0x91b8, EDID_QUIRK_NON_DESKTOP),
189 EDID_QUIRK('V', 'L', 'V', 0x91b9, EDID_QUIRK_NON_DESKTOP),
190 EDID_QUIRK('V', 'L', 'V', 0x91ba, EDID_QUIRK_NON_DESKTOP),
191 EDID_QUIRK('V', 'L', 'V', 0x91bb, EDID_QUIRK_NON_DESKTOP),
192 EDID_QUIRK('V', 'L', 'V', 0x91bc, EDID_QUIRK_NON_DESKTOP),
193 EDID_QUIRK('V', 'L', 'V', 0x91bd, EDID_QUIRK_NON_DESKTOP),
194 EDID_QUIRK('V', 'L', 'V', 0x91be, EDID_QUIRK_NON_DESKTOP),
195 EDID_QUIRK('V', 'L', 'V', 0x91bf, EDID_QUIRK_NON_DESKTOP),
Andres Rodriguez30d62d42019-05-02 15:31:57 -0400196
Lubosz Sarnecki69313172018-05-29 13:52:15 +0200197 /* HTC Vive and Vive Pro VR Headsets */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700198 EDID_QUIRK('H', 'V', 'R', 0xaa01, EDID_QUIRK_NON_DESKTOP),
199 EDID_QUIRK('H', 'V', 'R', 0xaa02, EDID_QUIRK_NON_DESKTOP),
Philipp Zabelb3b12ea2018-02-19 18:59:36 +0100200
Jan Schmidt5a3f6102020-05-08 04:06:28 +1000201 /* Oculus Rift DK1, DK2, CV1 and Rift S VR Headsets */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700202 EDID_QUIRK('O', 'V', 'R', 0x0001, EDID_QUIRK_NON_DESKTOP),
203 EDID_QUIRK('O', 'V', 'R', 0x0003, EDID_QUIRK_NON_DESKTOP),
204 EDID_QUIRK('O', 'V', 'R', 0x0004, EDID_QUIRK_NON_DESKTOP),
205 EDID_QUIRK('O', 'V', 'R', 0x0012, EDID_QUIRK_NON_DESKTOP),
Philipp Zabel90eda8f2018-02-19 18:59:37 +0100206
207 /* Windows Mixed Reality Headsets */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700208 EDID_QUIRK('A', 'C', 'R', 0x7fce, EDID_QUIRK_NON_DESKTOP),
209 EDID_QUIRK('H', 'P', 'N', 0x3515, EDID_QUIRK_NON_DESKTOP),
210 EDID_QUIRK('L', 'E', 'N', 0x0408, EDID_QUIRK_NON_DESKTOP),
211 EDID_QUIRK('L', 'E', 'N', 0xb800, EDID_QUIRK_NON_DESKTOP),
212 EDID_QUIRK('F', 'U', 'J', 0x1970, EDID_QUIRK_NON_DESKTOP),
213 EDID_QUIRK('D', 'E', 'L', 0x7fce, EDID_QUIRK_NON_DESKTOP),
214 EDID_QUIRK('S', 'E', 'C', 0x144a, EDID_QUIRK_NON_DESKTOP),
215 EDID_QUIRK('A', 'U', 'S', 0xc102, EDID_QUIRK_NON_DESKTOP),
Philipp Zabelccffc9e2018-02-19 18:59:38 +0100216
217 /* Sony PlayStation VR Headset */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700218 EDID_QUIRK('S', 'N', 'Y', 0x0704, EDID_QUIRK_NON_DESKTOP),
Ryan Pavlik29054232018-12-03 10:46:44 -0600219
220 /* Sensics VR Headsets */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700221 EDID_QUIRK('S', 'E', 'N', 0x1019, EDID_QUIRK_NON_DESKTOP),
Ryan Pavlik29054232018-12-03 10:46:44 -0600222
223 /* OSVR HDK and HDK2 VR Headsets */
Douglas Anderson7d1be0a02021-09-24 07:53:21 -0700224 EDID_QUIRK('S', 'V', 'R', 0x1019, EDID_QUIRK_NON_DESKTOP),
Dave Airlief453ba02008-11-07 14:05:41 -0800225};
226
Thierry Redinga6b21832012-11-23 15:01:42 +0100227/*
228 * Autogenerated from the DMT spec.
229 * This table is copied from xfree86/modes/xf86EdidModes.c.
230 */
231static const struct drm_display_mode drm_dmt_modes[] = {
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300232 /* 0x01 - 640x350@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100233 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
234 736, 832, 0, 350, 382, 385, 445, 0,
235 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300236 /* 0x02 - 640x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100237 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
238 736, 832, 0, 400, 401, 404, 445, 0,
239 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300240 /* 0x03 - 720x400@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100241 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
242 828, 936, 0, 400, 401, 404, 446, 0,
243 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300244 /* 0x04 - 640x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100245 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300246 752, 800, 0, 480, 490, 492, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100247 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300248 /* 0x05 - 640x480@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100249 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
250 704, 832, 0, 480, 489, 492, 520, 0,
251 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300252 /* 0x06 - 640x480@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100253 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
254 720, 840, 0, 480, 481, 484, 500, 0,
255 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300256 /* 0x07 - 640x480@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100257 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
258 752, 832, 0, 480, 481, 484, 509, 0,
259 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300260 /* 0x08 - 800x600@56Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100261 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
262 896, 1024, 0, 600, 601, 603, 625, 0,
263 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300264 /* 0x09 - 800x600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100265 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
266 968, 1056, 0, 600, 601, 605, 628, 0,
267 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300268 /* 0x0a - 800x600@72Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100269 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
270 976, 1040, 0, 600, 637, 643, 666, 0,
271 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300272 /* 0x0b - 800x600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100273 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
274 896, 1056, 0, 600, 601, 604, 625, 0,
275 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300276 /* 0x0c - 800x600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100277 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
278 896, 1048, 0, 600, 601, 604, 631, 0,
279 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300280 /* 0x0d - 800x600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100281 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
282 880, 960, 0, 600, 603, 607, 636, 0,
283 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300284 /* 0x0e - 848x480@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100285 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
286 976, 1088, 0, 480, 486, 494, 517, 0,
287 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300288 /* 0x0f - 1024x768@43Hz, interlace */
Thierry Redinga6b21832012-11-23 15:01:42 +0100289 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
Paul Parsons735b1002016-04-04 20:36:34 +0100290 1208, 1264, 0, 768, 768, 776, 817, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100291 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300292 DRM_MODE_FLAG_INTERLACE) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300293 /* 0x10 - 1024x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100294 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
295 1184, 1344, 0, 768, 771, 777, 806, 0,
296 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300297 /* 0x11 - 1024x768@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100298 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
299 1184, 1328, 0, 768, 771, 777, 806, 0,
300 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300301 /* 0x12 - 1024x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100302 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
303 1136, 1312, 0, 768, 769, 772, 800, 0,
304 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300305 /* 0x13 - 1024x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100306 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
307 1168, 1376, 0, 768, 769, 772, 808, 0,
308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300309 /* 0x14 - 1024x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100310 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
311 1104, 1184, 0, 768, 771, 775, 813, 0,
312 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300313 /* 0x15 - 1152x864@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100314 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
315 1344, 1600, 0, 864, 865, 868, 900, 0,
316 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300317 /* 0x55 - 1280x720@60Hz */
318 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
319 1430, 1650, 0, 720, 725, 730, 750, 0,
320 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300321 /* 0x16 - 1280x768@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100322 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
323 1360, 1440, 0, 768, 771, 778, 790, 0,
324 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300325 /* 0x17 - 1280x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100326 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
327 1472, 1664, 0, 768, 771, 778, 798, 0,
328 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300329 /* 0x18 - 1280x768@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100330 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
331 1488, 1696, 0, 768, 771, 778, 805, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300332 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300333 /* 0x19 - 1280x768@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100334 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
335 1496, 1712, 0, 768, 771, 778, 809, 0,
336 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300337 /* 0x1a - 1280x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100338 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
339 1360, 1440, 0, 768, 771, 778, 813, 0,
340 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300341 /* 0x1b - 1280x800@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100342 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
343 1360, 1440, 0, 800, 803, 809, 823, 0,
344 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300345 /* 0x1c - 1280x800@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100346 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
347 1480, 1680, 0, 800, 803, 809, 831, 0,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300348 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300349 /* 0x1d - 1280x800@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100350 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
351 1488, 1696, 0, 800, 803, 809, 838, 0,
352 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300353 /* 0x1e - 1280x800@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100354 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
355 1496, 1712, 0, 800, 803, 809, 843, 0,
356 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300357 /* 0x1f - 1280x800@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100358 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
359 1360, 1440, 0, 800, 803, 809, 847, 0,
360 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300361 /* 0x20 - 1280x960@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100362 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
363 1488, 1800, 0, 960, 961, 964, 1000, 0,
364 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300365 /* 0x21 - 1280x960@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100366 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
367 1504, 1728, 0, 960, 961, 964, 1011, 0,
368 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300369 /* 0x22 - 1280x960@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100370 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
371 1360, 1440, 0, 960, 963, 967, 1017, 0,
372 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300373 /* 0x23 - 1280x1024@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100374 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
375 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
376 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300377 /* 0x24 - 1280x1024@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100378 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
379 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
380 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300381 /* 0x25 - 1280x1024@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100382 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
383 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
384 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300385 /* 0x26 - 1280x1024@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100386 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
387 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
388 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300389 /* 0x27 - 1360x768@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100390 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
391 1536, 1792, 0, 768, 771, 777, 795, 0,
392 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300393 /* 0x28 - 1360x768@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100394 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
395 1440, 1520, 0, 768, 771, 776, 813, 0,
396 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300397 /* 0x51 - 1366x768@60Hz */
398 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
399 1579, 1792, 0, 768, 771, 774, 798, 0,
400 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
401 /* 0x56 - 1366x768@60Hz */
402 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
403 1436, 1500, 0, 768, 769, 772, 800, 0,
404 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300405 /* 0x29 - 1400x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100406 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
407 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
408 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300409 /* 0x2a - 1400x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100410 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
411 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
412 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300413 /* 0x2b - 1400x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100414 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
415 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
416 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300417 /* 0x2c - 1400x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100418 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
419 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
420 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300421 /* 0x2d - 1400x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100422 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
423 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
424 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300425 /* 0x2e - 1440x900@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100426 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
427 1520, 1600, 0, 900, 903, 909, 926, 0,
428 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300429 /* 0x2f - 1440x900@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100430 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
431 1672, 1904, 0, 900, 903, 909, 934, 0,
432 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300433 /* 0x30 - 1440x900@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100434 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
435 1688, 1936, 0, 900, 903, 909, 942, 0,
436 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300437 /* 0x31 - 1440x900@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100438 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
439 1696, 1952, 0, 900, 903, 909, 948, 0,
440 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300441 /* 0x32 - 1440x900@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100442 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
443 1520, 1600, 0, 900, 903, 909, 953, 0,
444 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300445 /* 0x53 - 1600x900@60Hz */
446 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
447 1704, 1800, 0, 900, 901, 904, 1000, 0,
448 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300449 /* 0x33 - 1600x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100450 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
451 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
452 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300453 /* 0x34 - 1600x1200@65Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100454 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
455 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
456 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300457 /* 0x35 - 1600x1200@70Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100458 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
459 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
460 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300461 /* 0x36 - 1600x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100462 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
463 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
464 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300465 /* 0x37 - 1600x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100466 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
467 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
468 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300469 /* 0x38 - 1600x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100470 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
471 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
472 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300473 /* 0x39 - 1680x1050@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100474 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
475 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
476 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300477 /* 0x3a - 1680x1050@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100478 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
479 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
480 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300481 /* 0x3b - 1680x1050@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100482 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
483 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
484 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300485 /* 0x3c - 1680x1050@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100486 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
487 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
488 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300489 /* 0x3d - 1680x1050@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100490 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
491 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
492 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300493 /* 0x3e - 1792x1344@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100494 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
495 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
496 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300497 /* 0x3f - 1792x1344@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100498 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
499 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
500 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300501 /* 0x40 - 1792x1344@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100502 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
503 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
504 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300505 /* 0x41 - 1856x1392@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100506 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
507 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
508 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300509 /* 0x42 - 1856x1392@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100510 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
Ville Syrjäläfcf22d02015-04-02 17:02:09 +0300511 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100512 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300513 /* 0x43 - 1856x1392@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100514 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
515 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
516 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300517 /* 0x52 - 1920x1080@60Hz */
518 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
519 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
520 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300521 /* 0x44 - 1920x1200@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100522 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
523 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
524 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300525 /* 0x45 - 1920x1200@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100526 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
527 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
528 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300529 /* 0x46 - 1920x1200@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100530 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
531 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
532 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300533 /* 0x47 - 1920x1200@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100534 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
535 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
536 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300537 /* 0x48 - 1920x1200@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100538 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
539 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
540 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300541 /* 0x49 - 1920x1440@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100542 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
543 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
544 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300545 /* 0x4a - 1920x1440@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100546 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
547 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
548 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300549 /* 0x4b - 1920x1440@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100550 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
551 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
552 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300553 /* 0x54 - 2048x1152@60Hz */
554 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
555 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
556 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300557 /* 0x4c - 2560x1600@60Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100558 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
559 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
560 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300561 /* 0x4d - 2560x1600@60Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100562 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
563 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
564 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300565 /* 0x4e - 2560x1600@75Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100566 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
567 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
568 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300569 /* 0x4f - 2560x1600@85Hz */
Thierry Redinga6b21832012-11-23 15:01:42 +0100570 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
571 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
572 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
Ville Syrjälä24b856b2015-04-02 17:02:10 +0300573 /* 0x50 - 2560x1600@120Hz RB */
Thierry Redinga6b21832012-11-23 15:01:42 +0100574 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
575 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
576 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Ville Syrjäläbfcd74d2015-04-02 17:02:11 +0300577 /* 0x57 - 4096x2160@60Hz RB */
578 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
579 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
580 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
581 /* 0x58 - 4096x2160@59.94Hz RB */
582 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
583 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
584 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
Thierry Redinga6b21832012-11-23 15:01:42 +0100585};
586
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300587/*
588 * These more or less come from the DMT spec. The 720x400 modes are
589 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
590 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
591 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
592 * mode.
593 *
594 * The DMT modes have been fact-checked; the rest are mild guesses.
595 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100596static const struct drm_display_mode edid_est_modes[] = {
597 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
598 968, 1056, 0, 600, 601, 605, 628, 0,
599 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
600 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
601 896, 1024, 0, 600, 601, 603, 625, 0,
602 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
603 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
604 720, 840, 0, 480, 481, 484, 500, 0,
605 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
606 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
Paul Parsons87707cf2016-04-02 11:08:06 +0100607 704, 832, 0, 480, 489, 492, 520, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100608 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
609 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
610 768, 864, 0, 480, 483, 486, 525, 0,
611 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100612 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
Thierry Redinga6b21832012-11-23 15:01:42 +0100613 752, 800, 0, 480, 490, 492, 525, 0,
614 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
615 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
616 846, 900, 0, 400, 421, 423, 449, 0,
617 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
618 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
619 846, 900, 0, 400, 412, 414, 449, 0,
620 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
621 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
622 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
623 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
Paul Parsons87707cf2016-04-02 11:08:06 +0100624 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
Thierry Redinga6b21832012-11-23 15:01:42 +0100625 1136, 1312, 0, 768, 769, 772, 800, 0,
626 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
627 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
628 1184, 1328, 0, 768, 771, 777, 806, 0,
629 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
630 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
631 1184, 1344, 0, 768, 771, 777, 806, 0,
632 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
633 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
634 1208, 1264, 0, 768, 768, 776, 817, 0,
635 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
636 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
637 928, 1152, 0, 624, 625, 628, 667, 0,
638 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
639 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
640 896, 1056, 0, 600, 601, 604, 625, 0,
641 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
642 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
643 976, 1040, 0, 600, 637, 643, 666, 0,
644 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
645 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
646 1344, 1600, 0, 864, 865, 868, 900, 0,
647 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
648};
649
650struct minimode {
651 short w;
652 short h;
653 short r;
654 short rb;
655};
656
657static const struct minimode est3_modes[] = {
658 /* byte 6 */
659 { 640, 350, 85, 0 },
660 { 640, 400, 85, 0 },
661 { 720, 400, 85, 0 },
662 { 640, 480, 85, 0 },
663 { 848, 480, 60, 0 },
664 { 800, 600, 85, 0 },
665 { 1024, 768, 85, 0 },
666 { 1152, 864, 75, 0 },
667 /* byte 7 */
668 { 1280, 768, 60, 1 },
669 { 1280, 768, 60, 0 },
670 { 1280, 768, 75, 0 },
671 { 1280, 768, 85, 0 },
672 { 1280, 960, 60, 0 },
673 { 1280, 960, 85, 0 },
674 { 1280, 1024, 60, 0 },
675 { 1280, 1024, 85, 0 },
676 /* byte 8 */
677 { 1360, 768, 60, 0 },
678 { 1440, 900, 60, 1 },
679 { 1440, 900, 60, 0 },
680 { 1440, 900, 75, 0 },
681 { 1440, 900, 85, 0 },
682 { 1400, 1050, 60, 1 },
683 { 1400, 1050, 60, 0 },
684 { 1400, 1050, 75, 0 },
685 /* byte 9 */
686 { 1400, 1050, 85, 0 },
687 { 1680, 1050, 60, 1 },
688 { 1680, 1050, 60, 0 },
689 { 1680, 1050, 75, 0 },
690 { 1680, 1050, 85, 0 },
691 { 1600, 1200, 60, 0 },
692 { 1600, 1200, 65, 0 },
693 { 1600, 1200, 70, 0 },
694 /* byte 10 */
695 { 1600, 1200, 75, 0 },
696 { 1600, 1200, 85, 0 },
697 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300698 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100699 { 1856, 1392, 60, 0 },
700 { 1856, 1392, 75, 0 },
701 { 1920, 1200, 60, 1 },
702 { 1920, 1200, 60, 0 },
703 /* byte 11 */
704 { 1920, 1200, 75, 0 },
705 { 1920, 1200, 85, 0 },
706 { 1920, 1440, 60, 0 },
707 { 1920, 1440, 75, 0 },
708};
709
710static const struct minimode extra_modes[] = {
711 { 1024, 576, 60, 0 },
712 { 1366, 768, 60, 0 },
713 { 1600, 900, 60, 0 },
714 { 1680, 945, 60, 0 },
715 { 1920, 1080, 60, 0 },
716 { 2048, 1152, 60, 0 },
717 { 2048, 1536, 60, 0 },
718};
719
720/*
Ville Syrjälä7befe622019-12-13 19:43:45 +0200721 * From CEA/CTA-861 spec.
Jani Nikulad9278b42016-01-08 13:21:51 +0200722 *
Ville Syrjälä7befe622019-12-13 19:43:45 +0200723 * Do not access directly, instead always use cea_mode_for_vic().
Thierry Redinga6b21832012-11-23 15:01:42 +0100724 */
Ville Syrjälä8c1b2bd2019-12-13 19:43:47 +0200725static const struct drm_display_mode edid_cea_modes_1[] = {
Ville Syrjälä78691962018-05-24 22:20:35 +0300726 /* 1 - 640x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100727 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
728 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300729 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300730 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300731 /* 2 - 720x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100732 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
733 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300734 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300735 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300736 /* 3 - 720x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100737 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
738 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300739 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300740 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300741 /* 4 - 1280x720@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100742 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
743 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300744 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300745 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300746 /* 5 - 1920x1080i@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100747 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
748 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
749 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300750 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300751 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300752 /* 6 - 720(1440)x480i@60Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700753 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
754 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100755 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300756 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300757 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300758 /* 7 - 720(1440)x480i@60Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700759 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
760 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100761 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300762 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300763 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300764 /* 8 - 720(1440)x240@60Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700765 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
766 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100767 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300768 DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300769 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300770 /* 9 - 720(1440)x240@60Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700771 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
772 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100773 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300774 DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300775 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300776 /* 10 - 2880x480i@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100777 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
778 3204, 3432, 0, 480, 488, 494, 525, 0,
779 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300780 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300781 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300782 /* 11 - 2880x480i@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100783 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
784 3204, 3432, 0, 480, 488, 494, 525, 0,
785 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300786 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300787 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300788 /* 12 - 2880x240@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100789 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
790 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300791 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300792 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300793 /* 13 - 2880x240@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100794 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
795 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300796 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300797 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300798 /* 14 - 1440x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100799 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
800 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300801 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300802 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300803 /* 15 - 1440x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100804 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
805 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300806 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300807 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300808 /* 16 - 1920x1080@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100809 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
810 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300811 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300812 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300813 /* 17 - 720x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100814 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
815 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300816 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300817 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300818 /* 18 - 720x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100819 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
820 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300821 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300822 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300823 /* 19 - 1280x720@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100824 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
825 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300826 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300827 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300828 /* 20 - 1920x1080i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100829 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
830 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
831 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300832 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300833 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300834 /* 21 - 720(1440)x576i@50Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700835 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
836 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100837 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300838 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300839 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300840 /* 22 - 720(1440)x576i@50Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700841 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
842 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100843 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300844 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300845 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300846 /* 23 - 720(1440)x288@50Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700847 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
848 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100849 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300850 DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300851 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300852 /* 24 - 720(1440)x288@50Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700853 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
854 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100855 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300856 DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300857 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300858 /* 25 - 2880x576i@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100859 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
860 3180, 3456, 0, 576, 580, 586, 625, 0,
861 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300862 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300863 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300864 /* 26 - 2880x576i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100865 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
866 3180, 3456, 0, 576, 580, 586, 625, 0,
867 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300868 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300869 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300870 /* 27 - 2880x288@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100871 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
872 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300873 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300874 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300875 /* 28 - 2880x288@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100876 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
877 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300878 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300879 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300880 /* 29 - 1440x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100881 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
882 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300883 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300884 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300885 /* 30 - 1440x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100886 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
887 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300888 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300889 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300890 /* 31 - 1920x1080@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100891 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
892 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300893 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300894 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300895 /* 32 - 1920x1080@24Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100896 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
897 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300898 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300899 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300900 /* 33 - 1920x1080@25Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100901 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
902 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300903 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300904 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300905 /* 34 - 1920x1080@30Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100906 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
907 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300908 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300909 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300910 /* 35 - 2880x480@60Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100911 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
912 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300913 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300914 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300915 /* 36 - 2880x480@60Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100916 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
917 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300918 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300919 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300920 /* 37 - 2880x576@50Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100921 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
922 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300923 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300924 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300925 /* 38 - 2880x576@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100926 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
927 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300928 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300929 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300930 /* 39 - 1920x1080i@50Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100931 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
932 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
933 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300934 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300935 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300936 /* 40 - 1920x1080i@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100937 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
938 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
939 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300940 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300941 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300942 /* 41 - 1280x720@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100943 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
944 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300945 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300946 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300947 /* 42 - 720x576@100Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100948 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
949 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300950 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300951 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300952 /* 43 - 720x576@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100953 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
954 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300955 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300956 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300957 /* 44 - 720(1440)x576i@100Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700958 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
959 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100960 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300961 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300962 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300963 /* 45 - 720(1440)x576i@100Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700964 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
965 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100966 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300967 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300968 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300969 /* 46 - 1920x1080i@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100970 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
971 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
972 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300973 DRM_MODE_FLAG_INTERLACE),
Ville Syrjälä04256622020-04-28 20:19:27 +0300974 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300975 /* 47 - 1280x720@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100976 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
977 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300978 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300979 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300980 /* 48 - 720x480@120Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100981 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
982 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300983 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300984 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300985 /* 49 - 720x480@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100986 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
987 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300988 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +0300989 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300990 /* 50 - 720(1440)x480i@120Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700991 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
992 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100993 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +0300994 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +0300995 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +0300996 /* 51 - 720(1440)x480i@120Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -0700997 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
998 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100999 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001000 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +03001001 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001002 /* 52 - 720x576@200Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001003 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
1004 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001005 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001006 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001007 /* 53 - 720x576@200Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001008 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
1009 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001010 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001011 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001012 /* 54 - 720(1440)x576i@200Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001013 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1014 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001015 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001016 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +03001017 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001018 /* 55 - 720(1440)x576i@200Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001019 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1020 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001021 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001022 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +03001023 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001024 /* 56 - 720x480@240Hz 4:3 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001025 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1026 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001027 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001028 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001029 /* 57 - 720x480@240Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001030 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1031 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001032 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001033 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001034 /* 58 - 720(1440)x480i@240Hz 4:3 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001035 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1036 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001037 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001038 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +03001039 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001040 /* 59 - 720(1440)x480i@240Hz 16:9 */
Clint Taylorfb01d282014-09-02 17:03:35 -07001041 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1042 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +01001043 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjälä78691962018-05-24 22:20:35 +03001044 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Ville Syrjälä04256622020-04-28 20:19:27 +03001045 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001046 /* 60 - 1280x720@24Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001047 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1048 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001049 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001050 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001051 /* 61 - 1280x720@25Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001052 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1053 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001054 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001055 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001056 /* 62 - 1280x720@30Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001057 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1058 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001059 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001060 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001061 /* 63 - 1920x1080@120Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001062 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1063 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001064 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001065 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001066 /* 64 - 1920x1080@100Hz 16:9 */
Thierry Redinga6b21832012-11-23 15:01:42 +01001067 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
Clint Taylor8f0e4902016-08-15 10:31:28 -07001068 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +03001069 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001070 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001071 /* 65 - 1280x720@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301072 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1073 3080, 3300, 0, 720, 725, 730, 750, 0,
1074 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001075 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001076 /* 66 - 1280x720@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301077 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1078 3740, 3960, 0, 720, 725, 730, 750, 0,
1079 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001080 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001081 /* 67 - 1280x720@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301082 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1083 3080, 3300, 0, 720, 725, 730, 750, 0,
1084 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001085 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001086 /* 68 - 1280x720@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301087 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1088 1760, 1980, 0, 720, 725, 730, 750, 0,
1089 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001090 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001091 /* 69 - 1280x720@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301092 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1093 1430, 1650, 0, 720, 725, 730, 750, 0,
1094 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001095 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001096 /* 70 - 1280x720@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301097 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1098 1760, 1980, 0, 720, 725, 730, 750, 0,
1099 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001100 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001101 /* 71 - 1280x720@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301102 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1103 1430, 1650, 0, 720, 725, 730, 750, 0,
1104 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001105 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001106 /* 72 - 1920x1080@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301107 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1108 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1109 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001110 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001111 /* 73 - 1920x1080@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301112 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1113 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1114 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001115 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001116 /* 74 - 1920x1080@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301117 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1118 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1119 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001120 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001121 /* 75 - 1920x1080@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301122 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1123 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1124 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001125 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001126 /* 76 - 1920x1080@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301127 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1128 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1129 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001130 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001131 /* 77 - 1920x1080@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301132 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1133 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1134 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001135 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001136 /* 78 - 1920x1080@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301137 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1138 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1139 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001140 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001141 /* 79 - 1680x720@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301142 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1143 3080, 3300, 0, 720, 725, 730, 750, 0,
1144 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001145 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001146 /* 80 - 1680x720@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301147 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1148 2948, 3168, 0, 720, 725, 730, 750, 0,
1149 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001150 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001151 /* 81 - 1680x720@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301152 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1153 2420, 2640, 0, 720, 725, 730, 750, 0,
1154 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001155 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001156 /* 82 - 1680x720@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301157 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1158 1980, 2200, 0, 720, 725, 730, 750, 0,
1159 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001160 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001161 /* 83 - 1680x720@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301162 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1163 1980, 2200, 0, 720, 725, 730, 750, 0,
1164 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001165 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001166 /* 84 - 1680x720@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301167 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1168 1780, 2000, 0, 720, 725, 730, 825, 0,
1169 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001170 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001171 /* 85 - 1680x720@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301172 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1173 1780, 2000, 0, 720, 725, 730, 825, 0,
1174 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001175 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001176 /* 86 - 2560x1080@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301177 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1178 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1179 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001180 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001181 /* 87 - 2560x1080@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301182 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1183 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1184 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001185 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001186 /* 88 - 2560x1080@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301187 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1188 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1189 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001190 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001191 /* 89 - 2560x1080@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301192 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1193 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1194 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001195 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001196 /* 90 - 2560x1080@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301197 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1198 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1199 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001200 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001201 /* 91 - 2560x1080@100Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301202 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1203 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1204 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001205 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001206 /* 92 - 2560x1080@120Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301207 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1208 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1209 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001210 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001211 /* 93 - 3840x2160@24Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301212 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1213 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1214 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001215 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001216 /* 94 - 3840x2160@25Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301217 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1218 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1219 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001220 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001221 /* 95 - 3840x2160@30Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301222 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1223 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1224 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001225 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001226 /* 96 - 3840x2160@50Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301227 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1228 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1229 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001230 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001231 /* 97 - 3840x2160@60Hz 16:9 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301232 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1233 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1234 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001235 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001236 /* 98 - 4096x2160@24Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301237 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1238 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1239 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001240 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001241 /* 99 - 4096x2160@25Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301242 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1243 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1244 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001245 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001246 /* 100 - 4096x2160@30Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301247 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1248 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1249 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001250 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001251 /* 101 - 4096x2160@50Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301252 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1253 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1254 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001255 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001256 /* 102 - 4096x2160@60Hz 256:135 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301257 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1258 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1259 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001260 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001261 /* 103 - 3840x2160@24Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301262 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1263 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1264 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001265 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001266 /* 104 - 3840x2160@25Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301267 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1268 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1269 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001270 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001271 /* 105 - 3840x2160@30Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301272 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1273 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1274 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001275 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001276 /* 106 - 3840x2160@50Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301277 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1278 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1279 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001280 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä78691962018-05-24 22:20:35 +03001281 /* 107 - 3840x2160@60Hz 64:27 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05301282 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1283 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1284 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001285 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001286 /* 108 - 1280x720@48Hz 16:9 */
1287 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
1288 2280, 2500, 0, 720, 725, 730, 750, 0,
1289 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001290 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001291 /* 109 - 1280x720@48Hz 64:27 */
1292 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
1293 2280, 2500, 0, 720, 725, 730, 750, 0,
1294 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001295 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001296 /* 110 - 1680x720@48Hz 64:27 */
1297 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 2490,
1298 2530, 2750, 0, 720, 725, 730, 750, 0,
1299 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001300 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001301 /* 111 - 1920x1080@48Hz 16:9 */
1302 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
1303 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1304 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001305 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001306 /* 112 - 1920x1080@48Hz 64:27 */
1307 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
1308 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1309 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001310 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001311 /* 113 - 2560x1080@48Hz 64:27 */
1312 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 3558,
1313 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1314 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001315 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001316 /* 114 - 3840x2160@48Hz 16:9 */
1317 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
1318 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1319 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001320 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001321 /* 115 - 4096x2160@48Hz 256:135 */
1322 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5116,
1323 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1324 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001325 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001326 /* 116 - 3840x2160@48Hz 64:27 */
1327 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
1328 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1329 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001330 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001331 /* 117 - 3840x2160@100Hz 16:9 */
1332 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
1333 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1334 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001335 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001336 /* 118 - 3840x2160@120Hz 16:9 */
1337 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
1338 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1339 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001340 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001341 /* 119 - 3840x2160@100Hz 64:27 */
1342 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
1343 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1344 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001345 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001346 /* 120 - 3840x2160@120Hz 64:27 */
1347 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
1348 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1349 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001350 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001351 /* 121 - 5120x2160@24Hz 64:27 */
1352 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 7116,
1353 7204, 7500, 0, 2160, 2168, 2178, 2200, 0,
1354 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001355 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001356 /* 122 - 5120x2160@25Hz 64:27 */
1357 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 6816,
1358 6904, 7200, 0, 2160, 2168, 2178, 2200, 0,
1359 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001360 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001361 /* 123 - 5120x2160@30Hz 64:27 */
1362 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 5784,
1363 5872, 6000, 0, 2160, 2168, 2178, 2200, 0,
1364 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001365 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001366 /* 124 - 5120x2160@48Hz 64:27 */
1367 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5866,
1368 5954, 6250, 0, 2160, 2168, 2178, 2475, 0,
1369 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001370 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001371 /* 125 - 5120x2160@50Hz 64:27 */
1372 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 6216,
1373 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
1374 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001375 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001376 /* 126 - 5120x2160@60Hz 64:27 */
1377 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5284,
1378 5372, 5500, 0, 2160, 2168, 2178, 2250, 0,
1379 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001380 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjälä978f6b02019-07-11 13:32:30 +03001381 /* 127 - 5120x2160@100Hz 64:27 */
1382 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 1485000, 5120, 6216,
1383 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
1384 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001385 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Thierry Redinga6b21832012-11-23 15:01:42 +01001386};
1387
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001388/*
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001389 * From CEA/CTA-861 spec.
1390 *
1391 * Do not access directly, instead always use cea_mode_for_vic().
1392 */
1393static const struct drm_display_mode edid_cea_modes_193[] = {
1394 /* 193 - 5120x2160@120Hz 64:27 */
1395 { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 1485000, 5120, 5284,
1396 5372, 5500, 0, 2160, 2168, 2178, 2250, 0,
1397 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001398 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001399 /* 194 - 7680x4320@24Hz 16:9 */
1400 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 10232,
1401 10408, 11000, 0, 4320, 4336, 4356, 4500, 0,
1402 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001403 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001404 /* 195 - 7680x4320@25Hz 16:9 */
1405 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 10032,
1406 10208, 10800, 0, 4320, 4336, 4356, 4400, 0,
1407 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001408 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001409 /* 196 - 7680x4320@30Hz 16:9 */
1410 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 8232,
1411 8408, 9000, 0, 4320, 4336, 4356, 4400, 0,
1412 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001413 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001414 /* 197 - 7680x4320@48Hz 16:9 */
1415 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 10232,
1416 10408, 11000, 0, 4320, 4336, 4356, 4500, 0,
1417 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001418 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001419 /* 198 - 7680x4320@50Hz 16:9 */
1420 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 10032,
1421 10208, 10800, 0, 4320, 4336, 4356, 4400, 0,
1422 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001423 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001424 /* 199 - 7680x4320@60Hz 16:9 */
1425 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 8232,
1426 8408, 9000, 0, 4320, 4336, 4356, 4400, 0,
1427 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001428 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001429 /* 200 - 7680x4320@100Hz 16:9 */
1430 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 4752000, 7680, 9792,
1431 9968, 10560, 0, 4320, 4336, 4356, 4500, 0,
1432 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001433 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001434 /* 201 - 7680x4320@120Hz 16:9 */
1435 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 4752000, 7680, 8032,
1436 8208, 8800, 0, 4320, 4336, 4356, 4500, 0,
1437 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001438 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001439 /* 202 - 7680x4320@24Hz 64:27 */
1440 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 10232,
1441 10408, 11000, 0, 4320, 4336, 4356, 4500, 0,
1442 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001443 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001444 /* 203 - 7680x4320@25Hz 64:27 */
1445 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 10032,
1446 10208, 10800, 0, 4320, 4336, 4356, 4400, 0,
1447 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001448 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001449 /* 204 - 7680x4320@30Hz 64:27 */
1450 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 8232,
1451 8408, 9000, 0, 4320, 4336, 4356, 4400, 0,
1452 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001453 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001454 /* 205 - 7680x4320@48Hz 64:27 */
1455 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 10232,
1456 10408, 11000, 0, 4320, 4336, 4356, 4500, 0,
1457 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001458 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001459 /* 206 - 7680x4320@50Hz 64:27 */
1460 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 10032,
1461 10208, 10800, 0, 4320, 4336, 4356, 4400, 0,
1462 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001463 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001464 /* 207 - 7680x4320@60Hz 64:27 */
1465 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 8232,
1466 8408, 9000, 0, 4320, 4336, 4356, 4400, 0,
1467 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001468 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001469 /* 208 - 7680x4320@100Hz 64:27 */
1470 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 4752000, 7680, 9792,
1471 9968, 10560, 0, 4320, 4336, 4356, 4500, 0,
1472 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001473 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001474 /* 209 - 7680x4320@120Hz 64:27 */
1475 { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 4752000, 7680, 8032,
1476 8208, 8800, 0, 4320, 4336, 4356, 4500, 0,
1477 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001478 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001479 /* 210 - 10240x4320@24Hz 64:27 */
1480 { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 1485000, 10240, 11732,
1481 11908, 12500, 0, 4320, 4336, 4356, 4950, 0,
1482 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001483 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001484 /* 211 - 10240x4320@25Hz 64:27 */
1485 { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 1485000, 10240, 12732,
1486 12908, 13500, 0, 4320, 4336, 4356, 4400, 0,
1487 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001488 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001489 /* 212 - 10240x4320@30Hz 64:27 */
1490 { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 1485000, 10240, 10528,
1491 10704, 11000, 0, 4320, 4336, 4356, 4500, 0,
1492 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001493 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001494 /* 213 - 10240x4320@48Hz 64:27 */
1495 { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 2970000, 10240, 11732,
1496 11908, 12500, 0, 4320, 4336, 4356, 4950, 0,
1497 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001498 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001499 /* 214 - 10240x4320@50Hz 64:27 */
1500 { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 2970000, 10240, 12732,
1501 12908, 13500, 0, 4320, 4336, 4356, 4400, 0,
1502 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001503 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001504 /* 215 - 10240x4320@60Hz 64:27 */
1505 { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 2970000, 10240, 10528,
1506 10704, 11000, 0, 4320, 4336, 4356, 4500, 0,
1507 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001508 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001509 /* 216 - 10240x4320@100Hz 64:27 */
1510 { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 5940000, 10240, 12432,
1511 12608, 13200, 0, 4320, 4336, 4356, 4500, 0,
1512 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001513 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001514 /* 217 - 10240x4320@120Hz 64:27 */
1515 { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 5940000, 10240, 10528,
1516 10704, 11000, 0, 4320, 4336, 4356, 4500, 0,
1517 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001518 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001519 /* 218 - 4096x2160@100Hz 256:135 */
1520 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 1188000, 4096, 4896,
1521 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1522 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001523 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001524 /* 219 - 4096x2160@120Hz 256:135 */
1525 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 1188000, 4096, 4184,
1526 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1527 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001528 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Ville Syrjäläf7655d42019-12-13 19:43:46 +02001529};
1530
1531/*
Jani Nikulad9278b42016-01-08 13:21:51 +02001532 * HDMI 1.4 4k modes. Index using the VIC.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001533 */
1534static const struct drm_display_mode edid_4k_modes[] = {
Jani Nikulad9278b42016-01-08 13:21:51 +02001535 /* 0 - dummy, VICs start at 1 */
1536 { },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001537 /* 1 - 3840x2160@30Hz */
1538 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1539 3840, 4016, 4104, 4400, 0,
1540 2160, 2168, 2178, 2250, 0,
1541 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001542 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001543 /* 2 - 3840x2160@25Hz */
1544 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1545 3840, 4896, 4984, 5280, 0,
1546 2160, 2168, 2178, 2250, 0,
1547 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001548 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001549 /* 3 - 3840x2160@24Hz */
1550 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1551 3840, 5116, 5204, 5500, 0,
1552 2160, 2168, 2178, 2250, 0,
1553 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001554 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001555 /* 4 - 4096x2160@24Hz (SMPTE) */
1556 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1557 4096, 5116, 5204, 5500, 0,
1558 2160, 2168, 2178, 2250, 0,
1559 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Ville Syrjälä04256622020-04-28 20:19:27 +03001560 .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01001561};
1562
Adam Jackson61e57a82010-03-29 21:43:18 +00001563/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -08001564
Adam Jackson083ae052009-09-23 17:30:45 -04001565static const u8 edid_header[] = {
1566 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1567};
Dave Airlief453ba02008-11-07 14:05:41 -08001568
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001569/**
1570 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1571 * @raw_edid: pointer to raw base EDID block
1572 *
1573 * Sanity check the header of the base EDID block.
1574 *
1575 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +00001576 */
1577int drm_edid_header_is_valid(const u8 *raw_edid)
1578{
1579 int i, score = 0;
1580
1581 for (i = 0; i < sizeof(edid_header); i++)
1582 if (raw_edid[i] == edid_header[i])
1583 score++;
1584
1585 return score;
1586}
1587EXPORT_SYMBOL(drm_edid_header_is_valid);
1588
Adam Jackson47819ba2012-05-30 16:42:39 -04001589static int edid_fixup __read_mostly = 6;
1590module_param_named(edid_fixup, edid_fixup, int, 0400);
1591MODULE_PARM_DESC(edid_fixup,
1592 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001593
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001594static int drm_edid_block_checksum(const u8 *raw_edid)
1595{
1596 int i;
Jerry (Fangzhi) Zuoe11f5bd2020-02-11 11:08:32 -05001597 u8 csum = 0, crc = 0;
1598
1599 for (i = 0; i < EDID_LENGTH - 1; i++)
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001600 csum += raw_edid[i];
1601
Jerry (Fangzhi) Zuoe11f5bd2020-02-11 11:08:32 -05001602 crc = 0x100 - csum;
1603
1604 return crc;
1605}
1606
1607static bool drm_edid_block_checksum_diff(const u8 *raw_edid, u8 real_checksum)
1608{
1609 if (raw_edid[EDID_LENGTH - 1] != real_checksum)
1610 return true;
1611 else
1612 return false;
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001613}
1614
Stefan Brünsd6885d62014-11-30 19:57:41 +01001615static bool drm_edid_is_zero(const u8 *in_edid, int length)
1616{
1617 if (memchr_inv(in_edid, 0, length))
1618 return false;
1619
1620 return true;
1621}
1622
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001623/**
Stanislav Lisovskiy536faa42020-06-30 05:56:58 +05301624 * drm_edid_are_equal - compare two edid blobs.
1625 * @edid1: pointer to first blob
1626 * @edid2: pointer to second blob
1627 * This helper can be used during probing to determine if
1628 * edid had changed.
1629 */
1630bool drm_edid_are_equal(const struct edid *edid1, const struct edid *edid2)
1631{
1632 int edid1_len, edid2_len;
1633 bool edid1_present = edid1 != NULL;
1634 bool edid2_present = edid2 != NULL;
1635
1636 if (edid1_present != edid2_present)
1637 return false;
1638
1639 if (edid1) {
Stanislav Lisovskiy536faa42020-06-30 05:56:58 +05301640 edid1_len = EDID_LENGTH * (1 + edid1->extensions);
1641 edid2_len = EDID_LENGTH * (1 + edid2->extensions);
1642
1643 if (edid1_len != edid2_len)
1644 return false;
1645
1646 if (memcmp(edid1, edid2, edid1_len))
1647 return false;
1648 }
1649
1650 return true;
1651}
1652EXPORT_SYMBOL(drm_edid_are_equal);
1653
Stanislav Lisovskiy536faa42020-06-30 05:56:58 +05301654/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001655 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1656 * @raw_edid: pointer to raw EDID block
1657 * @block: type of block to validate (0 for base, extension otherwise)
1658 * @print_bad_edid: if true, dump bad EDID blocks to the console
Todd Previte6ba2bd32015-04-21 11:09:41 -07001659 * @edid_corrupt: if true, the header or checksum is invalid
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001660 *
1661 * Validate a base or extension EDID block and optionally dump bad blocks to
1662 * the console.
1663 *
1664 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001665 */
Todd Previte6ba2bd32015-04-21 11:09:41 -07001666bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1667 bool *edid_corrupt)
Dave Airlief453ba02008-11-07 14:05:41 -08001668{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001669 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001670 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001671
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001672 if (WARN_ON(!raw_edid))
1673 return false;
1674
Adam Jackson47819ba2012-05-30 16:42:39 -04001675 if (edid_fixup > 8 || edid_fixup < 0)
1676 edid_fixup = 6;
1677
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001678 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001679 int score = drm_edid_header_is_valid(raw_edid);
Suraj Upadhyay948de8422020-07-02 18:53:32 +05301680
Todd Previte6ba2bd32015-04-21 11:09:41 -07001681 if (score == 8) {
1682 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001683 *edid_corrupt = false;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001684 } else if (score >= edid_fixup) {
1685 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1686 * The corrupt flag needs to be set here otherwise, the
1687 * fix-up code here will correct the problem, the
1688 * checksum is correct and the test fails
1689 */
1690 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001691 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001692 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1693 memcpy(raw_edid, edid_header, sizeof(edid_header));
1694 } else {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001695 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001696 *edid_corrupt = true;
Adam Jackson61e57a82010-03-29 21:43:18 +00001697 goto bad;
1698 }
1699 }
Dave Airlief453ba02008-11-07 14:05:41 -08001700
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001701 csum = drm_edid_block_checksum(raw_edid);
Jerry (Fangzhi) Zuoe11f5bd2020-02-11 11:08:32 -05001702 if (drm_edid_block_checksum_diff(raw_edid, csum)) {
Todd Previte6ba2bd32015-04-21 11:09:41 -07001703 if (edid_corrupt)
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001704 *edid_corrupt = true;
Todd Previte6ba2bd32015-04-21 11:09:41 -07001705
Adam Jackson4a638b42010-05-25 16:33:09 -04001706 /* allow CEA to slide through, switches mangle this */
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001707 if (raw_edid[0] == CEA_EXT) {
1708 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1709 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1710 } else {
1711 if (print_bad_edid)
Chris Wilson813a7872017-02-10 19:59:13 +00001712 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001713
Adam Jackson4a638b42010-05-25 16:33:09 -04001714 goto bad;
Tomeu Vizoso82d75352016-12-08 14:11:56 +01001715 }
Dave Airlief453ba02008-11-07 14:05:41 -08001716 }
1717
Adam Jackson61e57a82010-03-29 21:43:18 +00001718 /* per-block-type checks */
1719 switch (raw_edid[0]) {
1720 case 0: /* base */
1721 if (edid->version != 1) {
Chris Wilson813a7872017-02-10 19:59:13 +00001722 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
Adam Jackson61e57a82010-03-29 21:43:18 +00001723 goto bad;
1724 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001725
Adam Jackson61e57a82010-03-29 21:43:18 +00001726 if (edid->revision > 4)
1727 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1728 break;
1729
1730 default:
1731 break;
1732 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001733
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001734 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001735
1736bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001737 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001738 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
Joe Perches499447d2017-02-28 04:55:53 -08001739 pr_notice("EDID block is all zeroes\n");
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001740 } else {
Joe Perches499447d2017-02-28 04:55:53 -08001741 pr_notice("Raw EDID:\n");
Chris Wilson813a7872017-02-10 19:59:13 +00001742 print_hex_dump(KERN_NOTICE,
1743 " \t", DUMP_PREFIX_NONE, 16, 1,
1744 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001745 }
Dave Airlief453ba02008-11-07 14:05:41 -08001746 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001747 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001748}
Carsten Emdeda0df922012-03-18 22:37:33 +01001749EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001750
1751/**
1752 * drm_edid_is_valid - sanity check EDID data
1753 * @edid: EDID data
1754 *
1755 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001756 *
1757 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001758 */
1759bool drm_edid_is_valid(struct edid *edid)
1760{
1761 int i;
1762 u8 *raw = (u8 *)edid;
1763
1764 if (!edid)
1765 return false;
1766
1767 for (i = 0; i <= edid->extensions; i++)
Todd Previte6ba2bd32015-04-21 11:09:41 -07001768 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00001769 return false;
1770
1771 return true;
1772}
Alex Deucher3c537882010-02-05 04:21:19 -05001773EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001774
Adam Jackson61e57a82010-03-29 21:43:18 +00001775#define DDC_SEGMENT_ADDR 0x30
1776/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001777 * drm_do_probe_ddc_edid() - get EDID information via I2C
Thierry Reding7c58e872014-12-03 16:52:18 +01001778 * @data: I2C device adapter
Daniel Vetterfc668112014-01-21 12:02:26 +01001779 * @buf: EDID data buffer to be filled
1780 * @block: 128 byte EDID block to start fetching from
1781 * @len: EDID data buffer length to fetch
1782 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001783 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001784 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001785 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001786 */
1787static int
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001788drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
Adam Jackson61e57a82010-03-29 21:43:18 +00001789{
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001790 struct i2c_adapter *adapter = data;
Adam Jackson61e57a82010-03-29 21:43:18 +00001791 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001792 unsigned char segment = block >> 1;
1793 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001794 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001795
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001796 /*
1797 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001798 * adapter reports EAGAIN. However, we find that bit-banging transfers
1799 * are susceptible to errors under a heavily loaded machine and
1800 * generate spurious NAKs and timeouts. Retrying the transfer
1801 * of the individual block a few times seems to overcome this.
1802 */
1803 do {
1804 struct i2c_msg msgs[] = {
1805 {
Shirish Scd004b32012-08-30 07:04:06 +00001806 .addr = DDC_SEGMENT_ADDR,
1807 .flags = 0,
1808 .len = 1,
1809 .buf = &segment,
1810 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001811 .addr = DDC_ADDR,
1812 .flags = 0,
1813 .len = 1,
1814 .buf = &start,
1815 }, {
1816 .addr = DDC_ADDR,
1817 .flags = I2C_M_RD,
1818 .len = len,
1819 .buf = buf,
1820 }
1821 };
Shirish Scd004b32012-08-30 07:04:06 +00001822
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001823 /*
1824 * Avoid sending the segment addr to not upset non-compliant
1825 * DDC monitors.
1826 */
Shirish Scd004b32012-08-30 07:04:06 +00001827 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1828
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001829 if (ret == -ENXIO) {
1830 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1831 adapter->name);
1832 break;
1833 }
Shirish Scd004b32012-08-30 07:04:06 +00001834 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001835
Shirish Scd004b32012-08-30 07:04:06 +00001836 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001837}
1838
Chris Wilson14544d02016-10-24 12:38:21 +01001839static void connector_bad_edid(struct drm_connector *connector,
1840 u8 *edid, int num_blocks)
1841{
1842 int i;
Jerry (Fangzhi) Zuoe11f5bd2020-02-11 11:08:32 -05001843 u8 num_of_ext = edid[0x7e];
1844
1845 /* Calculate real checksum for the last edid extension block data */
1846 connector->real_edid_checksum =
1847 drm_edid_block_checksum(edid + num_of_ext * EDID_LENGTH);
Chris Wilson14544d02016-10-24 12:38:21 +01001848
Jani Nikulaf0a8f532019-10-01 17:06:14 +03001849 if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS))
Chris Wilson14544d02016-10-24 12:38:21 +01001850 return;
1851
Chris Wilsonfa3bfa32020-10-29 21:30:42 +00001852 drm_dbg_kms(connector->dev, "%s: EDID is invalid:\n", connector->name);
Chris Wilson14544d02016-10-24 12:38:21 +01001853 for (i = 0; i < num_blocks; i++) {
1854 u8 *block = edid + i * EDID_LENGTH;
1855 char prefix[20];
1856
1857 if (drm_edid_is_zero(block, EDID_LENGTH))
1858 sprintf(prefix, "\t[%02x] ZERO ", i);
1859 else if (!drm_edid_block_valid(block, i, false, NULL))
1860 sprintf(prefix, "\t[%02x] BAD ", i);
1861 else
1862 sprintf(prefix, "\t[%02x] GOOD ", i);
1863
Chris Wilsonfa3bfa32020-10-29 21:30:42 +00001864 print_hex_dump(KERN_DEBUG,
Chris Wilson14544d02016-10-24 12:38:21 +01001865 prefix, DUMP_PREFIX_NONE, 16, 1,
1866 block, EDID_LENGTH, false);
1867 }
1868}
1869
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001870/* Get override or firmware EDID */
1871static struct edid *drm_get_override_edid(struct drm_connector *connector)
1872{
1873 struct edid *override = NULL;
1874
1875 if (connector->override_edid)
1876 override = drm_edid_duplicate(connector->edid_blob_ptr->data);
1877
1878 if (!override)
1879 override = drm_load_edid_firmware(connector);
1880
1881 return IS_ERR(override) ? NULL : override;
1882}
1883
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001884/**
Jani Nikula48eaeb72019-06-10 12:30:54 +03001885 * drm_add_override_edid_modes - add modes from override/firmware EDID
1886 * @connector: connector we're probing
1887 *
1888 * Add modes from the override/firmware EDID, if available. Only to be used from
1889 * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe
1890 * failed during drm_get_edid() and caused the override/firmware EDID to be
1891 * skipped.
1892 *
1893 * Return: The number of modes added or 0 if we couldn't find any.
1894 */
1895int drm_add_override_edid_modes(struct drm_connector *connector)
1896{
1897 struct edid *override;
1898 int num_modes = 0;
1899
1900 override = drm_get_override_edid(connector);
1901 if (override) {
1902 drm_connector_update_edid_property(connector, override);
1903 num_modes = drm_add_edid_modes(connector, override);
1904 kfree(override);
1905
1906 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] adding %d modes via fallback override/firmware EDID\n",
1907 connector->base.id, connector->name, num_modes);
1908 }
1909
1910 return num_modes;
1911}
1912EXPORT_SYMBOL(drm_add_override_edid_modes);
1913
Douglas Andersonbac9c292021-09-14 13:21:49 -07001914static struct edid *drm_do_get_edid_base_block(
1915 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1916 size_t len),
1917 void *data, bool *edid_corrupt, int *null_edid_counter)
1918{
1919 int i;
1920 void *edid;
1921
1922 edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
1923 if (edid == NULL)
1924 return NULL;
1925
1926 /* base block fetch */
1927 for (i = 0; i < 4; i++) {
1928 if (get_edid_block(data, edid, 0, EDID_LENGTH))
1929 goto out;
1930 if (drm_edid_block_valid(edid, 0, false, edid_corrupt))
1931 break;
1932 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
1933 if (null_edid_counter)
1934 (*null_edid_counter)++;
1935 goto carp;
1936 }
1937 }
1938 if (i == 4)
1939 goto carp;
1940
1941 return edid;
1942
1943carp:
1944 kfree(edid);
1945 return ERR_PTR(-EINVAL);
1946
1947out:
1948 kfree(edid);
1949 return NULL;
1950}
1951
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001952/**
1953 * drm_do_get_edid - get EDID data using a custom EDID block read function
1954 * @connector: connector we're probing
1955 * @get_edid_block: EDID block read function
1956 * @data: private data passed to the block read function
1957 *
1958 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1959 * exposes a different interface to read EDID blocks this function can be used
1960 * to get EDID data using a custom block read function.
1961 *
1962 * As in the general case the DDC bus is accessible by the kernel at the I2C
1963 * level, drivers must make all reasonable efforts to expose it as an I2C
1964 * adapter and use drm_get_edid() instead of abusing this function.
1965 *
Cai Huoqing0ae865e2021-07-30 21:27:29 +08001966 * The EDID may be overridden using debugfs override_edid or firmware EDID
Jani Nikula53fd40a2017-09-12 11:19:26 +03001967 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1968 * order. Having either of them bypasses actual EDID reads.
1969 *
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02001970 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1971 */
1972struct edid *drm_do_get_edid(struct drm_connector *connector,
1973 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1974 size_t len),
1975 void *data)
Adam Jackson61e57a82010-03-29 21:43:18 +00001976{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001977 int i, j = 0, valid_extensions = 0;
Chris Wilsonf14f3682016-10-17 09:35:12 +01001978 u8 *edid, *new;
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001979 struct edid *override;
Jani Nikula53fd40a2017-09-12 11:19:26 +03001980
Jani Nikula56a2b7f2019-06-07 14:05:12 +03001981 override = drm_get_override_edid(connector);
1982 if (override)
Jani Nikula53fd40a2017-09-12 11:19:26 +03001983 return override;
Adam Jackson61e57a82010-03-29 21:43:18 +00001984
Douglas Andersonbac9c292021-09-14 13:21:49 -07001985 edid = (u8 *)drm_do_get_edid_base_block(get_edid_block, data,
1986 &connector->edid_corrupt,
1987 &connector->null_edid_counter);
1988 if (IS_ERR_OR_NULL(edid)) {
1989 if (IS_ERR(edid))
1990 connector_bad_edid(connector, edid, 1);
Adam Jackson61e57a82010-03-29 21:43:18 +00001991 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00001992 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001993
Douglas Andersonbac9c292021-09-14 13:21:49 -07001994 /* if there's no extensions or no connector, we're done */
Chris Wilson14544d02016-10-24 12:38:21 +01001995 valid_extensions = edid[0x7e];
1996 if (valid_extensions == 0)
Chris Wilsonf14f3682016-10-17 09:35:12 +01001997 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001998
Chris Wilson14544d02016-10-24 12:38:21 +01001999 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
Adam Jackson61e57a82010-03-29 21:43:18 +00002000 if (!new)
2001 goto out;
Chris Wilsonf14f3682016-10-17 09:35:12 +01002002 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00002003
Chris Wilsonf14f3682016-10-17 09:35:12 +01002004 for (j = 1; j <= edid[0x7e]; j++) {
Chris Wilson14544d02016-10-24 12:38:21 +01002005 u8 *block = edid + j * EDID_LENGTH;
Chris Wilsona28187c2016-10-17 09:35:13 +01002006
Adam Jackson61e57a82010-03-29 21:43:18 +00002007 for (i = 0; i < 4; i++) {
Chris Wilsona28187c2016-10-17 09:35:13 +01002008 if (get_edid_block(data, block, j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00002009 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01002010 if (drm_edid_block_valid(block, j, false, NULL))
Adam Jackson61e57a82010-03-29 21:43:18 +00002011 break;
2012 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01002013
Chris Wilson14544d02016-10-24 12:38:21 +01002014 if (i == 4)
2015 valid_extensions--;
Sam Tygier0ea75e22010-09-23 10:11:01 +01002016 }
2017
Chris Wilsonf14f3682016-10-17 09:35:12 +01002018 if (valid_extensions != edid[0x7e]) {
Chris Wilson14544d02016-10-24 12:38:21 +01002019 u8 *base;
2020
2021 connector_bad_edid(connector, edid, edid[0x7e] + 1);
2022
Chris Wilsonf14f3682016-10-17 09:35:12 +01002023 edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
2024 edid[0x7e] = valid_extensions;
Chris Wilson14544d02016-10-24 12:38:21 +01002025
Kees Cook6da2ec52018-06-12 13:55:00 -07002026 new = kmalloc_array(valid_extensions + 1, EDID_LENGTH,
2027 GFP_KERNEL);
Sam Tygier0ea75e22010-09-23 10:11:01 +01002028 if (!new)
2029 goto out;
Chris Wilson14544d02016-10-24 12:38:21 +01002030
2031 base = new;
2032 for (i = 0; i <= edid[0x7e]; i++) {
2033 u8 *block = edid + i * EDID_LENGTH;
2034
2035 if (!drm_edid_block_valid(block, i, false, NULL))
2036 continue;
2037
2038 memcpy(base, block, EDID_LENGTH);
2039 base += EDID_LENGTH;
2040 }
2041
2042 kfree(edid);
Chris Wilsonf14f3682016-10-17 09:35:12 +01002043 edid = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00002044 }
2045
Chris Wilsonf14f3682016-10-17 09:35:12 +01002046 return (struct edid *)edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00002047
Adam Jackson61e57a82010-03-29 21:43:18 +00002048out:
Chris Wilsonf14f3682016-10-17 09:35:12 +01002049 kfree(edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00002050 return NULL;
2051}
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02002052EXPORT_SYMBOL_GPL(drm_do_get_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00002053
2054/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002055 * drm_probe_ddc() - probe DDC presence
2056 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00002057 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002058 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00002059 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04002060bool
Adam Jackson61e57a82010-03-29 21:43:18 +00002061drm_probe_ddc(struct i2c_adapter *adapter)
2062{
2063 unsigned char out;
2064
2065 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
2066}
Adam Jacksonfbff4692012-09-18 10:58:47 -04002067EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00002068
2069/**
2070 * drm_get_edid - get EDID data, if available
2071 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002072 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00002073 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002074 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00002075 * attach it to the connector.
2076 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002077 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00002078 */
2079struct edid *drm_get_edid(struct drm_connector *connector,
2080 struct i2c_adapter *adapter)
2081{
Stanislav Lisovskiy51864212020-06-30 05:56:59 +05302082 struct edid *edid;
2083
Jani Nikula15f080f2017-02-17 17:20:53 +02002084 if (connector->force == DRM_FORCE_OFF)
2085 return NULL;
2086
2087 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
Lars-Peter Clausen18df89f2012-04-27 11:11:58 +02002088 return NULL;
Adam Jackson61e57a82010-03-29 21:43:18 +00002089
Stanislav Lisovskiy51864212020-06-30 05:56:59 +05302090 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
2091 drm_connector_update_edid_property(connector, edid);
2092 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00002093}
2094EXPORT_SYMBOL(drm_get_edid);
2095
Douglas Andersond9f91a12021-09-14 13:21:50 -07002096static u32 edid_extract_panel_id(const struct edid *edid)
2097{
2098 /*
Douglas Andersone8de4d52021-09-14 13:21:51 -07002099 * We represent the ID as a 32-bit number so it can easily be compared
2100 * with "==".
Douglas Andersond9f91a12021-09-14 13:21:50 -07002101 *
2102 * NOTE that we deal with endianness differently for the top half
2103 * of this ID than for the bottom half. The bottom half (the product
2104 * id) gets decoded as little endian by the EDID_PRODUCT_ID because
2105 * that's how everyone seems to interpret it. The top half (the mfg_id)
2106 * gets stored as big endian because that makes
2107 * drm_edid_encode_panel_id() and drm_edid_decode_panel_id() easier
2108 * to write (it's easier to extract the ASCII). It doesn't really
2109 * matter, though, as long as the number here is unique.
2110 */
2111 return (u32)edid->mfg_id[0] << 24 |
2112 (u32)edid->mfg_id[1] << 16 |
2113 (u32)EDID_PRODUCT_ID(edid);
2114}
2115
2116/**
2117 * drm_edid_get_panel_id - Get a panel's ID through DDC
2118 * @adapter: I2C adapter to use for DDC
2119 *
2120 * This function reads the first block of the EDID of a panel and (assuming
2121 * that the EDID is valid) extracts the ID out of it. The ID is a 32-bit value
2122 * (16 bits of manufacturer ID and 16 bits of per-manufacturer ID) that's
2123 * supposed to be different for each different modem of panel.
2124 *
2125 * This function is intended to be used during early probing on devices where
2126 * more than one panel might be present. Because of its intended use it must
2127 * assume that the EDID of the panel is correct, at least as far as the ID
2128 * is concerned (in other words, we don't process any overrides here).
2129 *
2130 * NOTE: it's expected that this function and drm_do_get_edid() will both
2131 * be read the EDID, but there is no caching between them. Since we're only
2132 * reading the first block, hopefully this extra overhead won't be too big.
2133 *
2134 * Return: A 32-bit ID that should be different for each make/model of panel.
2135 * See the functions drm_edid_encode_panel_id() and
2136 * drm_edid_decode_panel_id() for some details on the structure of this
2137 * ID.
2138 */
2139
2140u32 drm_edid_get_panel_id(struct i2c_adapter *adapter)
2141{
2142 struct edid *edid;
2143 u32 panel_id;
2144
2145 edid = drm_do_get_edid_base_block(drm_do_probe_ddc_edid, adapter,
2146 NULL, NULL);
2147
2148 /*
2149 * There are no manufacturer IDs of 0, so if there is a problem reading
2150 * the EDID then we'll just return 0.
2151 */
2152 if (IS_ERR_OR_NULL(edid))
2153 return 0;
2154
2155 panel_id = edid_extract_panel_id(edid);
2156 kfree(edid);
2157
2158 return panel_id;
2159}
2160EXPORT_SYMBOL(drm_edid_get_panel_id);
2161
Jani Nikula51f8da52013-09-27 15:08:27 +03002162/**
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01002163 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
2164 * @connector: connector we're probing
2165 * @adapter: I2C adapter to use for DDC
2166 *
2167 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
2168 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
2169 * switch DDC to the GPU which is retrieving EDID.
2170 *
2171 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
2172 */
2173struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2174 struct i2c_adapter *adapter)
2175{
Thomas Zimmermann36b73b02021-01-18 14:14:15 +01002176 struct drm_device *dev = connector->dev;
2177 struct pci_dev *pdev = to_pci_dev(dev->dev);
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01002178 struct edid *edid;
2179
Thomas Zimmermann36b73b02021-01-18 14:14:15 +01002180 if (drm_WARN_ON_ONCE(dev, !dev_is_pci(dev->dev)))
2181 return NULL;
2182
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01002183 vga_switcheroo_lock_ddc(pdev);
2184 edid = drm_get_edid(connector, adapter);
2185 vga_switcheroo_unlock_ddc(pdev);
2186
2187 return edid;
2188}
2189EXPORT_SYMBOL(drm_get_edid_switcheroo);
2190
2191/**
Jani Nikula51f8da52013-09-27 15:08:27 +03002192 * drm_edid_duplicate - duplicate an EDID and the extensions
2193 * @edid: EDID to duplicate
2194 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002195 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03002196 */
2197struct edid *drm_edid_duplicate(const struct edid *edid)
2198{
2199 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
2200}
2201EXPORT_SYMBOL(drm_edid_duplicate);
2202
Adam Jackson61e57a82010-03-29 21:43:18 +00002203/*** EDID parsing ***/
2204
Dave Airlief453ba02008-11-07 14:05:41 -08002205/**
Dave Airlief453ba02008-11-07 14:05:41 -08002206 * edid_get_quirks - return quirk flags for a given EDID
2207 * @edid: EDID to process
2208 *
2209 * This tells subsequent routines what fixes they need to apply.
2210 */
Keith Packard170178f2017-12-13 00:44:26 -08002211static u32 edid_get_quirks(const struct edid *edid)
Dave Airlief453ba02008-11-07 14:05:41 -08002212{
Douglas Andersone8de4d52021-09-14 13:21:51 -07002213 u32 panel_id = edid_extract_panel_id(edid);
Jani Nikula23c4cfb2016-12-28 13:06:26 +02002214 const struct edid_quirk *quirk;
Dave Airlief453ba02008-11-07 14:05:41 -08002215 int i;
2216
2217 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
2218 quirk = &edid_quirk_list[i];
Douglas Andersone8de4d52021-09-14 13:21:51 -07002219 if (quirk->panel_id == panel_id)
Dave Airlief453ba02008-11-07 14:05:41 -08002220 return quirk->quirks;
2221 }
2222
2223 return 0;
2224}
2225
2226#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04002227#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08002228
Dave Airlief453ba02008-11-07 14:05:41 -08002229/**
2230 * edid_fixup_preferred - set preferred modes based on quirk list
2231 * @connector: has mode list to fix up
2232 * @quirks: quirks list
2233 *
2234 * Walk the mode list for @connector, clearing the preferred status
2235 * on existing modes and setting it anew for the right mode ala @quirks.
2236 */
2237static void edid_fixup_preferred(struct drm_connector *connector,
2238 u32 quirks)
2239{
2240 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10002241 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04002242 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08002243
2244 if (list_empty(&connector->probed_modes))
2245 return;
2246
2247 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
2248 target_refresh = 60;
2249 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
2250 target_refresh = 75;
2251
2252 preferred_mode = list_first_entry(&connector->probed_modes,
2253 struct drm_display_mode, head);
2254
2255 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
2256 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
2257
2258 if (cur_mode == preferred_mode)
2259 continue;
2260
2261 /* Largest mode is preferred */
2262 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
2263 preferred_mode = cur_mode;
2264
Ville Syrjälä04256622020-04-28 20:19:27 +03002265 cur_vrefresh = drm_mode_vrefresh(cur_mode);
2266 preferred_vrefresh = drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08002267 /* At a given size, try to get closest to target refresh */
2268 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04002269 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
2270 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08002271 preferred_mode = cur_mode;
2272 }
2273 }
2274
2275 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
2276}
2277
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002278static bool
2279mode_is_rb(const struct drm_display_mode *mode)
2280{
2281 return (mode->htotal - mode->hdisplay == 160) &&
2282 (mode->hsync_end - mode->hdisplay == 80) &&
2283 (mode->hsync_end - mode->hsync_start == 32) &&
2284 (mode->vsync_start - mode->vdisplay == 3);
2285}
2286
Adam Jackson33c75312012-04-13 16:33:29 -04002287/*
2288 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
2289 * @dev: Device to duplicate against
2290 * @hsize: Mode width
2291 * @vsize: Mode height
2292 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002293 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04002294 *
2295 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002296 *
2297 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04002298 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002299struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002300 int hsize, int vsize, int fresh,
2301 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08002302{
Adam Jackson07a5e632009-12-03 17:44:38 -05002303 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08002304
Thierry Redinga6b21832012-11-23 15:01:42 +01002305 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002306 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302307
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002308 if (hsize != ptr->hdisplay)
2309 continue;
2310 if (vsize != ptr->vdisplay)
2311 continue;
2312 if (fresh != drm_mode_vrefresh(ptr))
2313 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002314 if (rb != mode_is_rb(ptr))
2315 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002316
2317 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08002318 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04002319
2320 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002321}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002322EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04002323
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02002324static bool is_display_descriptor(const u8 d[18], u8 tag)
2325{
2326 return d[0] == 0x00 && d[1] == 0x00 &&
2327 d[2] == 0x00 && d[3] == tag;
2328}
2329
Ville Syrjäläf447dd12020-01-24 22:02:26 +02002330static bool is_detailed_timing_descriptor(const u8 d[18])
2331{
2332 return d[0] != 0x00 || d[1] != 0x00;
2333}
2334
Adam Jacksond1ff6402010-03-29 21:43:26 +00002335typedef void detailed_cb(struct detailed_timing *timing, void *closure);
2336
2337static void
Adam Jackson4d76a222010-08-03 14:38:17 -04002338cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
2339{
Ville Syrjälä7304b982020-01-24 22:02:24 +02002340 int i, n;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01002341 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04002342 u8 *det_base = ext + d;
2343
Ville Syrjälä7304b982020-01-24 22:02:24 +02002344 if (d < 4 || d > 127)
2345 return;
2346
Christian Schmidt4966b2a2011-12-19 20:03:43 +01002347 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04002348 for (i = 0; i < n; i++)
2349 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2350}
2351
2352static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002353vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
2354{
2355 unsigned int i, n = min((int)ext[0x02], 6);
2356 u8 *det_base = ext + 5;
2357
2358 if (ext[0x01] != 1)
2359 return; /* unknown version */
2360
2361 for (i = 0; i < n; i++)
2362 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2363}
2364
2365static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00002366drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
2367{
2368 int i;
2369 struct edid *edid = (struct edid *)raw_edid;
2370
2371 if (edid == NULL)
2372 return;
2373
2374 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
2375 cb(&(edid->detailed_timings[i]), closure);
2376
Adam Jackson4d76a222010-08-03 14:38:17 -04002377 for (i = 1; i <= raw_edid[0x7e]; i++) {
2378 u8 *ext = raw_edid + (i * EDID_LENGTH);
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302379
Adam Jackson4d76a222010-08-03 14:38:17 -04002380 switch (*ext) {
2381 case CEA_EXT:
2382 cea_for_each_detailed_block(ext, cb, closure);
2383 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04002384 case VTB_EXT:
2385 vtb_for_each_detailed_block(ext, cb, closure);
2386 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04002387 default:
2388 break;
2389 }
2390 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00002391}
2392
2393static void
2394is_rb(struct detailed_timing *t, void *data)
2395{
2396 u8 *r = (u8 *)t;
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02002397
2398 if (!is_display_descriptor(r, EDID_DETAIL_MONITOR_RANGE))
2399 return;
2400
2401 if (r[15] & 0x10)
2402 *(bool *)data = true;
Adam Jacksond1ff6402010-03-29 21:43:26 +00002403}
2404
2405/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
2406static bool
2407drm_monitor_supports_rb(struct edid *edid)
2408{
2409 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02002410 bool ret = false;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302411
Adam Jacksond1ff6402010-03-29 21:43:26 +00002412 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
2413 return ret;
2414 }
2415
2416 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
2417}
2418
Adam Jackson7a374352010-03-29 21:43:30 +00002419static void
2420find_gtf2(struct detailed_timing *t, void *data)
2421{
2422 u8 *r = (u8 *)t;
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02002423
2424 if (!is_display_descriptor(r, EDID_DETAIL_MONITOR_RANGE))
2425 return;
2426
2427 if (r[10] == 0x02)
Adam Jackson7a374352010-03-29 21:43:30 +00002428 *(u8 **)data = r;
2429}
2430
2431/* Secondary GTF curve kicks in above some break frequency */
2432static int
2433drm_gtf2_hbreak(struct edid *edid)
2434{
2435 u8 *r = NULL;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302436
Adam Jackson7a374352010-03-29 21:43:30 +00002437 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2438 return r ? (r[12] * 2) : 0;
2439}
2440
2441static int
2442drm_gtf2_2c(struct edid *edid)
2443{
2444 u8 *r = NULL;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302445
Adam Jackson7a374352010-03-29 21:43:30 +00002446 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2447 return r ? r[13] : 0;
2448}
2449
2450static int
2451drm_gtf2_m(struct edid *edid)
2452{
2453 u8 *r = NULL;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302454
Adam Jackson7a374352010-03-29 21:43:30 +00002455 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2456 return r ? (r[15] << 8) + r[14] : 0;
2457}
2458
2459static int
2460drm_gtf2_k(struct edid *edid)
2461{
2462 u8 *r = NULL;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302463
Adam Jackson7a374352010-03-29 21:43:30 +00002464 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2465 return r ? r[16] : 0;
2466}
2467
2468static int
2469drm_gtf2_2j(struct edid *edid)
2470{
2471 u8 *r = NULL;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302472
Adam Jackson7a374352010-03-29 21:43:30 +00002473 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2474 return r ? r[17] : 0;
2475}
2476
2477/**
2478 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
2479 * @edid: EDID block to scan
2480 */
2481static int standard_timing_level(struct edid *edid)
2482{
2483 if (edid->revision >= 2) {
2484 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
2485 return LEVEL_CVT;
2486 if (drm_gtf2_hbreak(edid))
2487 return LEVEL_GTF2;
Lee Shawn Cbfef04a2019-10-07 21:51:27 +08002488 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
2489 return LEVEL_GTF;
Adam Jackson7a374352010-03-29 21:43:30 +00002490 }
2491 return LEVEL_DMT;
2492}
2493
Adam Jackson23425ca2009-09-23 17:30:58 -04002494/*
2495 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2496 * monitors fill with ascii space (0x20) instead.
2497 */
2498static int
2499bad_std_timing(u8 a, u8 b)
2500{
2501 return (a == 0x00 && b == 0x00) ||
2502 (a == 0x01 && b == 0x01) ||
2503 (a == 0x20 && b == 0x20);
2504}
2505
Ville Syrjälä58911c22020-04-28 20:19:25 +03002506static int drm_mode_hsync(const struct drm_display_mode *mode)
2507{
2508 if (mode->htotal <= 0)
2509 return 0;
2510
2511 return DIV_ROUND_CLOSEST(mode->clock, mode->htotal);
2512}
2513
Dave Airlief453ba02008-11-07 14:05:41 -08002514/**
2515 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01002516 * @connector: connector of for the EDID block
2517 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08002518 * @t: standard timing params
2519 *
2520 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08002521 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08002522 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002523static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00002524drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002525 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08002526{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002527 struct drm_device *dev = connector->dev;
2528 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08002529 int hsize, vsize;
2530 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002531 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2532 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08002533 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2534 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00002535 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002536
Adam Jackson23425ca2009-09-23 17:30:58 -04002537 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2538 return NULL;
2539
Zhao Yakui5c612592009-06-22 13:17:10 +08002540 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2541 hsize = t->hsize * 8 + 248;
2542 /* vrefresh_rate = vfreq + 60 */
2543 vrefresh_rate = vfreq + 60;
2544 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04002545 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02002546 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04002547 vsize = hsize;
2548 else
2549 vsize = (hsize * 10) / 16;
2550 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08002551 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002552 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08002553 vsize = (hsize * 4) / 5;
2554 else
2555 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00002556
2557 /* HDTV hack, part 1 */
2558 if (vrefresh_rate == 60 &&
2559 ((hsize == 1360 && vsize == 765) ||
2560 (hsize == 1368 && vsize == 769))) {
2561 hsize = 1366;
2562 vsize = 768;
2563 }
2564
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002565 /*
2566 * If this connector already has a mode for this size and refresh
2567 * rate (because it came from detailed or CVT info), use that
2568 * instead. This way we don't have to guess at interlace or
2569 * reduced blanking.
2570 */
Adam Jackson522032d2010-04-09 16:52:49 +00002571 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00002572 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2573 drm_mode_vrefresh(m) == vrefresh_rate)
2574 return NULL;
2575
Adam Jacksona0910c82010-03-29 21:43:28 +00002576 /* HDTV hack, part 2 */
2577 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2578 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10002579 false);
Joe Moriartya5ef6562018-02-12 14:51:43 -05002580 if (!mode)
2581 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08002582 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10002583 mode->hsync_start = mode->hsync_start - 1;
2584 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08002585 return mode;
2586 }
Adam Jacksona0910c82010-03-29 21:43:28 +00002587
Zhao Yakui559ee212009-09-03 09:33:47 +08002588 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002589 if (drm_monitor_supports_rb(edid)) {
2590 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2591 true);
2592 if (mode)
2593 return mode;
2594 }
2595 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08002596 if (mode)
2597 return mode;
2598
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002599 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08002600 switch (timing_level) {
2601 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08002602 break;
2603 case LEVEL_GTF:
2604 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2605 break;
Adam Jackson7a374352010-03-29 21:43:30 +00002606 case LEVEL_GTF2:
2607 /*
2608 * This is potentially wrong if there's ever a monitor with
2609 * more than one ranges section, each claiming a different
2610 * secondary GTF curve. Please don't do that.
2611 */
2612 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002613 if (!mode)
2614 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00002615 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01002616 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00002617 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2618 vrefresh_rate, 0, 0,
2619 drm_gtf2_m(edid),
2620 drm_gtf2_2c(edid),
2621 drm_gtf2_k(edid),
2622 drm_gtf2_2j(edid));
2623 }
2624 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08002625 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10002626 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2627 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08002628 break;
2629 }
Dave Airlief453ba02008-11-07 14:05:41 -08002630 return mode;
2631}
2632
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002633/*
2634 * EDID is delightfully ambiguous about how interlaced modes are to be
2635 * encoded. Our internal representation is of frame height, but some
2636 * HDTV detailed timings are encoded as field height.
2637 *
2638 * The format list here is from CEA, in frame size. Technically we
2639 * should be checking refresh rate too. Whatever.
2640 */
2641static void
2642drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2643 struct detailed_pixel_timing *pt)
2644{
2645 int i;
2646 static const struct {
2647 int w, h;
2648 } cea_interlaced[] = {
2649 { 1920, 1080 },
2650 { 720, 480 },
2651 { 1440, 480 },
2652 { 2880, 480 },
2653 { 720, 576 },
2654 { 1440, 576 },
2655 { 2880, 576 },
2656 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002657
2658 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2659 return;
2660
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04002661 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002662 if ((mode->hdisplay == cea_interlaced[i].w) &&
2663 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2664 mode->vdisplay *= 2;
2665 mode->vsync_start *= 2;
2666 mode->vsync_end *= 2;
2667 mode->vtotal *= 2;
2668 mode->vtotal |= 1;
2669 }
2670 }
2671
2672 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2673}
2674
Dave Airlief453ba02008-11-07 14:05:41 -08002675/**
2676 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2677 * @dev: DRM device (needed to create new mode)
2678 * @edid: EDID block
2679 * @timing: EDID detailed timing info
2680 * @quirks: quirks to apply
2681 *
2682 * An EDID detailed timing block contains enough info for us to create and
2683 * return a new struct drm_display_mode.
2684 */
2685static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2686 struct edid *edid,
2687 struct detailed_timing *timing,
2688 u32 quirks)
2689{
2690 struct drm_display_mode *mode;
2691 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02002692 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2693 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2694 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2695 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02002696 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2697 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 +01002698 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 +02002699 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 -08002700
Adam Jacksonfc438962009-06-04 10:20:34 +10002701 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02002702 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10002703 return NULL;
2704
Michel Dänzer0454bea2009-06-15 16:56:07 +02002705 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002706 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002707 return NULL;
2708 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02002709 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02002710 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08002711 }
2712
Zhao Yakuifcb45612009-10-14 09:11:25 +08002713 /* it is incorrect if hsync/vsync width is zero */
2714 if (!hsync_pulse_width || !vsync_pulse_width) {
2715 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2716 "Wrong Hsync/Vsync pulse width\n");
2717 return NULL;
2718 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002719
2720 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2721 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2722 if (!mode)
2723 return NULL;
2724
2725 goto set_size;
2726 }
2727
Dave Airlief453ba02008-11-07 14:05:41 -08002728 mode = drm_mode_create(dev);
2729 if (!mode)
2730 return NULL;
2731
Dave Airlief453ba02008-11-07 14:05:41 -08002732 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02002733 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08002734
Michel Dänzer0454bea2009-06-15 16:56:07 +02002735 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08002736
Michel Dänzer0454bea2009-06-15 16:56:07 +02002737 mode->hdisplay = hactive;
2738 mode->hsync_start = mode->hdisplay + hsync_offset;
2739 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2740 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002741
Michel Dänzer0454bea2009-06-15 16:56:07 +02002742 mode->vdisplay = vactive;
2743 mode->vsync_start = mode->vdisplay + vsync_offset;
2744 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2745 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08002746
Jesse Barnes7064fef2009-11-05 10:12:54 -08002747 /* Some EDIDs have bogus h/vtotal values */
2748 if (mode->hsync_end > mode->htotal)
2749 mode->htotal = mode->hsync_end + 1;
2750 if (mode->vsync_end > mode->vtotal)
2751 mode->vtotal = mode->vsync_end + 1;
2752
Adam Jacksonb58db2c2010-02-15 22:15:39 +00002753 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08002754
2755 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02002756 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08002757 }
2758
Michel Dänzer0454bea2009-06-15 16:56:07 +02002759 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2760 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2761 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2762 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08002763
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002764set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02002765 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2766 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08002767
2768 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2769 mode->width_mm *= 10;
2770 mode->height_mm *= 10;
2771 }
2772
2773 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2774 mode->width_mm = edid->width_cm * 10;
2775 mode->height_mm = edid->height_cm * 10;
2776 }
2777
Adam Jacksonbc42aab2012-05-23 16:26:54 -04002778 mode->type = DRM_MODE_TYPE_DRIVER;
2779 drm_mode_set_name(mode);
2780
Dave Airlief453ba02008-11-07 14:05:41 -08002781 return mode;
2782}
2783
Adam Jackson07a5e632009-12-03 17:44:38 -05002784static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002785mode_in_hsync_range(const struct drm_display_mode *mode,
2786 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002787{
2788 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05002789
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002790 hmin = t[7];
2791 if (edid->revision >= 4)
2792 hmin += ((t[4] & 0x04) ? 255 : 0);
2793 hmax = t[8];
2794 if (edid->revision >= 4)
2795 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05002796 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05002797
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002798 return (hsync <= hmax && hsync >= hmin);
2799}
2800
2801static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002802mode_in_vsync_range(const struct drm_display_mode *mode,
2803 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002804{
2805 int vsync, vmin, vmax;
2806
2807 vmin = t[5];
2808 if (edid->revision >= 4)
2809 vmin += ((t[4] & 0x01) ? 255 : 0);
2810 vmax = t[6];
2811 if (edid->revision >= 4)
2812 vmax += ((t[4] & 0x02) ? 255 : 0);
2813 vsync = drm_mode_vrefresh(mode);
2814
2815 return (vsync <= vmax && vsync >= vmin);
2816}
2817
2818static u32
2819range_pixel_clock(struct edid *edid, u8 *t)
2820{
2821 /* unspecified */
2822 if (t[9] == 0 || t[9] == 255)
2823 return 0;
2824
2825 /* 1.4 with CVT support gives us real precision, yay */
2826 if (edid->revision >= 4 && t[10] == 0x04)
2827 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2828
2829 /* 1.3 is pathetic, so fuzz up a bit */
2830 return t[9] * 10000 + 5001;
2831}
2832
Adam Jackson07a5e632009-12-03 17:44:38 -05002833static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00002834mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002835 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002836{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002837 u32 max_clock;
2838 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05002839
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002840 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002841 return false;
2842
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002843 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05002844 return false;
2845
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002846 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05002847 if (mode->clock > max_clock)
2848 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002849
2850 /* 1.4 max horizontal check */
2851 if (edid->revision >= 4 && t[10] == 0x04)
2852 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2853 return false;
2854
2855 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2856 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05002857
2858 return true;
2859}
2860
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002861static bool valid_inferred_mode(const struct drm_connector *connector,
2862 const struct drm_display_mode *mode)
2863{
Ville Syrjälä85f8fcd2015-09-07 18:22:56 +03002864 const struct drm_display_mode *m;
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002865 bool ok = false;
2866
2867 list_for_each_entry(m, &connector->probed_modes, head) {
2868 if (mode->hdisplay == m->hdisplay &&
2869 mode->vdisplay == m->vdisplay &&
2870 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2871 return false; /* duplicated */
2872 if (mode->hdisplay <= m->hdisplay &&
2873 mode->vdisplay <= m->vdisplay)
2874 ok = true;
2875 }
2876 return ok;
2877}
2878
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002879static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04002880drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00002881 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05002882{
2883 int i, modes = 0;
2884 struct drm_display_mode *newmode;
2885 struct drm_device *dev = connector->dev;
2886
Thierry Redinga6b21832012-11-23 15:01:42 +01002887 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002888 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2889 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05002890 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2891 if (newmode) {
2892 drm_mode_probed_add(connector, newmode);
2893 modes++;
2894 }
2895 }
2896 }
2897
2898 return modes;
2899}
2900
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002901/* fix up 1366x768 mode from 1368x768;
2902 * GFT/CVT can't express 1366 width which isn't dividable by 8
2903 */
Takashi Iwai969218f2017-01-17 17:43:29 +01002904void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002905{
2906 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2907 mode->hdisplay = 1366;
2908 mode->hsync_start--;
2909 mode->hsync_end--;
2910 drm_mode_set_name(mode);
2911 }
2912}
2913
Adam Jacksonb309bd32012-04-13 16:33:40 -04002914static int
2915drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2916 struct detailed_timing *timing)
2917{
2918 int i, modes = 0;
2919 struct drm_display_mode *newmode;
2920 struct drm_device *dev = connector->dev;
2921
Thierry Redinga6b21832012-11-23 15:01:42 +01002922 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002923 const struct minimode *m = &extra_modes[i];
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302924
Adam Jacksonb309bd32012-04-13 16:33:40 -04002925 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002926 if (!newmode)
2927 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002928
Takashi Iwai969218f2017-01-17 17:43:29 +01002929 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002930 if (!mode_in_range(newmode, edid, timing) ||
2931 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002932 drm_mode_destroy(dev, newmode);
2933 continue;
2934 }
2935
2936 drm_mode_probed_add(connector, newmode);
2937 modes++;
2938 }
2939
2940 return modes;
2941}
2942
2943static int
2944drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2945 struct detailed_timing *timing)
2946{
2947 int i, modes = 0;
2948 struct drm_display_mode *newmode;
2949 struct drm_device *dev = connector->dev;
2950 bool rb = drm_monitor_supports_rb(edid);
2951
Thierry Redinga6b21832012-11-23 15:01:42 +01002952 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002953 const struct minimode *m = &extra_modes[i];
Suraj Upadhyay948de8422020-07-02 18:53:32 +05302954
Adam Jacksonb309bd32012-04-13 16:33:40 -04002955 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002956 if (!newmode)
2957 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002958
Takashi Iwai969218f2017-01-17 17:43:29 +01002959 drm_mode_fixup_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002960 if (!mode_in_range(newmode, edid, timing) ||
2961 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002962 drm_mode_destroy(dev, newmode);
2963 continue;
2964 }
2965
2966 drm_mode_probed_add(connector, newmode);
2967 modes++;
2968 }
2969
2970 return modes;
2971}
2972
Adam Jackson13931572010-08-03 14:38:19 -04002973static void
2974do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002975{
Adam Jackson13931572010-08-03 14:38:19 -04002976 struct detailed_mode_closure *closure = c;
2977 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002978 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002979
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02002980 if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_MONITOR_RANGE))
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002981 return;
2982
2983 closure->modes += drm_dmt_modes_for_range(closure->connector,
2984 closure->edid,
2985 timing);
Ville Syrjälä4d23f482020-01-24 22:02:27 +02002986
Adam Jacksonb309bd32012-04-13 16:33:40 -04002987 if (!version_greater(closure->edid, 1, 1))
2988 return; /* GTF not defined yet */
2989
2990 switch (range->flags) {
2991 case 0x02: /* secondary gtf, XXX could do more */
2992 case 0x00: /* default gtf */
2993 closure->modes += drm_gtf_modes_for_range(closure->connector,
2994 closure->edid,
2995 timing);
2996 break;
2997 case 0x04: /* cvt, only in 1.4+ */
2998 if (!version_greater(closure->edid, 1, 3))
2999 break;
3000
3001 closure->modes += drm_cvt_modes_for_range(closure->connector,
3002 closure->edid,
3003 timing);
3004 break;
3005 case 0x01: /* just the ranges, no formula */
3006 default:
3007 break;
3008 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05003009}
3010
Adam Jackson13931572010-08-03 14:38:19 -04003011static int
3012add_inferred_modes(struct drm_connector *connector, struct edid *edid)
3013{
3014 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02003015 .connector = connector,
3016 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04003017 };
3018
3019 if (version_greater(edid, 1, 0))
3020 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
3021 &closure);
3022
3023 return closure.modes;
3024}
3025
Adam Jackson2255be12010-03-29 21:43:22 +00003026static int
3027drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
3028{
3029 int i, j, m, modes = 0;
3030 struct drm_display_mode *mode;
Paul Parsonsf3a32d72016-03-26 13:18:38 +00003031 u8 *est = ((u8 *)timing) + 6;
Adam Jackson2255be12010-03-29 21:43:22 +00003032
3033 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03003034 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00003035 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07003036 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00003037 break;
3038 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00003039 mode = drm_mode_find_dmt(connector->dev,
3040 est3_modes[m].w,
3041 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04003042 est3_modes[m].r,
3043 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00003044 if (mode) {
3045 drm_mode_probed_add(connector, mode);
3046 modes++;
3047 }
3048 }
3049 }
3050 }
3051
3052 return modes;
3053}
3054
Adam Jackson13931572010-08-03 14:38:19 -04003055static void
3056do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05003057{
Adam Jackson13931572010-08-03 14:38:19 -04003058 struct detailed_mode_closure *closure = c;
Adam Jackson13931572010-08-03 14:38:19 -04003059
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02003060 if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_EST_TIMINGS))
3061 return;
3062
3063 closure->modes += drm_est3_modes(closure->connector, timing);
Adam Jackson13931572010-08-03 14:38:19 -04003064}
3065
3066/**
3067 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003068 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04003069 * @edid: EDID block to scan
3070 *
3071 * Each EDID block contains a bitmap of the supported "established modes" list
3072 * (defined above). Tease them out and add them to the global modes list.
3073 */
3074static int
3075add_established_modes(struct drm_connector *connector, struct edid *edid)
3076{
Adam Jackson9cf00972009-12-03 17:44:36 -05003077 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04003078 unsigned long est_bits = edid->established_timings.t1 |
3079 (edid->established_timings.t2 << 8) |
3080 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
3081 int i, modes = 0;
3082 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02003083 .connector = connector,
3084 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04003085 };
Adam Jackson9cf00972009-12-03 17:44:36 -05003086
Adam Jackson13931572010-08-03 14:38:19 -04003087 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
3088 if (est_bits & (1<<i)) {
3089 struct drm_display_mode *newmode;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05303090
Adam Jackson13931572010-08-03 14:38:19 -04003091 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
3092 if (newmode) {
3093 drm_mode_probed_add(connector, newmode);
3094 modes++;
3095 }
3096 }
Adam Jackson9cf00972009-12-03 17:44:36 -05003097 }
3098
Adam Jackson13931572010-08-03 14:38:19 -04003099 if (version_greater(edid, 1, 0))
3100 drm_for_each_detailed_block((u8 *)edid,
3101 do_established_modes, &closure);
3102
3103 return modes + closure.modes;
3104}
3105
3106static void
3107do_standard_modes(struct detailed_timing *timing, void *c)
3108{
3109 struct detailed_mode_closure *closure = c;
3110 struct detailed_non_pixel *data = &timing->data.other_data;
3111 struct drm_connector *connector = closure->connector;
3112 struct edid *edid = closure->edid;
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02003113 int i;
Adam Jackson13931572010-08-03 14:38:19 -04003114
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02003115 if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_STD_MODES))
3116 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05003117
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02003118 for (i = 0; i < 6; i++) {
3119 struct std_timing *std = &data->data.timings[i];
3120 struct drm_display_mode *newmode;
3121
3122 newmode = drm_mode_std(connector, edid, std);
3123 if (newmode) {
3124 drm_mode_probed_add(connector, newmode);
3125 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05003126 }
Adam Jackson13931572010-08-03 14:38:19 -04003127 }
3128}
3129
3130/**
3131 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003132 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04003133 * @edid: EDID block to scan
3134 *
3135 * Standard modes can be calculated using the appropriate standard (DMT,
3136 * GTF or CVT. Grab them from @edid and add them to the list.
3137 */
3138static int
3139add_standard_modes(struct drm_connector *connector, struct edid *edid)
3140{
3141 int i, modes = 0;
3142 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02003143 .connector = connector,
3144 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04003145 };
3146
3147 for (i = 0; i < EDID_STD_TIMINGS; i++) {
3148 struct drm_display_mode *newmode;
3149
3150 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02003151 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04003152 if (newmode) {
3153 drm_mode_probed_add(connector, newmode);
3154 modes++;
3155 }
3156 }
3157
3158 if (version_greater(edid, 1, 0))
3159 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
3160 &closure);
3161
3162 /* XXX should also look for standard codes in VTB blocks */
3163
3164 return modes + closure.modes;
3165}
3166
Dave Airlief453ba02008-11-07 14:05:41 -08003167static int drm_cvt_modes(struct drm_connector *connector,
3168 struct detailed_timing *timing)
3169{
3170 int i, j, modes = 0;
3171 struct drm_display_mode *newmode;
3172 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08003173 struct cvt_timing *cvt;
3174 const int rates[] = { 60, 85, 75, 60, 50 };
3175 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08003176
3177 for (i = 0; i < 4; i++) {
Kees Cook3f649ab2020-06-03 13:09:38 -07003178 int width, height;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05303179
Dave Airlief453ba02008-11-07 14:05:41 -08003180 cvt = &(timing->data.other_data.data.cvt[i]);
3181
3182 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02003183 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08003184
3185 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08003186 switch (cvt->code[1] & 0x0c) {
Linus Torvaldsd652d5f2020-12-17 09:27:57 -08003187 /* default - because compiler doesn't see that we've enumerated all cases */
3188 default:
Adam Jacksonf066a172009-09-23 17:31:21 -04003189 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08003190 width = height * 4 / 3;
3191 break;
3192 case 0x04:
3193 width = height * 16 / 9;
3194 break;
3195 case 0x08:
3196 width = height * 16 / 10;
3197 break;
3198 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08003199 width = height * 15 / 9;
3200 break;
3201 }
3202
3203 for (j = 1; j < 5; j++) {
3204 if (cvt->code[2] & (1 << j)) {
3205 newmode = drm_cvt_mode(dev, width, height,
3206 rates[j], j == 0,
3207 false, false);
3208 if (newmode) {
3209 drm_mode_probed_add(connector, newmode);
3210 modes++;
3211 }
3212 }
3213 }
3214 }
3215
3216 return modes;
3217}
3218
Adam Jackson13931572010-08-03 14:38:19 -04003219static void
3220do_cvt_mode(struct detailed_timing *timing, void *c)
3221{
3222 struct detailed_mode_closure *closure = c;
Adam Jackson13931572010-08-03 14:38:19 -04003223
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02003224 if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_CVT_3BYTE))
3225 return;
3226
3227 closure->modes += drm_cvt_modes(closure->connector, timing);
Adam Jackson13931572010-08-03 14:38:19 -04003228}
Adam Jackson9cf00972009-12-03 17:44:36 -05003229
3230static int
Adam Jackson13931572010-08-03 14:38:19 -04003231add_cvt_modes(struct drm_connector *connector, struct edid *edid)
Ville Syrjälä4d23f482020-01-24 22:02:27 +02003232{
Adam Jackson13931572010-08-03 14:38:19 -04003233 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02003234 .connector = connector,
3235 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04003236 };
Adam Jackson9cf00972009-12-03 17:44:36 -05003237
Adam Jackson13931572010-08-03 14:38:19 -04003238 if (version_greater(edid, 1, 2))
3239 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08003240
Adam Jackson13931572010-08-03 14:38:19 -04003241 /* XXX should also look for CVT codes in VTB blocks */
3242
3243 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08003244}
3245
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003246static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
3247
Adam Jackson13931572010-08-03 14:38:19 -04003248static void
3249do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08003250{
Adam Jackson13931572010-08-03 14:38:19 -04003251 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08003252 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05003253
Ville Syrjäläf447dd12020-01-24 22:02:26 +02003254 if (!is_detailed_timing_descriptor((const u8 *)timing))
3255 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05003256
Ville Syrjäläf447dd12020-01-24 22:02:26 +02003257 newmode = drm_mode_detailed(closure->connector->dev,
3258 closure->edid, timing,
3259 closure->quirks);
3260 if (!newmode)
3261 return;
Dave Airlief453ba02008-11-07 14:05:41 -08003262
Ville Syrjäläf447dd12020-01-24 22:02:26 +02003263 if (closure->preferred)
3264 newmode->type |= DRM_MODE_TYPE_PREFERRED;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03003265
Ville Syrjäläf447dd12020-01-24 22:02:26 +02003266 /*
3267 * Detailed modes are limited to 10kHz pixel clock resolution,
3268 * so fix up anything that looks like CEA/HDMI mode, but the clock
3269 * is just slightly off.
3270 */
3271 fixup_detailed_cea_mode_clock(newmode);
3272
3273 drm_mode_probed_add(closure->connector, newmode);
3274 closure->modes++;
3275 closure->preferred = false;
Ma Ling167f3a02009-03-20 14:09:48 +08003276}
3277
Adam Jackson13931572010-08-03 14:38:19 -04003278/*
3279 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08003280 * @connector: attached connector
3281 * @edid: EDID block to scan
3282 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08003283 */
Adam Jackson13931572010-08-03 14:38:19 -04003284static int
3285add_detailed_modes(struct drm_connector *connector, struct edid *edid,
3286 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08003287{
Adam Jackson13931572010-08-03 14:38:19 -04003288 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02003289 .connector = connector,
3290 .edid = edid,
Gustavo A. R. Silvac2925bd2018-01-30 04:05:28 -06003291 .preferred = true,
Julia Lawalld456ea22014-08-23 18:09:56 +02003292 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04003293 };
Dave Airlief453ba02008-11-07 14:05:41 -08003294
Adam Jackson13931572010-08-03 14:38:19 -04003295 if (closure.preferred && !version_greater(edid, 1, 3))
3296 closure.preferred =
3297 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00003298
Adam Jackson13931572010-08-03 14:38:19 -04003299 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08003300
Adam Jackson13931572010-08-03 14:38:19 -04003301 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08003302}
Dave Airlief453ba02008-11-07 14:05:41 -08003303
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003304#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003305#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08003306#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08003307#define SPEAKER_BLOCK 0x04
Uma Shankare85959d2019-05-16 19:40:08 +05303308#define HDR_STATIC_METADATA_BLOCK 0x6
Shashank Sharma87563fc2017-07-13 21:03:10 +05303309#define USE_EXTENDED_TAG 0x07
3310#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
Shashank Sharma832d4f22017-07-14 16:03:46 +05303311#define EXT_VIDEO_DATA_BLOCK_420 0x0E
3312#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003313#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003314#define EDID_CEA_YCRCB444 (1 << 5)
3315#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003316#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003317
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01003318/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003319 * Search EDID for CEA extension block.
3320 */
Jani Nikula4cc4f092021-03-29 16:37:16 +03003321const u8 *drm_find_edid_extension(const struct edid *edid,
3322 int ext_id, int *ext_index)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003323{
Jani Nikula43d16d82021-03-29 16:37:15 +03003324 const u8 *edid_ext = NULL;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003325 int i;
3326
3327 /* No EDID or EDID extensions */
3328 if (edid == NULL || edid->extensions == 0)
3329 return NULL;
3330
3331 /* Find CEA extension */
Ville Syrjälä8873cfa2020-05-27 16:03:08 +03003332 for (i = *ext_index; i < edid->extensions; i++) {
Jani Nikula43d16d82021-03-29 16:37:15 +03003333 edid_ext = (const u8 *)edid + EDID_LENGTH * (i + 1);
Dave Airlie40d9b042014-10-20 16:29:33 +10003334 if (edid_ext[0] == ext_id)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003335 break;
3336 }
3337
Ville Syrjälä8873cfa2020-05-27 16:03:08 +03003338 if (i >= edid->extensions)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003339 return NULL;
3340
Ville Syrjälä8873cfa2020-05-27 16:03:08 +03003341 *ext_index = i + 1;
3342
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003343 return edid_ext;
3344}
3345
Jani Nikula43d16d82021-03-29 16:37:15 +03003346static const u8 *drm_find_cea_extension(const struct edid *edid)
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003347{
Jani Nikula43d16d82021-03-29 16:37:15 +03003348 const struct displayid_block *block;
Jani Nikula1ba63ca2021-03-29 16:37:19 +03003349 struct displayid_iter iter;
Jani Nikula43d16d82021-03-29 16:37:15 +03003350 const u8 *cea;
Jani Nikula1ba63ca2021-03-29 16:37:19 +03003351 int ext_index = 0;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003352
3353 /* Look for a top level CEA extension block */
Ville Syrjälä7f261af2020-05-27 16:03:09 +03003354 /* FIXME: make callers iterate through multiple CEA ext blocks? */
Ville Syrjälä8873cfa2020-05-27 16:03:08 +03003355 cea = drm_find_edid_extension(edid, CEA_EXT, &ext_index);
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003356 if (cea)
3357 return cea;
3358
3359 /* CEA blocks can also be found embedded in a DisplayID block */
Jani Nikula1ba63ca2021-03-29 16:37:19 +03003360 displayid_iter_edid_begin(edid, &iter);
3361 displayid_iter_for_each(block, &iter) {
3362 if (block->tag == DATA_BLOCK_CTA) {
3363 cea = (const u8 *)block;
3364 break;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003365 }
3366 }
Jani Nikula1ba63ca2021-03-29 16:37:19 +03003367 displayid_iter_end(&iter);
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003368
Jani Nikula1ba63ca2021-03-29 16:37:19 +03003369 return cea;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04003370}
3371
Mauro Rossie1cf35b2020-02-03 22:31:13 +01003372static __always_inline const struct drm_display_mode *cea_mode_for_vic(u8 vic)
Ville Syrjälä7befe622019-12-13 19:43:45 +02003373{
Ville Syrjälä9212f8e2019-12-13 19:43:48 +02003374 BUILD_BUG_ON(1 + ARRAY_SIZE(edid_cea_modes_1) - 1 != 127);
3375 BUILD_BUG_ON(193 + ARRAY_SIZE(edid_cea_modes_193) - 1 != 219);
3376
Ville Syrjälä8c1b2bd2019-12-13 19:43:47 +02003377 if (vic >= 1 && vic < 1 + ARRAY_SIZE(edid_cea_modes_1))
3378 return &edid_cea_modes_1[vic - 1];
Ville Syrjäläf7655d42019-12-13 19:43:46 +02003379 if (vic >= 193 && vic < 193 + ARRAY_SIZE(edid_cea_modes_193))
3380 return &edid_cea_modes_193[vic - 193];
Ville Syrjälä7befe622019-12-13 19:43:45 +02003381 return NULL;
3382}
3383
3384static u8 cea_num_vics(void)
3385{
Ville Syrjäläf7655d42019-12-13 19:43:46 +02003386 return 193 + ARRAY_SIZE(edid_cea_modes_193);
Ville Syrjälä7befe622019-12-13 19:43:45 +02003387}
3388
3389static u8 cea_next_vic(u8 vic)
3390{
Ville Syrjälä8c1b2bd2019-12-13 19:43:47 +02003391 if (++vic == 1 + ARRAY_SIZE(edid_cea_modes_1))
Ville Syrjäläf7655d42019-12-13 19:43:46 +02003392 vic = 193;
3393 return vic;
Ville Syrjälä7befe622019-12-13 19:43:45 +02003394}
3395
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003396/*
3397 * Calculate the alternate clock for the CEA mode
3398 * (60Hz vs. 59.94Hz etc.)
3399 */
3400static unsigned int
3401cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
3402{
3403 unsigned int clock = cea_mode->clock;
3404
Ville Syrjälä04256622020-04-28 20:19:27 +03003405 if (drm_mode_vrefresh(cea_mode) % 6 != 0)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003406 return clock;
3407
3408 /*
3409 * edid_cea_modes contains the 59.94Hz
3410 * variant for 240 and 480 line modes,
3411 * and the 60Hz variant otherwise.
3412 */
3413 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
Ville Syrjälä9afd8082015-10-08 11:43:33 +03003414 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003415 else
Ville Syrjälä9afd8082015-10-08 11:43:33 +03003416 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003417
3418 return clock;
3419}
3420
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003421static bool
3422cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
3423{
3424 /*
3425 * For certain VICs the spec allows the vertical
3426 * front porch to vary by one or two lines.
3427 *
3428 * cea_modes[] stores the variant with the shortest
3429 * vertical front porch. We can adjust the mode to
3430 * get the other variants by simply increasing the
3431 * vertical front porch length.
3432 */
Ville Syrjälä7befe622019-12-13 19:43:45 +02003433 BUILD_BUG_ON(cea_mode_for_vic(8)->vtotal != 262 ||
3434 cea_mode_for_vic(9)->vtotal != 262 ||
3435 cea_mode_for_vic(12)->vtotal != 262 ||
3436 cea_mode_for_vic(13)->vtotal != 262 ||
3437 cea_mode_for_vic(23)->vtotal != 312 ||
3438 cea_mode_for_vic(24)->vtotal != 312 ||
3439 cea_mode_for_vic(27)->vtotal != 312 ||
3440 cea_mode_for_vic(28)->vtotal != 312);
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003441
3442 if (((vic == 8 || vic == 9 ||
3443 vic == 12 || vic == 13) && mode->vtotal < 263) ||
3444 ((vic == 23 || vic == 24 ||
3445 vic == 27 || vic == 28) && mode->vtotal < 314)) {
3446 mode->vsync_start++;
3447 mode->vsync_end++;
3448 mode->vtotal++;
3449
3450 return true;
3451 }
3452
3453 return false;
3454}
3455
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003456static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
3457 unsigned int clock_tolerance)
3458{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303459 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003460 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003461
3462 if (!to_match->clock)
3463 return 0;
3464
Ville Syrjälä357768c2018-05-08 16:39:38 +05303465 if (to_match->picture_aspect_ratio)
3466 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3467
Ville Syrjälä7befe622019-12-13 19:43:45 +02003468 for (vic = 1; vic < cea_num_vics(); vic = cea_next_vic(vic)) {
3469 struct drm_display_mode cea_mode = *cea_mode_for_vic(vic);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003470 unsigned int clock1, clock2;
3471
3472 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003473 clock1 = cea_mode.clock;
3474 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003475
3476 if (abs(to_match->clock - clock1) > clock_tolerance &&
3477 abs(to_match->clock - clock2) > clock_tolerance)
3478 continue;
3479
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003480 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303481 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003482 return vic;
3483 } while (cea_mode_alternate_timings(vic, &cea_mode));
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003484 }
3485
3486 return 0;
3487}
3488
Thierry Reding18316c82012-12-20 15:41:44 +01003489/**
3490 * drm_match_cea_mode - look for a CEA mode matching given mode
3491 * @to_match: display mode
3492 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003493 * 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 +01003494 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00003495 */
Thierry Reding18316c82012-12-20 15:41:44 +01003496u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00003497{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303498 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003499 u8 vic;
Stephane Marchesina4799032012-11-09 16:21:05 +00003500
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003501 if (!to_match->clock)
3502 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00003503
Ville Syrjälä357768c2018-05-08 16:39:38 +05303504 if (to_match->picture_aspect_ratio)
3505 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3506
Ville Syrjälä7befe622019-12-13 19:43:45 +02003507 for (vic = 1; vic < cea_num_vics(); vic = cea_next_vic(vic)) {
3508 struct drm_display_mode cea_mode = *cea_mode_for_vic(vic);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003509 unsigned int clock1, clock2;
3510
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003511 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003512 clock1 = cea_mode.clock;
3513 clock2 = cea_mode_alternate_clock(&cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03003514
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003515 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
3516 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
3517 continue;
3518
3519 do {
Ville Syrjälä357768c2018-05-08 16:39:38 +05303520 if (drm_mode_match(to_match, &cea_mode, match_flags))
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003521 return vic;
3522 } while (cea_mode_alternate_timings(vic, &cea_mode));
Stephane Marchesina4799032012-11-09 16:21:05 +00003523 }
Ville Syrjäläc45a4e42016-11-03 14:53:29 +02003524
Stephane Marchesina4799032012-11-09 16:21:05 +00003525 return 0;
3526}
3527EXPORT_SYMBOL(drm_match_cea_mode);
3528
Jani Nikulad9278b42016-01-08 13:21:51 +02003529static bool drm_valid_cea_vic(u8 vic)
3530{
Ville Syrjälä7befe622019-12-13 19:43:45 +02003531 return cea_mode_for_vic(vic) != NULL;
Jani Nikulad9278b42016-01-08 13:21:51 +02003532}
3533
Ville Syrjälä28c03a442019-10-04 17:19:11 +03003534static enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303535{
Ville Syrjälä7befe622019-12-13 19:43:45 +02003536 const struct drm_display_mode *mode = cea_mode_for_vic(video_code);
3537
3538 if (mode)
3539 return mode->picture_aspect_ratio;
3540
3541 return HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303542}
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303543
Wayne Lind2b43472019-11-18 18:18:31 +08003544static enum hdmi_picture_aspect drm_get_hdmi_aspect_ratio(const u8 video_code)
3545{
3546 return edid_4k_modes[video_code].picture_aspect_ratio;
3547}
3548
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003549/*
3550 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
3551 * specific block).
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003552 */
3553static unsigned int
3554hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3555{
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003556 return cea_mode_alternate_clock(hdmi_mode);
3557}
3558
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003559static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3560 unsigned int clock_tolerance)
3561{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303562 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003563 u8 vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003564
3565 if (!to_match->clock)
3566 return 0;
3567
Wayne Lind2b43472019-11-18 18:18:31 +08003568 if (to_match->picture_aspect_ratio)
3569 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3570
Jani Nikulad9278b42016-01-08 13:21:51 +02003571 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3572 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003573 unsigned int clock1, clock2;
3574
3575 /* Make sure to also match alternate clocks */
3576 clock1 = hdmi_mode->clock;
3577 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3578
3579 if (abs(to_match->clock - clock1) > clock_tolerance &&
3580 abs(to_match->clock - clock2) > clock_tolerance)
3581 continue;
3582
Ville Syrjälä357768c2018-05-08 16:39:38 +05303583 if (drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003584 return vic;
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02003585 }
3586
3587 return 0;
3588}
3589
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003590/*
3591 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3592 * @to_match: display mode
3593 *
3594 * An HDMI mode is one defined in the HDMI vendor specific block.
3595 *
3596 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3597 */
3598static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3599{
Ville Syrjälä357768c2018-05-08 16:39:38 +05303600 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
Jani Nikulad9278b42016-01-08 13:21:51 +02003601 u8 vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003602
3603 if (!to_match->clock)
3604 return 0;
3605
Wayne Lind2b43472019-11-18 18:18:31 +08003606 if (to_match->picture_aspect_ratio)
3607 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3608
Jani Nikulad9278b42016-01-08 13:21:51 +02003609 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3610 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003611 unsigned int clock1, clock2;
3612
3613 /* Make sure to also match alternate clocks */
3614 clock1 = hdmi_mode->clock;
3615 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3616
3617 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3618 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Ville Syrjälä357768c2018-05-08 16:39:38 +05303619 drm_mode_match(to_match, hdmi_mode, match_flags))
Jani Nikulad9278b42016-01-08 13:21:51 +02003620 return vic;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003621 }
3622 return 0;
3623}
3624
Jani Nikulad9278b42016-01-08 13:21:51 +02003625static bool drm_valid_hdmi_vic(u8 vic)
3626{
3627 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3628}
3629
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003630static int
3631add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3632{
3633 struct drm_device *dev = connector->dev;
3634 struct drm_display_mode *mode, *tmp;
3635 LIST_HEAD(list);
3636 int modes = 0;
3637
3638 /* Don't add CEA modes if the CEA extension block is missing */
3639 if (!drm_find_cea_extension(edid))
3640 return 0;
3641
3642 /*
3643 * Go through all probed modes and create a new mode
3644 * with the alternate clock for certain CEA modes.
3645 */
3646 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003647 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003648 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003649 u8 vic = drm_match_cea_mode(mode);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003650 unsigned int clock1, clock2;
3651
Jani Nikulad9278b42016-01-08 13:21:51 +02003652 if (drm_valid_cea_vic(vic)) {
Ville Syrjälä7befe622019-12-13 19:43:45 +02003653 cea_mode = cea_mode_for_vic(vic);
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003654 clock2 = cea_mode_alternate_clock(cea_mode);
3655 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02003656 vic = drm_match_hdmi_mode(mode);
3657 if (drm_valid_hdmi_vic(vic)) {
3658 cea_mode = &edid_4k_modes[vic];
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01003659 clock2 = hdmi_mode_alternate_clock(cea_mode);
3660 }
3661 }
3662
3663 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003664 continue;
3665
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003666 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003667
3668 if (clock1 == clock2)
3669 continue;
3670
3671 if (mode->clock != clock1 && mode->clock != clock2)
3672 continue;
3673
3674 newmode = drm_mode_duplicate(dev, cea_mode);
3675 if (!newmode)
3676 continue;
3677
Damien Lespiau27130212013-09-25 16:45:28 +01003678 /* Carry over the stereo flags */
3679 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3680
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003681 /*
3682 * The current mode could be either variant. Make
3683 * sure to pick the "other" clock for the new mode.
3684 */
3685 if (mode->clock != clock1)
3686 newmode->clock = clock1;
3687 else
3688 newmode->clock = clock2;
3689
3690 list_add_tail(&newmode->head, &list);
3691 }
3692
3693 list_for_each_entry_safe(mode, tmp, &list, head) {
3694 list_del(&mode->head);
3695 drm_mode_probed_add(connector, mode);
3696 modes++;
3697 }
3698
3699 return modes;
3700}
Stephane Marchesina4799032012-11-09 16:21:05 +00003701
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303702static u8 svd_to_vic(u8 svd)
3703{
3704 /* 0-6 bit vic, 7th bit native mode indicator */
3705 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3706 return svd & 127;
3707
3708 return svd;
3709}
3710
Thomas Woodaff04ac2013-11-29 15:33:27 +00003711static struct drm_display_mode *
3712drm_display_mode_from_vic_index(struct drm_connector *connector,
3713 const u8 *video_db, u8 video_len,
3714 u8 video_index)
3715{
3716 struct drm_device *dev = connector->dev;
3717 struct drm_display_mode *newmode;
Jani Nikulad9278b42016-01-08 13:21:51 +02003718 u8 vic;
Thomas Woodaff04ac2013-11-29 15:33:27 +00003719
3720 if (video_db == NULL || video_index >= video_len)
3721 return NULL;
3722
3723 /* CEA modes are numbered 1..127 */
Shashank Sharma8ec6e072017-07-13 21:03:08 +05303724 vic = svd_to_vic(video_db[video_index]);
Jani Nikulad9278b42016-01-08 13:21:51 +02003725 if (!drm_valid_cea_vic(vic))
Thomas Woodaff04ac2013-11-29 15:33:27 +00003726 return NULL;
3727
Ville Syrjälä7befe622019-12-13 19:43:45 +02003728 newmode = drm_mode_duplicate(dev, cea_mode_for_vic(vic));
Damien Lespiau409bbf12014-03-03 23:59:07 +00003729 if (!newmode)
3730 return NULL;
3731
Thomas Woodaff04ac2013-11-29 15:33:27 +00003732 return newmode;
3733}
3734
Shashank Sharma832d4f22017-07-14 16:03:46 +05303735/*
3736 * do_y420vdb_modes - Parse YCBCR 420 only modes
3737 * @connector: connector corresponding to the HDMI sink
3738 * @svds: start of the data block of CEA YCBCR 420 VDB
3739 * @len: length of the CEA YCBCR 420 VDB
3740 *
3741 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3742 * which contains modes which can be supported in YCBCR 420
3743 * output format only.
3744 */
3745static int do_y420vdb_modes(struct drm_connector *connector,
3746 const u8 *svds, u8 svds_len)
3747{
3748 int modes = 0, i;
3749 struct drm_device *dev = connector->dev;
3750 struct drm_display_info *info = &connector->display_info;
3751 struct drm_hdmi_info *hdmi = &info->hdmi;
3752
3753 for (i = 0; i < svds_len; i++) {
3754 u8 vic = svd_to_vic(svds[i]);
3755 struct drm_display_mode *newmode;
3756
3757 if (!drm_valid_cea_vic(vic))
3758 continue;
3759
Ville Syrjälä7befe622019-12-13 19:43:45 +02003760 newmode = drm_mode_duplicate(dev, cea_mode_for_vic(vic));
Shashank Sharma832d4f22017-07-14 16:03:46 +05303761 if (!newmode)
3762 break;
3763 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3764 drm_mode_probed_add(connector, newmode);
3765 modes++;
3766 }
3767
3768 if (modes > 0)
3769 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3770 return modes;
3771}
3772
3773/*
3774 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3775 * @connector: connector corresponding to the HDMI sink
3776 * @vic: CEA vic for the video mode to be added in the map
3777 *
3778 * Makes an entry for a videomode in the YCBCR 420 bitmap
3779 */
3780static void
3781drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3782{
3783 u8 vic = svd_to_vic(svd);
3784 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3785
3786 if (!drm_valid_cea_vic(vic))
3787 return;
3788
3789 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3790}
3791
Ville Syrjälä7af655b2020-09-04 14:53:49 +03003792/**
3793 * drm_display_mode_from_cea_vic() - return a mode for CEA VIC
3794 * @dev: DRM device
Mauro Carvalho Chehab8d7d8c02020-10-27 10:51:16 +01003795 * @video_code: CEA VIC of the mode
Ville Syrjälä7af655b2020-09-04 14:53:49 +03003796 *
3797 * Creates a new mode matching the specified CEA VIC.
3798 *
3799 * Returns: A new drm_display_mode on success or NULL on failure
3800 */
3801struct drm_display_mode *
3802drm_display_mode_from_cea_vic(struct drm_device *dev,
3803 u8 video_code)
3804{
3805 const struct drm_display_mode *cea_mode;
3806 struct drm_display_mode *newmode;
3807
3808 cea_mode = cea_mode_for_vic(video_code);
3809 if (!cea_mode)
3810 return NULL;
3811
3812 newmode = drm_mode_duplicate(dev, cea_mode);
3813 if (!newmode)
3814 return NULL;
3815
3816 return newmode;
3817}
3818EXPORT_SYMBOL(drm_display_mode_from_cea_vic);
3819
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003820static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01003821do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003822{
Thomas Woodaff04ac2013-11-29 15:33:27 +00003823 int i, modes = 0;
Shashank Sharma832d4f22017-07-14 16:03:46 +05303824 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003825
Thomas Woodaff04ac2013-11-29 15:33:27 +00003826 for (i = 0; i < len; i++) {
3827 struct drm_display_mode *mode;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05303828
Thomas Woodaff04ac2013-11-29 15:33:27 +00003829 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3830 if (mode) {
Shashank Sharma832d4f22017-07-14 16:03:46 +05303831 /*
3832 * YCBCR420 capability block contains a bitmap which
3833 * gives the index of CEA modes from CEA VDB, which
3834 * can support YCBCR 420 sampling output also (apart
3835 * from RGB/YCBCR444 etc).
3836 * For example, if the bit 0 in bitmap is set,
3837 * first mode in VDB can support YCBCR420 output too.
3838 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3839 */
3840 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3841 drm_add_cmdb_modes(connector, db[i]);
3842
Thomas Woodaff04ac2013-11-29 15:33:27 +00003843 drm_mode_probed_add(connector, mode);
3844 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003845 }
3846 }
3847
3848 return modes;
3849}
3850
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003851struct stereo_mandatory_mode {
3852 int width, height, vrefresh;
3853 unsigned int flags;
3854};
3855
3856static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003857 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3858 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003859 { 1920, 1080, 50,
3860 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3861 { 1920, 1080, 60,
3862 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003863 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3864 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3865 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3866 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003867};
3868
3869static bool
3870stereo_match_mandatory(const struct drm_display_mode *mode,
3871 const struct stereo_mandatory_mode *stereo_mode)
3872{
3873 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3874
3875 return mode->hdisplay == stereo_mode->width &&
3876 mode->vdisplay == stereo_mode->height &&
3877 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3878 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3879}
3880
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003881static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3882{
3883 struct drm_device *dev = connector->dev;
3884 const struct drm_display_mode *mode;
3885 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003886 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003887
3888 INIT_LIST_HEAD(&stereo_modes);
3889
3890 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003891 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3892 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003893 struct drm_display_mode *new_mode;
3894
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003895 if (!stereo_match_mandatory(mode,
3896 &stereo_mandatory_modes[i]))
3897 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003898
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003899 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003900 new_mode = drm_mode_duplicate(dev, mode);
3901 if (!new_mode)
3902 continue;
3903
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003904 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003905 list_add_tail(&new_mode->head, &stereo_modes);
3906 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01003907 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003908 }
3909
3910 list_splice_tail(&stereo_modes, &connector->probed_modes);
3911
3912 return modes;
3913}
3914
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003915static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3916{
3917 struct drm_device *dev = connector->dev;
3918 struct drm_display_mode *newmode;
3919
Jani Nikulad9278b42016-01-08 13:21:51 +02003920 if (!drm_valid_hdmi_vic(vic)) {
Damien Lespiau1deee8d2013-09-25 16:45:24 +01003921 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3922 return 0;
3923 }
3924
3925 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3926 if (!newmode)
3927 return 0;
3928
3929 drm_mode_probed_add(connector, newmode);
3930
3931 return 1;
3932}
3933
Thomas Woodfbf46022013-10-16 15:58:50 +01003934static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3935 const u8 *video_db, u8 video_len, u8 video_index)
3936{
Thomas Woodfbf46022013-10-16 15:58:50 +01003937 struct drm_display_mode *newmode;
3938 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01003939
3940 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003941 newmode = drm_display_mode_from_vic_index(connector, video_db,
3942 video_len,
3943 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003944 if (newmode) {
3945 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3946 drm_mode_probed_add(connector, newmode);
3947 modes++;
3948 }
3949 }
3950 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003951 newmode = drm_display_mode_from_vic_index(connector, video_db,
3952 video_len,
3953 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003954 if (newmode) {
3955 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3956 drm_mode_probed_add(connector, newmode);
3957 modes++;
3958 }
3959 }
3960 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00003961 newmode = drm_display_mode_from_vic_index(connector, video_db,
3962 video_len,
3963 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01003964 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00003965 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01003966 drm_mode_probed_add(connector, newmode);
3967 modes++;
3968 }
3969 }
3970
3971 return modes;
3972}
3973
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003974/*
3975 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3976 * @connector: connector corresponding to the HDMI sink
3977 * @db: start of the CEA vendor specific block
3978 * @len: length of the CEA block payload, ie. one can access up to db[len]
3979 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003980 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3981 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003982 */
3983static int
Thomas Woodfbf46022013-10-16 15:58:50 +01003984do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3985 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003986{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02003987 struct drm_display_info *info = &connector->display_info;
Thomas Wood0e5083aa2013-11-29 18:18:58 +00003988 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01003989 u8 vic_len, hdmi_3d_len = 0;
3990 u16 mask;
3991 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01003992
3993 if (len < 8)
3994 goto out;
3995
3996 /* no HDMI_Video_Present */
3997 if (!(db[8] & (1 << 5)))
3998 goto out;
3999
4000 /* Latency_Fields_Present */
4001 if (db[8] & (1 << 7))
4002 offset += 2;
4003
4004 /* I_Latency_Fields_Present */
4005 if (db[8] & (1 << 6))
4006 offset += 2;
4007
4008 /* the declared length is not long enough for the 2 first bytes
4009 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004010 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004011 goto out;
4012
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004013 /* 3D_Present */
4014 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01004015 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004016 modes += add_hdmi_mandatory_stereo_modes(connector);
4017
Thomas Woodfbf46022013-10-16 15:58:50 +01004018 /* 3D_Multi_present */
4019 multi_present = (db[8 + offset] & 0x60) >> 5;
4020 }
4021
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004022 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004023 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01004024 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004025
4026 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004027 u8 vic;
4028
4029 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01004030 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004031 }
Thomas Woodfbf46022013-10-16 15:58:50 +01004032 offset += 1 + vic_len;
4033
Thomas Wood0e5083aa2013-11-29 18:18:58 +00004034 if (multi_present == 1)
4035 multi_len = 2;
4036 else if (multi_present == 2)
4037 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01004038 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00004039 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01004040
Thomas Wood0e5083aa2013-11-29 18:18:58 +00004041 if (len < (8 + offset + hdmi_3d_len - 1))
4042 goto out;
4043
4044 if (hdmi_3d_len < multi_len)
4045 goto out;
4046
4047 if (multi_present == 1 || multi_present == 2) {
4048 /* 3D_Structure_ALL */
4049 structure_all = (db[8 + offset] << 8) | db[9 + offset];
4050
4051 /* check if 3D_MASK is present */
4052 if (multi_present == 2)
4053 mask = (db[10 + offset] << 8) | db[11 + offset];
4054 else
4055 mask = 0xffff;
4056
4057 for (i = 0; i < 16; i++) {
4058 if (mask & (1 << i))
4059 modes += add_3d_struct_modes(connector,
4060 structure_all,
4061 video_db,
4062 video_len, i);
4063 }
4064 }
4065
4066 offset += multi_len;
4067
4068 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
4069 int vic_index;
4070 struct drm_display_mode *newmode = NULL;
4071 unsigned int newflag = 0;
4072 bool detail_present;
4073
4074 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
4075
4076 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
4077 break;
4078
4079 /* 2D_VIC_order_X */
4080 vic_index = db[8 + offset + i] >> 4;
4081
4082 /* 3D_Structure_X */
4083 switch (db[8 + offset + i] & 0x0f) {
4084 case 0:
4085 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
4086 break;
4087 case 6:
4088 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
4089 break;
4090 case 8:
4091 /* 3D_Detail_X */
4092 if ((db[9 + offset + i] >> 4) == 1)
4093 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
4094 break;
4095 }
4096
4097 if (newflag != 0) {
4098 newmode = drm_display_mode_from_vic_index(connector,
4099 video_db,
4100 video_len,
4101 vic_index);
4102
4103 if (newmode) {
4104 newmode->flags |= newflag;
4105 drm_mode_probed_add(connector, newmode);
4106 modes++;
4107 }
4108 }
4109
4110 if (detail_present)
4111 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01004112 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004113
4114out:
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004115 if (modes > 0)
4116 info->has_hdmi_infoframe = true;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004117 return modes;
4118}
4119
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004120static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004121cea_db_payload_len(const u8 *db)
4122{
4123 return db[0] & 0x1f;
4124}
4125
4126static int
Shashank Sharma87563fc2017-07-13 21:03:10 +05304127cea_db_extended_tag(const u8 *db)
4128{
4129 return db[1];
4130}
4131
4132static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004133cea_db_tag(const u8 *db)
4134{
4135 return db[0] >> 5;
4136}
4137
4138static int
4139cea_revision(const u8 *cea)
4140{
Ville Syrjälä5036c0d2020-01-24 22:02:29 +02004141 /*
4142 * FIXME is this correct for the DispID variant?
4143 * The DispID spec doesn't really specify whether
4144 * this is the revision of the CEA extension or
4145 * the DispID CEA data block. And the only value
4146 * given as an example is 0.
4147 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004148 return cea[1];
4149}
4150
4151static int
4152cea_db_offsets(const u8 *cea, int *start, int *end)
4153{
Andres Rodrigueze28ad542019-06-19 14:09:01 -04004154 /* DisplayID CTA extension blocks and top-level CEA EDID
4155 * block header definitions differ in the following bytes:
4156 * 1) Byte 2 of the header specifies length differently,
4157 * 2) Byte 3 is only present in the CEA top level block.
4158 *
4159 * The different definitions for byte 2 follow.
4160 *
4161 * DisplayID CTA extension block defines byte 2 as:
4162 * Number of payload bytes
4163 *
4164 * CEA EDID block defines byte 2 as:
4165 * Byte number (decimal) within this block where the 18-byte
4166 * DTDs begin. If no non-DTD data is present in this extension
4167 * block, the value should be set to 04h (the byte after next).
4168 * If set to 00h, there are no DTDs present in this block and
4169 * no non-DTD data.
4170 */
4171 if (cea[0] == DATA_BLOCK_CTA) {
Ville Syrjälä6e8a9422020-01-24 22:02:28 +02004172 /*
4173 * for_each_displayid_db() has already verified
4174 * that these stay within expected bounds.
4175 */
Andres Rodrigueze28ad542019-06-19 14:09:01 -04004176 *start = 3;
4177 *end = *start + cea[2];
4178 } else if (cea[0] == CEA_EXT) {
4179 /* Data block offset in CEA extension block */
4180 *start = 4;
4181 *end = cea[2];
4182 if (*end == 0)
4183 *end = 127;
4184 if (*end < 4 || *end > 127)
4185 return -ERANGE;
4186 } else {
Daniel Vetterc7581a42019-09-04 16:39:42 +02004187 return -EOPNOTSUPP;
Andres Rodrigueze28ad542019-06-19 14:09:01 -04004188 }
4189
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004190 return 0;
4191}
4192
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004193static bool cea_db_is_hdmi_vsdb(const u8 *db)
4194{
4195 int hdmi_id;
4196
4197 if (cea_db_tag(db) != VENDOR_BLOCK)
4198 return false;
4199
4200 if (cea_db_payload_len(db) < 5)
4201 return false;
4202
4203 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
4204
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01004205 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01004206}
4207
Thierry Reding50dd1bd2017-03-13 16:54:00 +05304208static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
4209{
4210 unsigned int oui;
4211
4212 if (cea_db_tag(db) != VENDOR_BLOCK)
4213 return false;
4214
4215 if (cea_db_payload_len(db) < 7)
4216 return false;
4217
4218 oui = db[3] << 16 | db[2] << 8 | db[1];
4219
4220 return oui == HDMI_FORUM_IEEE_OUI;
4221}
4222
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004223static bool cea_db_is_vcdb(const u8 *db)
4224{
4225 if (cea_db_tag(db) != USE_EXTENDED_TAG)
4226 return false;
4227
4228 if (cea_db_payload_len(db) != 2)
4229 return false;
4230
4231 if (cea_db_extended_tag(db) != EXT_VIDEO_CAPABILITY_BLOCK)
4232 return false;
4233
4234 return true;
4235}
4236
Shashank Sharma832d4f22017-07-14 16:03:46 +05304237static bool cea_db_is_y420cmdb(const u8 *db)
4238{
4239 if (cea_db_tag(db) != USE_EXTENDED_TAG)
4240 return false;
4241
4242 if (!cea_db_payload_len(db))
4243 return false;
4244
4245 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
4246 return false;
4247
4248 return true;
4249}
4250
4251static bool cea_db_is_y420vdb(const u8 *db)
4252{
4253 if (cea_db_tag(db) != USE_EXTENDED_TAG)
4254 return false;
4255
4256 if (!cea_db_payload_len(db))
4257 return false;
4258
4259 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
4260 return false;
4261
4262 return true;
4263}
4264
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004265#define for_each_cea_db(cea, i, start, end) \
4266 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
4267
Shashank Sharma832d4f22017-07-14 16:03:46 +05304268static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
4269 const u8 *db)
4270{
4271 struct drm_display_info *info = &connector->display_info;
4272 struct drm_hdmi_info *hdmi = &info->hdmi;
4273 u8 map_len = cea_db_payload_len(db) - 1;
4274 u8 count;
4275 u64 map = 0;
4276
4277 if (map_len == 0) {
4278 /* All CEA modes support ycbcr420 sampling also.*/
4279 hdmi->y420_cmdb_map = U64_MAX;
4280 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
4281 return;
4282 }
4283
4284 /*
4285 * This map indicates which of the existing CEA block modes
4286 * from VDB can support YCBCR420 output too. So if bit=0 is
4287 * set, first mode from VDB can support YCBCR420 output too.
4288 * We will parse and keep this map, before parsing VDB itself
4289 * to avoid going through the same block again and again.
4290 *
4291 * Spec is not clear about max possible size of this block.
4292 * Clamping max bitmap block size at 8 bytes. Every byte can
4293 * address 8 CEA modes, in this way this map can address
4294 * 8*8 = first 64 SVDs.
4295 */
4296 if (WARN_ON_ONCE(map_len > 8))
4297 map_len = 8;
4298
4299 for (count = 0; count < map_len; count++)
4300 map |= (u64)db[2 + count] << (8 * count);
4301
4302 if (map)
4303 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
4304
4305 hdmi->y420_cmdb_map = map;
4306}
4307
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004308static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004309add_cea_modes(struct drm_connector *connector, struct edid *edid)
4310{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01004311 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01004312 const u8 *db, *hdmi = NULL, *video = NULL;
4313 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004314 int modes = 0;
4315
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004316 if (cea && cea_revision(cea) >= 3) {
4317 int i, start, end;
4318
4319 if (cea_db_offsets(cea, &start, &end))
4320 return 0;
4321
4322 for_each_cea_db(cea, i, start, end) {
4323 db = &cea[i];
4324 dbl = cea_db_payload_len(db);
4325
Thomas Woodfbf46022013-10-16 15:58:50 +01004326 if (cea_db_tag(db) == VIDEO_BLOCK) {
4327 video = db + 1;
4328 video_len = dbl;
4329 modes += do_cea_modes(connector, video, dbl);
Shashank Sharma832d4f22017-07-14 16:03:46 +05304330 } else if (cea_db_is_hdmi_vsdb(db)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004331 hdmi = db;
4332 hdmi_len = dbl;
Shashank Sharma832d4f22017-07-14 16:03:46 +05304333 } else if (cea_db_is_y420vdb(db)) {
4334 const u8 *vdb420 = &db[2];
4335
4336 /* Add 4:2:0(only) modes present in EDID */
4337 modes += do_y420vdb_modes(connector,
4338 vdb420,
4339 dbl - 1);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004340 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004341 }
4342 }
4343
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004344 /*
4345 * We parse the HDMI VSDB after having added the cea modes as we will
4346 * be patching their flags when the sink supports stereo 3D.
4347 */
4348 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01004349 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
4350 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01004351
Christian Schmidt54ac76f2011-12-19 14:53:16 +00004352 return modes;
4353}
4354
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004355static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
4356{
4357 const struct drm_display_mode *cea_mode;
4358 int clock1, clock2, clock;
Jani Nikulad9278b42016-01-08 13:21:51 +02004359 u8 vic;
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004360 const char *type;
4361
Ville Syrjälä4c6bcf42015-11-16 21:05:12 +02004362 /*
4363 * allow 5kHz clock difference either way to account for
4364 * the 10kHz clock resolution limit of detailed timings.
4365 */
Jani Nikulad9278b42016-01-08 13:21:51 +02004366 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
4367 if (drm_valid_cea_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004368 type = "CEA";
Ville Syrjälä7befe622019-12-13 19:43:45 +02004369 cea_mode = cea_mode_for_vic(vic);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004370 clock1 = cea_mode->clock;
4371 clock2 = cea_mode_alternate_clock(cea_mode);
4372 } else {
Jani Nikulad9278b42016-01-08 13:21:51 +02004373 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
4374 if (drm_valid_hdmi_vic(vic)) {
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004375 type = "HDMI";
Jani Nikulad9278b42016-01-08 13:21:51 +02004376 cea_mode = &edid_4k_modes[vic];
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004377 clock1 = cea_mode->clock;
4378 clock2 = hdmi_mode_alternate_clock(cea_mode);
4379 } else {
4380 return;
4381 }
4382 }
4383
4384 /* pick whichever is closest */
4385 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
4386 clock = clock1;
4387 else
4388 clock = clock2;
4389
4390 if (mode->clock == clock)
4391 return;
4392
4393 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
Jani Nikulad9278b42016-01-08 13:21:51 +02004394 type, vic, mode->clock, clock);
Ville Syrjäläfa3a7342015-10-08 11:43:32 +03004395 mode->clock = clock;
4396}
4397
Uma Shankare85959d2019-05-16 19:40:08 +05304398static bool cea_db_is_hdmi_hdr_metadata_block(const u8 *db)
4399{
4400 if (cea_db_tag(db) != USE_EXTENDED_TAG)
4401 return false;
4402
4403 if (db[1] != HDR_STATIC_METADATA_BLOCK)
4404 return false;
4405
4406 if (cea_db_payload_len(db) < 3)
4407 return false;
4408
4409 return true;
4410}
4411
4412static uint8_t eotf_supported(const u8 *edid_ext)
4413{
4414 return edid_ext[2] &
4415 (BIT(HDMI_EOTF_TRADITIONAL_GAMMA_SDR) |
4416 BIT(HDMI_EOTF_TRADITIONAL_GAMMA_HDR) |
Ville Syrjäläb5e3eed2019-05-16 19:40:12 +05304417 BIT(HDMI_EOTF_SMPTE_ST2084) |
4418 BIT(HDMI_EOTF_BT_2100_HLG));
Uma Shankare85959d2019-05-16 19:40:08 +05304419}
4420
4421static uint8_t hdr_metadata_type(const u8 *edid_ext)
4422{
4423 return edid_ext[3] &
4424 BIT(HDMI_STATIC_METADATA_TYPE1);
4425}
4426
4427static void
4428drm_parse_hdr_metadata_block(struct drm_connector *connector, const u8 *db)
4429{
4430 u16 len;
4431
4432 len = cea_db_payload_len(db);
4433
4434 connector->hdr_sink_metadata.hdmi_type1.eotf =
4435 eotf_supported(db);
4436 connector->hdr_sink_metadata.hdmi_type1.metadata_type =
4437 hdr_metadata_type(db);
4438
4439 if (len >= 4)
4440 connector->hdr_sink_metadata.hdmi_type1.max_cll = db[4];
4441 if (len >= 5)
4442 connector->hdr_sink_metadata.hdmi_type1.max_fall = db[5];
4443 if (len >= 6)
4444 connector->hdr_sink_metadata.hdmi_type1.min_cll = db[6];
4445}
4446
Wu Fengguang76adaa342011-09-05 14:23:20 +08004447static void
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004448drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004449{
Ville Syrjälä85040722012-08-16 14:55:05 +00004450 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004451
Jani Nikulaf7da77852017-11-01 16:20:57 +02004452 if (len >= 6 && (db[6] & (1 << 7)))
4453 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
Ville Syrjälä85040722012-08-16 14:55:05 +00004454 if (len >= 8) {
4455 connector->latency_present[0] = db[8] >> 7;
4456 connector->latency_present[1] = (db[8] >> 6) & 1;
4457 }
4458 if (len >= 9)
4459 connector->video_latency[0] = db[9];
4460 if (len >= 10)
4461 connector->audio_latency[0] = db[10];
4462 if (len >= 11)
4463 connector->video_latency[1] = db[11];
4464 if (len >= 12)
4465 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004466
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004467 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
4468 "video latency %d %d, "
4469 "audio latency %d %d\n",
4470 connector->latency_present[0],
4471 connector->latency_present[1],
4472 connector->video_latency[0],
4473 connector->video_latency[1],
4474 connector->audio_latency[0],
4475 connector->audio_latency[1]);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004476}
4477
4478static void
4479monitor_name(struct detailed_timing *t, void *data)
4480{
Ville Syrjäläa7a131a2020-01-24 22:02:25 +02004481 if (!is_display_descriptor((const u8 *)t, EDID_DETAIL_MONITOR_NAME))
4482 return;
4483
4484 *(u8 **)data = t->data.other_data.data.str.str;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004485}
4486
Jim Bride59f7c0f2016-04-14 10:18:35 -07004487static int get_monitor_name(struct edid *edid, char name[13])
4488{
4489 char *edid_name = NULL;
4490 int mnl;
4491
4492 if (!edid || !name)
4493 return 0;
4494
4495 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
4496 for (mnl = 0; edid_name && mnl < 13; mnl++) {
4497 if (edid_name[mnl] == 0x0a)
4498 break;
4499
4500 name[mnl] = edid_name[mnl];
4501 }
4502
4503 return mnl;
4504}
4505
4506/**
4507 * drm_edid_get_monitor_name - fetch the monitor name from the edid
4508 * @edid: monitor EDID information
4509 * @name: pointer to a character array to hold the name of the monitor
4510 * @bufsize: The size of the name buffer (should be at least 14 chars.)
4511 *
4512 */
4513void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
4514{
4515 int name_length;
4516 char buf[13];
Ville Syrjälä4d23f482020-01-24 22:02:27 +02004517
Jim Bride59f7c0f2016-04-14 10:18:35 -07004518 if (bufsize <= 0)
4519 return;
4520
4521 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
4522 memcpy(name, buf, name_length);
4523 name[name_length] = '\0';
4524}
4525EXPORT_SYMBOL(drm_edid_get_monitor_name);
4526
Jani Nikula42750d32017-11-01 16:21:00 +02004527static void clear_eld(struct drm_connector *connector)
4528{
4529 memset(connector->eld, 0, sizeof(connector->eld));
4530
4531 connector->latency_present[0] = false;
4532 connector->latency_present[1] = false;
4533 connector->video_latency[0] = 0;
4534 connector->audio_latency[0] = 0;
4535 connector->video_latency[1] = 0;
4536 connector->audio_latency[1] = 0;
4537}
4538
Jani Nikula79436a12017-11-01 16:21:03 +02004539/*
Wu Fengguang76adaa342011-09-05 14:23:20 +08004540 * drm_edid_to_eld - build ELD from EDID
4541 * @connector: connector corresponding to the HDMI/DP sink
4542 * @edid: EDID to parse
4543 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004544 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
Jani Nikula1d1c3662017-11-01 16:20:58 +02004545 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004546 */
Jani Nikula79436a12017-11-01 16:21:03 +02004547static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004548{
4549 uint8_t *eld = connector->eld;
Jani Nikula43d16d82021-03-29 16:37:15 +03004550 const u8 *cea;
4551 const u8 *db;
Ville Syrjälä7c018782016-03-09 22:07:46 +02004552 int total_sad_count = 0;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004553 int mnl;
4554 int dbl;
4555
Jani Nikula42750d32017-11-01 16:21:00 +02004556 clear_eld(connector);
Ville Syrjälä85c91582016-09-28 16:51:34 +03004557
Jani Nikulae9bd0b82017-02-17 17:20:52 +02004558 if (!edid)
4559 return;
4560
Wu Fengguang76adaa342011-09-05 14:23:20 +08004561 cea = drm_find_cea_extension(edid);
4562 if (!cea) {
4563 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
4564 return;
4565 }
4566
Jani Nikulaf7da77852017-11-01 16:20:57 +02004567 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
4568 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
Jim Bride59f7c0f2016-04-14 10:18:35 -07004569
Jani Nikulaf7da77852017-11-01 16:20:57 +02004570 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
4571 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004572
Jani Nikulaf7da77852017-11-01 16:20:57 +02004573 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004574
Jani Nikulaf7da77852017-11-01 16:20:57 +02004575 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
4576 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
4577 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
4578 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
Wu Fengguang76adaa342011-09-05 14:23:20 +08004579
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004580 if (cea_revision(cea) >= 3) {
4581 int i, start, end;
Kees Cookdeec2222020-03-06 09:32:13 -08004582 int sad_count;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004583
4584 if (cea_db_offsets(cea, &start, &end)) {
4585 start = 0;
4586 end = 0;
4587 }
4588
4589 for_each_cea_db(cea, i, start, end) {
4590 db = &cea[i];
4591 dbl = cea_db_payload_len(db);
4592
4593 switch (cea_db_tag(db)) {
Christian Schmidta0ab7342011-12-19 20:03:38 +01004594 case AUDIO_BLOCK:
4595 /* Audio Data Block, contains SADs */
Ville Syrjälä7c018782016-03-09 22:07:46 +02004596 sad_count = min(dbl / 3, 15 - total_sad_count);
4597 if (sad_count >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004598 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
Ville Syrjälä7c018782016-03-09 22:07:46 +02004599 &db[1], sad_count * 3);
4600 total_sad_count += sad_count;
Christian Schmidta0ab7342011-12-19 20:03:38 +01004601 break;
4602 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004603 /* Speaker Allocation Data Block */
4604 if (dbl >= 1)
Jani Nikulaf7da77852017-11-01 16:20:57 +02004605 eld[DRM_ELD_SPEAKER] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01004606 break;
4607 case VENDOR_BLOCK:
4608 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004609 if (cea_db_is_hdmi_vsdb(db))
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03004610 drm_parse_hdmi_vsdb_audio(connector, db);
Christian Schmidta0ab7342011-12-19 20:03:38 +01004611 break;
4612 default:
4613 break;
4614 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08004615 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004616 }
Jani Nikulaf7da77852017-11-01 16:20:57 +02004617 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004618
Jani Nikula1d1c3662017-11-01 16:20:58 +02004619 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4620 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4621 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
4622 else
4623 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
Wu Fengguang76adaa342011-09-05 14:23:20 +08004624
Jani Nikula938fd8a2014-10-28 16:20:48 +02004625 eld[DRM_ELD_BASELINE_ELD_LEN] =
4626 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
4627
4628 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
Ville Syrjälä7c018782016-03-09 22:07:46 +02004629 drm_eld_size(eld), total_sad_count);
Wu Fengguang76adaa342011-09-05 14:23:20 +08004630}
Wu Fengguang76adaa342011-09-05 14:23:20 +08004631
4632/**
Rafał Miłeckife214162013-04-19 19:01:25 +02004633 * drm_edid_to_sad - extracts SADs from EDID
4634 * @edid: EDID to parse
4635 * @sads: pointer that will be set to the extracted SADs
4636 *
4637 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02004638 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004639 * Note: The returned pointer needs to be freed using kfree().
4640 *
4641 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02004642 */
4643int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
4644{
4645 int count = 0;
4646 int i, start, end, dbl;
Jani Nikula43d16d82021-03-29 16:37:15 +03004647 const u8 *cea;
Rafał Miłeckife214162013-04-19 19:01:25 +02004648
4649 cea = drm_find_cea_extension(edid);
4650 if (!cea) {
4651 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
Jean Delvare42908002019-11-15 17:07:36 +01004652 return 0;
Rafał Miłeckife214162013-04-19 19:01:25 +02004653 }
4654
4655 if (cea_revision(cea) < 3) {
4656 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Jean Delvare42908002019-11-15 17:07:36 +01004657 return 0;
Rafał Miłeckife214162013-04-19 19:01:25 +02004658 }
4659
4660 if (cea_db_offsets(cea, &start, &end)) {
4661 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4662 return -EPROTO;
4663 }
4664
4665 for_each_cea_db(cea, i, start, end) {
Jani Nikula43d16d82021-03-29 16:37:15 +03004666 const u8 *db = &cea[i];
Rafał Miłeckife214162013-04-19 19:01:25 +02004667
4668 if (cea_db_tag(db) == AUDIO_BLOCK) {
4669 int j;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05304670
Rafał Miłeckife214162013-04-19 19:01:25 +02004671 dbl = cea_db_payload_len(db);
4672
4673 count = dbl / 3; /* SAD is 3B */
4674 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
4675 if (!*sads)
4676 return -ENOMEM;
4677 for (j = 0; j < count; j++) {
Jani Nikula43d16d82021-03-29 16:37:15 +03004678 const u8 *sad = &db[1 + j * 3];
Rafał Miłeckife214162013-04-19 19:01:25 +02004679
4680 (*sads)[j].format = (sad[0] & 0x78) >> 3;
4681 (*sads)[j].channels = sad[0] & 0x7;
4682 (*sads)[j].freq = sad[1] & 0x7F;
4683 (*sads)[j].byte2 = sad[2];
4684 }
4685 break;
4686 }
4687 }
4688
4689 return count;
4690}
4691EXPORT_SYMBOL(drm_edid_to_sad);
4692
4693/**
Alex Deucherd105f472013-07-25 15:55:32 -04004694 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4695 * @edid: EDID to parse
4696 * @sadb: pointer to the speaker block
4697 *
4698 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04004699 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004700 * Note: The returned pointer needs to be freed using kfree().
4701 *
4702 * Return: The number of found Speaker Allocation Blocks or negative number on
4703 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04004704 */
4705int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4706{
4707 int count = 0;
4708 int i, start, end, dbl;
4709 const u8 *cea;
4710
4711 cea = drm_find_cea_extension(edid);
4712 if (!cea) {
4713 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
Jean Delvare42908002019-11-15 17:07:36 +01004714 return 0;
Alex Deucherd105f472013-07-25 15:55:32 -04004715 }
4716
4717 if (cea_revision(cea) < 3) {
4718 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
Jean Delvare42908002019-11-15 17:07:36 +01004719 return 0;
Alex Deucherd105f472013-07-25 15:55:32 -04004720 }
4721
4722 if (cea_db_offsets(cea, &start, &end)) {
4723 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4724 return -EPROTO;
4725 }
4726
4727 for_each_cea_db(cea, i, start, end) {
4728 const u8 *db = &cea[i];
4729
4730 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4731 dbl = cea_db_payload_len(db);
4732
4733 /* Speaker Allocation Data Block */
4734 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02004735 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04004736 if (!*sadb)
4737 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04004738 count = dbl;
4739 break;
4740 }
4741 }
4742 }
4743
4744 return count;
4745}
4746EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4747
4748/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004749 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08004750 * @connector: connector associated with the HDMI/DP sink
4751 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004752 *
4753 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4754 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08004755 */
4756int drm_av_sync_delay(struct drm_connector *connector,
Ville Syrjälä3a818d32015-09-07 18:22:58 +03004757 const struct drm_display_mode *mode)
Wu Fengguang76adaa342011-09-05 14:23:20 +08004758{
4759 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4760 int a, v;
4761
4762 if (!connector->latency_present[0])
4763 return 0;
4764 if (!connector->latency_present[1])
4765 i = 0;
4766
4767 a = connector->audio_latency[i];
4768 v = connector->video_latency[i];
4769
4770 /*
4771 * HDMI/DP sink doesn't support audio or video?
4772 */
4773 if (a == 255 || v == 255)
4774 return 0;
4775
4776 /*
4777 * Convert raw EDID values to millisecond.
4778 * Treat unknown latency as 0ms.
4779 */
4780 if (a)
4781 a = min(2 * (a - 1), 500);
4782 if (v)
4783 v = min(2 * (v - 1), 500);
4784
4785 return max(v - a, 0);
4786}
4787EXPORT_SYMBOL(drm_av_sync_delay);
4788
4789/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004790 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08004791 * @edid: monitor EDID information
4792 *
4793 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004794 *
Laurent Pincharta92d0832020-02-26 13:24:23 +02004795 * Drivers that have added the modes parsed from EDID to drm_display_info
4796 * should use &drm_display_info.is_hdmi instead of calling this function.
4797 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004798 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08004799 */
4800bool drm_detect_hdmi_monitor(struct edid *edid)
4801{
Jani Nikula43d16d82021-03-29 16:37:15 +03004802 const u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004803 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08004804 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08004805
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004806 edid_ext = drm_find_cea_extension(edid);
4807 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004808 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004809
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004810 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004811 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004812
4813 /*
4814 * Because HDMI identifier is in Vendor Specific Block,
4815 * search it from all data blocks of CEA extension.
4816 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004817 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004818 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4819 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08004820 }
4821
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00004822 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08004823}
4824EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4825
Dave Airlief453ba02008-11-07 14:05:41 -08004826/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004827 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01004828 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004829 *
4830 * Monitor should have CEA extension block.
4831 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4832 * audio' only. If there is any audio extension block and supported
4833 * audio format, assume at least 'basic audio' support, even if 'basic
4834 * audio' is not defined in EDID.
4835 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02004836 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004837 */
4838bool drm_detect_monitor_audio(struct edid *edid)
4839{
Jani Nikula43d16d82021-03-29 16:37:15 +03004840 const u8 *edid_ext;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004841 int i, j;
4842 bool has_audio = false;
4843 int start_offset, end_offset;
4844
4845 edid_ext = drm_find_cea_extension(edid);
4846 if (!edid_ext)
4847 goto end;
4848
4849 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4850
4851 if (has_audio) {
4852 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4853 goto end;
4854 }
4855
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004856 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4857 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004858
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004859 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4860 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004861 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00004862 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08004863 DRM_DEBUG_KMS("CEA audio format %d\n",
4864 (edid_ext[i + j] >> 3) & 0xf);
4865 goto end;
4866 }
4867 }
4868end:
4869 return has_audio;
4870}
4871EXPORT_SYMBOL(drm_detect_monitor_audio);
4872
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02004873
Ville Syrjäläc8127cf02017-01-11 16:18:35 +02004874/**
4875 * drm_default_rgb_quant_range - default RGB quantization range
4876 * @mode: display mode
4877 *
4878 * Determine the default RGB quantization range for the mode,
4879 * as specified in CEA-861.
4880 *
4881 * Return: The default RGB quantization range for the mode
4882 */
4883enum hdmi_quantization_range
4884drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4885{
4886 /* All CEA modes other than VIC 1 use limited quantization range. */
4887 return drm_match_cea_mode(mode) > 1 ?
4888 HDMI_QUANTIZATION_RANGE_LIMITED :
4889 HDMI_QUANTIZATION_RANGE_FULL;
4890}
4891EXPORT_SYMBOL(drm_default_rgb_quant_range);
4892
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02004893static void drm_parse_vcdb(struct drm_connector *connector, const u8 *db)
4894{
4895 struct drm_display_info *info = &connector->display_info;
4896
4897 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", db[2]);
4898
4899 if (db[2] & EDID_CEA_VCDB_QS)
4900 info->rgb_quant_range_selectable = true;
4901}
4902
Swati Sharma4499d482020-12-18 16:07:10 +05304903static
4904void drm_get_max_frl_rate(int max_frl_rate, u8 *max_lanes, u8 *max_rate_per_lane)
4905{
4906 switch (max_frl_rate) {
4907 case 1:
4908 *max_lanes = 3;
4909 *max_rate_per_lane = 3;
4910 break;
4911 case 2:
4912 *max_lanes = 3;
4913 *max_rate_per_lane = 6;
4914 break;
4915 case 3:
4916 *max_lanes = 4;
4917 *max_rate_per_lane = 6;
4918 break;
4919 case 4:
4920 *max_lanes = 4;
4921 *max_rate_per_lane = 8;
4922 break;
4923 case 5:
4924 *max_lanes = 4;
4925 *max_rate_per_lane = 10;
4926 break;
4927 case 6:
4928 *max_lanes = 4;
4929 *max_rate_per_lane = 12;
4930 break;
4931 case 0:
4932 default:
4933 *max_lanes = 0;
4934 *max_rate_per_lane = 0;
4935 }
4936}
4937
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304938static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4939 const u8 *db)
4940{
4941 u8 dc_mask;
4942 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4943
4944 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
Clint Taylor9068e022018-10-05 14:52:15 -07004945 hdmi->y420_dc_modes = dc_mask;
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304946}
4947
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304948static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4949 const u8 *hf_vsdb)
4950{
Shashank Sharma62c58af2017-03-13 16:54:02 +05304951 struct drm_display_info *display = &connector->display_info;
4952 struct drm_hdmi_info *hdmi = &display->hdmi;
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304953
Ville Syrjäläf1781e92017-11-13 19:04:19 +02004954 display->has_hdmi_infoframe = true;
4955
Shashank Sharmaafa1c762017-03-13 16:54:01 +05304956 if (hf_vsdb[6] & 0x80) {
4957 hdmi->scdc.supported = true;
4958 if (hf_vsdb[6] & 0x40)
4959 hdmi->scdc.read_request = true;
4960 }
Shashank Sharma62c58af2017-03-13 16:54:02 +05304961
4962 /*
4963 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4964 * And as per the spec, three factors confirm this:
4965 * * Availability of a HF-VSDB block in EDID (check)
4966 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4967 * * SCDC support available (let's check)
4968 * Lets check it out.
4969 */
4970
4971 if (hf_vsdb[5]) {
4972 /* max clock is 5000 KHz times block value */
4973 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4974 struct drm_scdc *scdc = &hdmi->scdc;
4975
4976 if (max_tmds_clock > 340000) {
4977 display->max_tmds_clock = max_tmds_clock;
4978 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4979 display->max_tmds_clock);
4980 }
4981
4982 if (scdc->supported) {
4983 scdc->scrambling.supported = true;
4984
Thierry Redingdbe2d2b2019-12-06 14:53:35 +01004985 /* Few sinks support scrambling for clocks < 340M */
Shashank Sharma62c58af2017-03-13 16:54:02 +05304986 if ((hf_vsdb[6] & 0x8))
4987 scdc->scrambling.low_rates = true;
4988 }
4989 }
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05304990
Swati Sharma4499d482020-12-18 16:07:10 +05304991 if (hf_vsdb[7]) {
4992 u8 max_frl_rate;
Ankit Nautiyal76ee7b92020-12-18 16:07:11 +05304993 u8 dsc_max_frl_rate;
4994 u8 dsc_max_slices;
4995 struct drm_hdmi_dsc_cap *hdmi_dsc = &hdmi->dsc_cap;
Swati Sharma4499d482020-12-18 16:07:10 +05304996
4997 DRM_DEBUG_KMS("hdmi_21 sink detected. parsing edid\n");
4998 max_frl_rate = (hf_vsdb[7] & DRM_EDID_MAX_FRL_RATE_MASK) >> 4;
4999 drm_get_max_frl_rate(max_frl_rate, &hdmi->max_lanes,
5000 &hdmi->max_frl_rate_per_lane);
Ankit Nautiyal76ee7b92020-12-18 16:07:11 +05305001 hdmi_dsc->v_1p2 = hf_vsdb[11] & DRM_EDID_DSC_1P2;
5002
5003 if (hdmi_dsc->v_1p2) {
5004 hdmi_dsc->native_420 = hf_vsdb[11] & DRM_EDID_DSC_NATIVE_420;
5005 hdmi_dsc->all_bpp = hf_vsdb[11] & DRM_EDID_DSC_ALL_BPP;
5006
5007 if (hf_vsdb[11] & DRM_EDID_DSC_16BPC)
5008 hdmi_dsc->bpc_supported = 16;
5009 else if (hf_vsdb[11] & DRM_EDID_DSC_12BPC)
5010 hdmi_dsc->bpc_supported = 12;
5011 else if (hf_vsdb[11] & DRM_EDID_DSC_10BPC)
5012 hdmi_dsc->bpc_supported = 10;
5013 else
5014 hdmi_dsc->bpc_supported = 0;
5015
5016 dsc_max_frl_rate = (hf_vsdb[12] & DRM_EDID_DSC_MAX_FRL_RATE_MASK) >> 4;
5017 drm_get_max_frl_rate(dsc_max_frl_rate, &hdmi_dsc->max_lanes,
5018 &hdmi_dsc->max_frl_rate_per_lane);
5019 hdmi_dsc->total_chunk_kbytes = hf_vsdb[13] & DRM_EDID_DSC_TOTAL_CHUNK_KBYTES;
5020
5021 dsc_max_slices = hf_vsdb[12] & DRM_EDID_DSC_MAX_SLICES;
5022 switch (dsc_max_slices) {
5023 case 1:
5024 hdmi_dsc->max_slices = 1;
5025 hdmi_dsc->clk_per_slice = 340;
5026 break;
5027 case 2:
5028 hdmi_dsc->max_slices = 2;
5029 hdmi_dsc->clk_per_slice = 340;
5030 break;
5031 case 3:
5032 hdmi_dsc->max_slices = 4;
5033 hdmi_dsc->clk_per_slice = 340;
5034 break;
5035 case 4:
5036 hdmi_dsc->max_slices = 8;
5037 hdmi_dsc->clk_per_slice = 340;
5038 break;
5039 case 5:
5040 hdmi_dsc->max_slices = 8;
5041 hdmi_dsc->clk_per_slice = 400;
5042 break;
5043 case 6:
5044 hdmi_dsc->max_slices = 12;
5045 hdmi_dsc->clk_per_slice = 400;
5046 break;
5047 case 7:
5048 hdmi_dsc->max_slices = 16;
5049 hdmi_dsc->clk_per_slice = 400;
5050 break;
5051 case 0:
5052 default:
5053 hdmi_dsc->max_slices = 0;
5054 hdmi_dsc->clk_per_slice = 0;
5055 }
5056 }
Swati Sharma4499d482020-12-18 16:07:10 +05305057 }
5058
Shashank Sharmae6a9a2c2017-07-13 21:03:13 +05305059 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05305060}
5061
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005062static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
5063 const u8 *hdmi)
Mario Kleinerd0c94692014-03-27 19:59:39 +01005064{
Ville Syrjälä18267502016-09-28 16:51:38 +03005065 struct drm_display_info *info = &connector->display_info;
Mario Kleinerd0c94692014-03-27 19:59:39 +01005066 unsigned int dc_bpc = 0;
5067
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005068 /* HDMI supports at least 8 bpc */
5069 info->bpc = 8;
5070
5071 if (cea_db_payload_len(hdmi) < 6)
5072 return;
5073
5074 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
5075 dc_bpc = 10;
5076 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
5077 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
5078 connector->name);
5079 }
5080
5081 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
5082 dc_bpc = 12;
5083 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
5084 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
5085 connector->name);
5086 }
5087
5088 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
5089 dc_bpc = 16;
5090 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
5091 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
5092 connector->name);
5093 }
5094
5095 if (dc_bpc == 0) {
5096 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
5097 connector->name);
5098 return;
5099 }
5100
5101 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
5102 connector->name, dc_bpc);
5103 info->bpc = dc_bpc;
5104
5105 /*
5106 * Deep color support mandates RGB444 support for all video
5107 * modes and forbids YCRCB422 support for all video modes per
5108 * HDMI 1.3 spec.
5109 */
5110 info->color_formats = DRM_COLOR_FORMAT_RGB444;
5111
5112 /* YCRCB444 is optional according to spec. */
5113 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
5114 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
5115 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
5116 connector->name);
5117 }
5118
5119 /*
5120 * Spec says that if any deep color mode is supported at all,
5121 * then deep color 36 bit must be supported.
5122 */
5123 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
5124 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
5125 connector->name);
5126 }
5127}
5128
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03005129static void
5130drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
5131{
5132 struct drm_display_info *info = &connector->display_info;
5133 u8 len = cea_db_payload_len(db);
5134
Laurent Pincharta92d0832020-02-26 13:24:23 +02005135 info->is_hdmi = true;
5136
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03005137 if (len >= 6)
5138 info->dvi_dual = db[6] & 1;
5139 if (len >= 7)
5140 info->max_tmds_clock = db[7] * 5000;
5141
5142 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
5143 "max TMDS clock %d kHz\n",
5144 info->dvi_dual,
5145 info->max_tmds_clock);
5146
5147 drm_parse_hdmi_deep_color_info(connector, db);
5148}
5149
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005150static void drm_parse_cea_ext(struct drm_connector *connector,
Keith Packard170178f2017-12-13 00:44:26 -08005151 const struct edid *edid)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005152{
5153 struct drm_display_info *info = &connector->display_info;
5154 const u8 *edid_ext;
5155 int i, start, end;
5156
Mario Kleinerd0c94692014-03-27 19:59:39 +01005157 edid_ext = drm_find_cea_extension(edid);
5158 if (!edid_ext)
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005159 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01005160
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005161 info->cea_rev = edid_ext[1];
Mario Kleinerd0c94692014-03-27 19:59:39 +01005162
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005163 /* The existence of a CEA block should imply RGB support */
5164 info->color_formats = DRM_COLOR_FORMAT_RGB444;
5165 if (edid_ext[3] & EDID_CEA_YCRCB444)
5166 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
5167 if (edid_ext[3] & EDID_CEA_YCRCB422)
5168 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Mario Kleinerd0c94692014-03-27 19:59:39 +01005169
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005170 if (cea_db_offsets(edid_ext, &start, &end))
5171 return;
Mario Kleinerd0c94692014-03-27 19:59:39 +01005172
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005173 for_each_cea_db(edid_ext, i, start, end) {
5174 const u8 *db = &edid_ext[i];
Mario Kleinerd0c94692014-03-27 19:59:39 +01005175
Ville Syrjälä23ebf8b2016-09-28 16:51:41 +03005176 if (cea_db_is_hdmi_vsdb(db))
5177 drm_parse_hdmi_vsdb_video(connector, db);
Shashank Sharmaafa1c762017-03-13 16:54:01 +05305178 if (cea_db_is_hdmi_forum_vsdb(db))
5179 drm_parse_hdmi_forum_vsdb(connector, db);
Shashank Sharma832d4f22017-07-14 16:03:46 +05305180 if (cea_db_is_y420cmdb(db))
5181 drm_parse_y420cmdb_bitmap(connector, db);
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005182 if (cea_db_is_vcdb(db))
5183 drm_parse_vcdb(connector, db);
Uma Shankare85959d2019-05-16 19:40:08 +05305184 if (cea_db_is_hdmi_hdr_metadata_block(db))
5185 drm_parse_hdr_metadata_block(connector, db);
Mario Kleinerd0c94692014-03-27 19:59:39 +01005186 }
Mario Kleinerd0c94692014-03-27 19:59:39 +01005187}
5188
Manasi Navarea1d11d12020-03-10 16:16:51 -07005189static
5190void get_monitor_range(struct detailed_timing *timing,
5191 void *info_monitor_range)
5192{
5193 struct drm_monitor_range_info *monitor_range = info_monitor_range;
5194 const struct detailed_non_pixel *data = &timing->data.other_data;
5195 const struct detailed_data_monitor_range *range = &data->data.range;
5196
5197 if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_MONITOR_RANGE))
5198 return;
5199
5200 /*
5201 * Check for flag range limits only. If flag == 1 then
5202 * no additional timing information provided.
5203 * Default GTF, GTF Secondary curve and CVT are not
5204 * supported
5205 */
5206 if (range->flags != DRM_EDID_RANGE_LIMITS_ONLY_FLAG)
5207 return;
5208
5209 monitor_range->min_vfreq = range->min_vfreq;
5210 monitor_range->max_vfreq = range->max_vfreq;
5211}
5212
5213static
5214void drm_get_monitor_range(struct drm_connector *connector,
5215 const struct edid *edid)
5216{
5217 struct drm_display_info *info = &connector->display_info;
5218
5219 if (!version_greater(edid, 1, 1))
5220 return;
5221
5222 drm_for_each_detailed_block((u8 *)edid, get_monitor_range,
5223 &info->monitor_range);
5224
5225 DRM_DEBUG_KMS("Supported Monitor Refresh rate range is %d Hz - %d Hz\n",
5226 info->monitor_range.min_vfreq,
5227 info->monitor_range.max_vfreq);
5228}
5229
Keith Packard170178f2017-12-13 00:44:26 -08005230/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
5231 * all of the values which would have been set from EDID
5232 */
5233void
5234drm_reset_display_info(struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07005235{
Ville Syrjälä18267502016-09-28 16:51:38 +03005236 struct drm_display_info *info = &connector->display_info;
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07005237
Keith Packard170178f2017-12-13 00:44:26 -08005238 info->width_mm = 0;
5239 info->height_mm = 0;
5240
5241 info->bpc = 0;
5242 info->color_formats = 0;
5243 info->cea_rev = 0;
5244 info->max_tmds_clock = 0;
5245 info->dvi_dual = false;
Laurent Pincharta92d0832020-02-26 13:24:23 +02005246 info->is_hdmi = false;
Keith Packard170178f2017-12-13 00:44:26 -08005247 info->has_hdmi_infoframe = false;
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005248 info->rgb_quant_range_selectable = false;
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03005249 memset(&info->hdmi, 0, sizeof(info->hdmi));
Keith Packard170178f2017-12-13 00:44:26 -08005250
5251 info->non_desktop = 0;
Manasi Navarea1d11d12020-03-10 16:16:51 -07005252 memset(&info->monitor_range, 0, sizeof(info->monitor_range));
Keith Packard170178f2017-12-13 00:44:26 -08005253}
Keith Packard170178f2017-12-13 00:44:26 -08005254
5255u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
5256{
5257 struct drm_display_info *info = &connector->display_info;
5258
5259 u32 quirks = edid_get_quirks(edid);
5260
Ville Syrjälä1f6b8ee2018-04-24 16:02:50 +03005261 drm_reset_display_info(connector);
5262
Jesse Barnes3b112282011-04-15 12:49:23 -07005263 info->width_mm = edid->width_cm * 10;
5264 info->height_mm = edid->height_cm * 10;
5265
Dave Airlie66660d42017-10-16 05:08:09 +01005266 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
5267
Manasi Navarea1d11d12020-03-10 16:16:51 -07005268 drm_get_monitor_range(connector, edid);
5269
Keith Packard170178f2017-12-13 00:44:26 -08005270 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
5271
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02005272 if (edid->revision < 3)
Keith Packard170178f2017-12-13 00:44:26 -08005273 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07005274
5275 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
Keith Packard170178f2017-12-13 00:44:26 -08005276 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07005277
Ville Syrjälä1cea1462016-09-28 16:51:39 +03005278 drm_parse_cea_ext(connector, edid);
Mario Kleinerd0c94692014-03-27 19:59:39 +01005279
Mario Kleiner210a0212016-07-06 12:05:48 +02005280 /*
5281 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
5282 *
5283 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
5284 * tells us to assume 8 bpc color depth if the EDID doesn't have
5285 * extensions which tell otherwise.
5286 */
Ville Syrjälä3bde4492019-05-29 14:02:04 +03005287 if (info->bpc == 0 && edid->revision == 3 &&
5288 edid->input & DRM_EDID_DIGITAL_DFP_1_X) {
Mario Kleiner210a0212016-07-06 12:05:48 +02005289 info->bpc = 8;
5290 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
5291 connector->name, info->bpc);
5292 }
5293
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02005294 /* Only defined for 1.4 with digital displays */
5295 if (edid->revision < 4)
Keith Packard170178f2017-12-13 00:44:26 -08005296 return quirks;
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02005297
Jesse Barnes3b112282011-04-15 12:49:23 -07005298 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
5299 case DRM_EDID_DIGITAL_DEPTH_6:
5300 info->bpc = 6;
5301 break;
5302 case DRM_EDID_DIGITAL_DEPTH_8:
5303 info->bpc = 8;
5304 break;
5305 case DRM_EDID_DIGITAL_DEPTH_10:
5306 info->bpc = 10;
5307 break;
5308 case DRM_EDID_DIGITAL_DEPTH_12:
5309 info->bpc = 12;
5310 break;
5311 case DRM_EDID_DIGITAL_DEPTH_14:
5312 info->bpc = 14;
5313 break;
5314 case DRM_EDID_DIGITAL_DEPTH_16:
5315 info->bpc = 16;
5316 break;
5317 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
5318 default:
5319 info->bpc = 0;
5320 break;
5321 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07005322
Mario Kleinerd0c94692014-03-27 19:59:39 +01005323 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03005324 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01005325
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02005326 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02005327 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
5328 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
5329 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
5330 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Keith Packard170178f2017-12-13 00:44:26 -08005331 return quirks;
Jesse Barnes3b112282011-04-15 12:49:23 -07005332}
5333
Dave Airliea39ed682016-05-02 08:35:05 +10005334static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
5335 struct displayid_detailed_timings_1 *timings)
5336{
5337 struct drm_display_mode *mode;
5338 unsigned pixel_clock = (timings->pixel_clock[0] |
5339 (timings->pixel_clock[1] << 8) |
Ville Syrjälä6292b8e2020-04-23 18:17:43 +03005340 (timings->pixel_clock[2] << 16)) + 1;
Dave Airliea39ed682016-05-02 08:35:05 +10005341 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
5342 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
5343 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
5344 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
5345 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
5346 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
5347 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
5348 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
5349 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
5350 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
Suraj Upadhyay948de8422020-07-02 18:53:32 +05305351
Dave Airliea39ed682016-05-02 08:35:05 +10005352 mode = drm_mode_create(dev);
5353 if (!mode)
5354 return NULL;
5355
5356 mode->clock = pixel_clock * 10;
5357 mode->hdisplay = hactive;
5358 mode->hsync_start = mode->hdisplay + hsync;
5359 mode->hsync_end = mode->hsync_start + hsync_width;
5360 mode->htotal = mode->hdisplay + hblank;
5361
5362 mode->vdisplay = vactive;
5363 mode->vsync_start = mode->vdisplay + vsync;
5364 mode->vsync_end = mode->vsync_start + vsync_width;
5365 mode->vtotal = mode->vdisplay + vblank;
5366
5367 mode->flags = 0;
5368 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
5369 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
5370 mode->type = DRM_MODE_TYPE_DRIVER;
5371
5372 if (timings->flags & 0x80)
5373 mode->type |= DRM_MODE_TYPE_PREFERRED;
Dave Airliea39ed682016-05-02 08:35:05 +10005374 drm_mode_set_name(mode);
5375
5376 return mode;
5377}
5378
5379static int add_displayid_detailed_1_modes(struct drm_connector *connector,
Jani Nikula43d16d82021-03-29 16:37:15 +03005380 const struct displayid_block *block)
Dave Airliea39ed682016-05-02 08:35:05 +10005381{
5382 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
5383 int i;
5384 int num_timings;
5385 struct drm_display_mode *newmode;
5386 int num_modes = 0;
5387 /* blocks must be multiple of 20 bytes length */
5388 if (block->num_bytes % 20)
5389 return 0;
5390
5391 num_timings = block->num_bytes / 20;
5392 for (i = 0; i < num_timings; i++) {
5393 struct displayid_detailed_timings_1 *timings = &det->timings[i];
5394
5395 newmode = drm_mode_displayid_detailed(connector->dev, timings);
5396 if (!newmode)
5397 continue;
5398
5399 drm_mode_probed_add(connector, newmode);
5400 num_modes++;
5401 }
5402 return num_modes;
5403}
5404
5405static int add_displayid_detailed_modes(struct drm_connector *connector,
5406 struct edid *edid)
5407{
Jani Nikula43d16d82021-03-29 16:37:15 +03005408 const struct displayid_block *block;
Jani Nikula5ef88dc2021-03-29 16:37:18 +03005409 struct displayid_iter iter;
Dave Airliea39ed682016-05-02 08:35:05 +10005410 int num_modes = 0;
5411
Jani Nikula5ef88dc2021-03-29 16:37:18 +03005412 displayid_iter_edid_begin(edid, &iter);
5413 displayid_iter_for_each(block, &iter) {
5414 if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING)
5415 num_modes += add_displayid_detailed_1_modes(connector, block);
Dave Airliea39ed682016-05-02 08:35:05 +10005416 }
Jani Nikula5ef88dc2021-03-29 16:37:18 +03005417 displayid_iter_end(&iter);
Ville Syrjälä7f261af2020-05-27 16:03:09 +03005418
Dave Airliea39ed682016-05-02 08:35:05 +10005419 return num_modes;
5420}
5421
Jesse Barnes3b112282011-04-15 12:49:23 -07005422/**
Dave Airlief453ba02008-11-07 14:05:41 -08005423 * drm_add_edid_modes - add modes from EDID data, if available
5424 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005425 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08005426 *
Daniel Vetterb3c6c8b2016-08-12 22:48:55 +02005427 * Add the specified modes to the connector's mode list. Also fills out the
Jani Nikulac945b8c2017-11-01 16:21:01 +02005428 * &drm_display_info structure and ELD in @connector with any information which
5429 * can be derived from the edid.
Dave Airlief453ba02008-11-07 14:05:41 -08005430 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005431 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08005432 */
5433int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
5434{
5435 int num_modes = 0;
5436 u32 quirks;
5437
5438 if (edid == NULL) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02005439 clear_eld(connector);
Dave Airlief453ba02008-11-07 14:05:41 -08005440 return 0;
5441 }
Alex Deucher3c537882010-02-05 04:21:19 -05005442 if (!drm_edid_is_valid(edid)) {
Jani Nikulac945b8c2017-11-01 16:21:01 +02005443 clear_eld(connector);
Suraj Upadhyay6d45fff2020-07-18 20:39:55 +05305444 drm_warn(connector->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03005445 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08005446 return 0;
5447 }
5448
Jani Nikulac945b8c2017-11-01 16:21:01 +02005449 drm_edid_to_eld(connector, edid);
5450
Adam Jacksonc867df72010-03-29 21:43:21 +00005451 /*
Shashank Sharma0f0f8702017-07-13 21:03:09 +05305452 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
5453 * To avoid multiple parsing of same block, lets parse that map
5454 * from sink info, before parsing CEA modes.
5455 */
Keith Packard170178f2017-12-13 00:44:26 -08005456 quirks = drm_add_display_info(connector, edid);
Shashank Sharma0f0f8702017-07-13 21:03:09 +05305457
5458 /*
Adam Jacksonc867df72010-03-29 21:43:21 +00005459 * EDID spec says modes should be preferred in this order:
5460 * - preferred detailed mode
5461 * - other detailed modes from base block
5462 * - detailed modes from extension blocks
5463 * - CVT 3-byte code modes
5464 * - standard timing codes
5465 * - established timing codes
5466 * - modes inferred from GTF or CVT range information
5467 *
Adam Jackson13931572010-08-03 14:38:19 -04005468 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00005469 *
5470 * XXX order for additional mode types in extension blocks?
5471 */
Adam Jackson13931572010-08-03 14:38:19 -04005472 num_modes += add_detailed_modes(connector, edid, quirks);
5473 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00005474 num_modes += add_standard_modes(connector, edid);
5475 num_modes += add_established_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00005476 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03005477 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airliea39ed682016-05-02 08:35:05 +10005478 num_modes += add_displayid_detailed_modes(connector, edid);
Ville Syrjälä4d53dc02015-05-08 17:45:07 +03005479 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
5480 num_modes += add_inferred_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08005481
5482 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
5483 edid_fixup_preferred(connector, quirks);
5484
Mario Kleinere10aec62016-07-06 12:05:44 +02005485 if (quirks & EDID_QUIRK_FORCE_6BPC)
5486 connector->display_info.bpc = 6;
5487
Rafał Miłecki49d45a312013-12-07 13:22:42 +01005488 if (quirks & EDID_QUIRK_FORCE_8BPC)
5489 connector->display_info.bpc = 8;
5490
Mario Kleinere345da82017-04-21 17:05:08 +02005491 if (quirks & EDID_QUIRK_FORCE_10BPC)
5492 connector->display_info.bpc = 10;
5493
Mario Kleinerbc5b9642014-05-23 21:40:55 +02005494 if (quirks & EDID_QUIRK_FORCE_12BPC)
5495 connector->display_info.bpc = 12;
5496
Dave Airlief453ba02008-11-07 14:05:41 -08005497 return num_modes;
5498}
5499EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005500
5501/**
5502 * drm_add_modes_noedid - add modes for the connectors without EDID
5503 * @connector: connector we're probing
5504 * @hdisplay: the horizontal display limit
5505 * @vdisplay: the vertical display limit
5506 *
5507 * Add the specified modes to the connector's mode list. Only when the
5508 * hdisplay/vdisplay is not beyond the given limit, it will be added.
5509 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005510 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005511 */
5512int drm_add_modes_noedid(struct drm_connector *connector,
5513 int hdisplay, int vdisplay)
5514{
5515 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00005516 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005517 struct drm_device *dev = connector->dev;
5518
Daniel Vetterfbb40b22015-08-10 11:55:37 +02005519 count = ARRAY_SIZE(drm_dmt_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005520 if (hdisplay < 0)
5521 hdisplay = 0;
5522 if (vdisplay < 0)
5523 vdisplay = 0;
5524
5525 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00005526 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Suraj Upadhyay948de8422020-07-02 18:53:32 +05305527
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005528 if (hdisplay && vdisplay) {
5529 /*
5530 * Only when two are valid, they will be used to check
5531 * whether the mode should be added to the mode list of
5532 * the connector.
5533 */
5534 if (ptr->hdisplay > hdisplay ||
5535 ptr->vdisplay > vdisplay)
5536 continue;
5537 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05005538 if (drm_mode_vrefresh(ptr) > 61)
5539 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08005540 mode = drm_mode_duplicate(dev, ptr);
5541 if (mode) {
5542 drm_mode_probed_add(connector, mode);
5543 num_modes++;
5544 }
5545 }
5546 return num_modes;
5547}
5548EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01005549
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005550/**
5551 * drm_set_preferred_mode - Sets the preferred mode of a connector
5552 * @connector: connector whose mode list should be processed
5553 * @hpref: horizontal resolution of preferred mode
5554 * @vpref: vertical resolution of preferred mode
5555 *
5556 * Marks a mode as preferred if it matches the resolution specified by @hpref
5557 * and @vpref.
5558 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02005559void drm_set_preferred_mode(struct drm_connector *connector,
5560 int hpref, int vpref)
5561{
5562 struct drm_display_mode *mode;
5563
5564 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005565 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01005566 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02005567 mode->type |= DRM_MODE_TYPE_PREFERRED;
5568 }
5569}
5570EXPORT_SYMBOL(drm_set_preferred_mode);
5571
Laurent Pinchart192a3aa2020-05-26 04:14:47 +03005572static bool is_hdmi2_sink(const struct drm_connector *connector)
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005573{
5574 /*
5575 * FIXME: sil-sii8620 doesn't have a connector around when
5576 * we need one, so we have to be prepared for a NULL connector.
5577 */
5578 if (!connector)
5579 return true;
5580
5581 return connector->display_info.hdmi.scdc.supported ||
5582 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCRCB420;
5583}
5584
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305585static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
5586{
5587 return sink_eotf & BIT(output_eotf);
5588}
5589
5590/**
5591 * drm_hdmi_infoframe_set_hdr_metadata() - fill an HDMI DRM infoframe with
5592 * HDR metadata from userspace
5593 * @frame: HDMI DRM infoframe
Sean Paul6ac98822019-05-23 09:54:58 -04005594 * @conn_state: Connector state containing HDR metadata
Uma Shankar2cdbfd62019-05-16 19:40:09 +05305595 *
5596 * Return: 0 on success or a negative error code on failure.
5597 */
5598int
5599drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
5600 const struct drm_connector_state *conn_state)
5601{
5602 struct drm_connector *connector;
5603 struct hdr_output_metadata *hdr_metadata;
5604 int err;
5605
5606 if (!frame || !conn_state)
5607 return -EINVAL;
5608
5609 connector = conn_state->connector;
5610
5611 if (!conn_state->hdr_output_metadata)
5612 return -EINVAL;
5613
5614 hdr_metadata = conn_state->hdr_output_metadata->data;
5615
5616 if (!hdr_metadata || !connector)
5617 return -EINVAL;
5618
5619 /* Sink EOTF is Bit map while infoframe is absolute values */
5620 if (!is_eotf_supported(hdr_metadata->hdmi_metadata_type1.eotf,
5621 connector->hdr_sink_metadata.hdmi_type1.eotf)) {
5622 DRM_DEBUG_KMS("EOTF Not Supported\n");
5623 return -EINVAL;
5624 }
5625
5626 err = hdmi_drm_infoframe_init(frame);
5627 if (err < 0)
5628 return err;
5629
5630 frame->eotf = hdr_metadata->hdmi_metadata_type1.eotf;
5631 frame->metadata_type = hdr_metadata->hdmi_metadata_type1.metadata_type;
5632
5633 BUILD_BUG_ON(sizeof(frame->display_primaries) !=
5634 sizeof(hdr_metadata->hdmi_metadata_type1.display_primaries));
5635 BUILD_BUG_ON(sizeof(frame->white_point) !=
5636 sizeof(hdr_metadata->hdmi_metadata_type1.white_point));
5637
5638 memcpy(&frame->display_primaries,
5639 &hdr_metadata->hdmi_metadata_type1.display_primaries,
5640 sizeof(frame->display_primaries));
5641
5642 memcpy(&frame->white_point,
5643 &hdr_metadata->hdmi_metadata_type1.white_point,
5644 sizeof(frame->white_point));
5645
5646 frame->max_display_mastering_luminance =
5647 hdr_metadata->hdmi_metadata_type1.max_display_mastering_luminance;
5648 frame->min_display_mastering_luminance =
5649 hdr_metadata->hdmi_metadata_type1.min_display_mastering_luminance;
5650 frame->max_fall = hdr_metadata->hdmi_metadata_type1.max_fall;
5651 frame->max_cll = hdr_metadata->hdmi_metadata_type1.max_cll;
5652
5653 return 0;
5654}
5655EXPORT_SYMBOL(drm_hdmi_infoframe_set_hdr_metadata);
5656
Laurent Pinchart192a3aa2020-05-26 04:14:47 +03005657static u8 drm_mode_hdmi_vic(const struct drm_connector *connector,
Ville Syrjälä949561e2019-10-04 17:19:13 +03005658 const struct drm_display_mode *mode)
5659{
5660 bool has_hdmi_infoframe = connector ?
5661 connector->display_info.has_hdmi_infoframe : false;
5662
5663 if (!has_hdmi_infoframe)
5664 return 0;
5665
5666 /* No HDMI VIC when signalling 3D video format */
5667 if (mode->flags & DRM_MODE_FLAG_3D_MASK)
5668 return 0;
5669
5670 return drm_match_hdmi_mode(mode);
5671}
5672
Laurent Pinchart192a3aa2020-05-26 04:14:47 +03005673static u8 drm_mode_cea_vic(const struct drm_connector *connector,
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005674 const struct drm_display_mode *mode)
5675{
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005676 u8 vic;
5677
5678 /*
5679 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
5680 * we should send its VIC in vendor infoframes, else send the
5681 * VIC in AVI infoframes. Lets check if this mode is present in
5682 * HDMI 1.4b 4K modes
5683 */
Ville Syrjälä949561e2019-10-04 17:19:13 +03005684 if (drm_mode_hdmi_vic(connector, mode))
Ville Syrjäläcfd6f8c32019-10-04 17:19:12 +03005685 return 0;
5686
5687 vic = drm_match_cea_mode(mode);
5688
5689 /*
5690 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
5691 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
5692 * have to make sure we dont break HDMI 1.4 sinks.
5693 */
5694 if (!is_hdmi2_sink(connector) && vic > 64)
5695 return 0;
5696
5697 return vic;
5698}
5699
Thierry Reding10a85122012-11-21 15:31:35 +01005700/**
5701 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
5702 * data from a DRM display mode
5703 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005704 * @connector: the connector
Thierry Reding10a85122012-11-21 15:31:35 +01005705 * @mode: DRM display mode
5706 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005707 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01005708 */
5709int
5710drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
Laurent Pinchart192a3aa2020-05-26 04:14:47 +03005711 const struct drm_connector *connector,
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005712 const struct drm_display_mode *mode)
Thierry Reding10a85122012-11-21 15:31:35 +01005713{
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305714 enum hdmi_picture_aspect picture_aspect;
Wayne Lind2b43472019-11-18 18:18:31 +08005715 u8 vic, hdmi_vic;
Thierry Reding10a85122012-11-21 15:31:35 +01005716
5717 if (!frame || !mode)
5718 return -EINVAL;
5719
Laurent Pinchart5ee0caf2020-02-26 13:24:21 +02005720 hdmi_avi_infoframe_init(frame);
Thierry Reding10a85122012-11-21 15:31:35 +01005721
Damien Lespiaubf02db92013-08-06 20:32:22 +01005722 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
5723 frame->pixel_repeat = 1;
5724
Wayne Lind2b43472019-11-18 18:18:31 +08005725 vic = drm_mode_cea_vic(connector, mode);
5726 hdmi_vic = drm_mode_hdmi_vic(connector, mode);
Shashank Sharma0c1f5282017-07-13 21:03:07 +05305727
Thierry Reding10a85122012-11-21 15:31:35 +01005728 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305729
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305730 /*
Stanislav Lisovskiy50525c32018-05-15 16:59:27 +03005731 * As some drivers don't support atomic, we can't use connector state.
5732 * So just initialize the frame with default values, just the same way
5733 * as it's done with other properties here.
5734 */
5735 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
5736 frame->itc = 0;
5737
5738 /*
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305739 * Populate picture aspect ratio from either
Wayne Lind2b43472019-11-18 18:18:31 +08005740 * user input (if specified) or from the CEA/HDMI mode lists.
Vandana Kannan69ab6d32014-06-05 14:45:29 +05305741 */
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305742 picture_aspect = mode->picture_aspect_ratio;
Wayne Lind2b43472019-11-18 18:18:31 +08005743 if (picture_aspect == HDMI_PICTURE_ASPECT_NONE) {
5744 if (vic)
5745 picture_aspect = drm_get_cea_aspect_ratio(vic);
5746 else if (hdmi_vic)
5747 picture_aspect = drm_get_hdmi_aspect_ratio(hdmi_vic);
5748 }
Vandana Kannan0967e6a2014-04-01 16:26:59 +05305749
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305750 /*
5751 * The infoframe can't convey anything but none, 4:3
5752 * and 16:9, so if the user has asked for anything else
5753 * we can only satisfy it by specifying the right VIC.
5754 */
5755 if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
Wayne Lind2b43472019-11-18 18:18:31 +08005756 if (vic) {
5757 if (picture_aspect != drm_get_cea_aspect_ratio(vic))
5758 return -EINVAL;
5759 } else if (hdmi_vic) {
5760 if (picture_aspect != drm_get_hdmi_aspect_ratio(hdmi_vic))
5761 return -EINVAL;
5762 } else {
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305763 return -EINVAL;
Wayne Lind2b43472019-11-18 18:18:31 +08005764 }
5765
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305766 picture_aspect = HDMI_PICTURE_ASPECT_NONE;
5767 }
5768
Wayne Lind2b43472019-11-18 18:18:31 +08005769 frame->video_code = vic;
Ville Syrjäläa9c266c2018-05-08 16:39:39 +05305770 frame->picture_aspect = picture_aspect;
Thierry Reding10a85122012-11-21 15:31:35 +01005771 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d018052014-02-27 09:19:30 -06005772 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01005773
5774 return 0;
5775}
5776EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005777
Uma Shankar0d68b882019-02-19 22:43:00 +05305778/* HDMI Colorspace Spec Definitions */
5779#define FULL_COLORIMETRY_MASK 0x1FF
5780#define NORMAL_COLORIMETRY_MASK 0x3
5781#define EXTENDED_COLORIMETRY_MASK 0x7
5782#define EXTENDED_ACE_COLORIMETRY_MASK 0xF
5783
5784#define C(x) ((x) << 0)
5785#define EC(x) ((x) << 2)
5786#define ACE(x) ((x) << 5)
5787
5788#define HDMI_COLORIMETRY_NO_DATA 0x0
5789#define HDMI_COLORIMETRY_SMPTE_170M_YCC (C(1) | EC(0) | ACE(0))
5790#define HDMI_COLORIMETRY_BT709_YCC (C(2) | EC(0) | ACE(0))
5791#define HDMI_COLORIMETRY_XVYCC_601 (C(3) | EC(0) | ACE(0))
5792#define HDMI_COLORIMETRY_XVYCC_709 (C(3) | EC(1) | ACE(0))
5793#define HDMI_COLORIMETRY_SYCC_601 (C(3) | EC(2) | ACE(0))
5794#define HDMI_COLORIMETRY_OPYCC_601 (C(3) | EC(3) | ACE(0))
5795#define HDMI_COLORIMETRY_OPRGB (C(3) | EC(4) | ACE(0))
5796#define HDMI_COLORIMETRY_BT2020_CYCC (C(3) | EC(5) | ACE(0))
5797#define HDMI_COLORIMETRY_BT2020_RGB (C(3) | EC(6) | ACE(0))
5798#define HDMI_COLORIMETRY_BT2020_YCC (C(3) | EC(6) | ACE(0))
5799#define HDMI_COLORIMETRY_DCI_P3_RGB_D65 (C(3) | EC(7) | ACE(0))
5800#define HDMI_COLORIMETRY_DCI_P3_RGB_THEATER (C(3) | EC(7) | ACE(1))
5801
5802static const u32 hdmi_colorimetry_val[] = {
5803 [DRM_MODE_COLORIMETRY_NO_DATA] = HDMI_COLORIMETRY_NO_DATA,
5804 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = HDMI_COLORIMETRY_SMPTE_170M_YCC,
5805 [DRM_MODE_COLORIMETRY_BT709_YCC] = HDMI_COLORIMETRY_BT709_YCC,
5806 [DRM_MODE_COLORIMETRY_XVYCC_601] = HDMI_COLORIMETRY_XVYCC_601,
5807 [DRM_MODE_COLORIMETRY_XVYCC_709] = HDMI_COLORIMETRY_XVYCC_709,
5808 [DRM_MODE_COLORIMETRY_SYCC_601] = HDMI_COLORIMETRY_SYCC_601,
5809 [DRM_MODE_COLORIMETRY_OPYCC_601] = HDMI_COLORIMETRY_OPYCC_601,
5810 [DRM_MODE_COLORIMETRY_OPRGB] = HDMI_COLORIMETRY_OPRGB,
5811 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = HDMI_COLORIMETRY_BT2020_CYCC,
5812 [DRM_MODE_COLORIMETRY_BT2020_RGB] = HDMI_COLORIMETRY_BT2020_RGB,
5813 [DRM_MODE_COLORIMETRY_BT2020_YCC] = HDMI_COLORIMETRY_BT2020_YCC,
5814};
5815
5816#undef C
5817#undef EC
5818#undef ACE
5819
5820/**
5821 * drm_hdmi_avi_infoframe_colorspace() - fill the HDMI AVI infoframe
5822 * colorspace information
5823 * @frame: HDMI AVI infoframe
5824 * @conn_state: connector state
5825 */
5826void
5827drm_hdmi_avi_infoframe_colorspace(struct hdmi_avi_infoframe *frame,
5828 const struct drm_connector_state *conn_state)
5829{
5830 u32 colorimetry_val;
5831 u32 colorimetry_index = conn_state->colorspace & FULL_COLORIMETRY_MASK;
5832
5833 if (colorimetry_index >= ARRAY_SIZE(hdmi_colorimetry_val))
5834 colorimetry_val = HDMI_COLORIMETRY_NO_DATA;
5835 else
5836 colorimetry_val = hdmi_colorimetry_val[colorimetry_index];
5837
5838 frame->colorimetry = colorimetry_val & NORMAL_COLORIMETRY_MASK;
5839 /*
5840 * ToDo: Extend it for ACE formats as well. Modify the infoframe
5841 * structure and extend it in drivers/video/hdmi
5842 */
5843 frame->extended_colorimetry = (colorimetry_val >> 2) &
5844 EXTENDED_COLORIMETRY_MASK;
5845}
5846EXPORT_SYMBOL(drm_hdmi_avi_infoframe_colorspace);
5847
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005848/**
5849 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
5850 * quantization range information
5851 * @frame: HDMI AVI infoframe
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005852 * @connector: the connector
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005853 * @mode: DRM display mode
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005854 * @rgb_quant_range: RGB quantization range (Q)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005855 */
5856void
5857drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Laurent Pinchart192a3aa2020-05-26 04:14:47 +03005858 const struct drm_connector *connector,
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005859 const struct drm_display_mode *mode,
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005860 enum hdmi_quantization_range rgb_quant_range)
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005861{
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005862 const struct drm_display_info *info = &connector->display_info;
5863
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005864 /*
5865 * CEA-861:
5866 * "A Source shall not send a non-zero Q value that does not correspond
5867 * to the default RGB Quantization Range for the transmitted Picture
5868 * unless the Sink indicates support for the Q bit in a Video
5869 * Capabilities Data Block."
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005870 *
5871 * HDMI 2.0 recommends sending non-zero Q when it does match the
5872 * default RGB quantization range for the mode, even when QS=0.
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005873 */
Ville Syrjälä1581b2d2019-01-08 19:28:28 +02005874 if (info->rgb_quant_range_selectable ||
Ville Syrjälä779c4c22017-01-11 14:57:24 +02005875 rgb_quant_range == drm_default_rgb_quant_range(mode))
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005876 frame->quantization_range = rgb_quant_range;
5877 else
5878 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005879
5880 /*
5881 * CEA-861-F:
5882 * "When transmitting any RGB colorimetry, the Source should set the
5883 * YQ-field to match the RGB Quantization Range being transmitted
5884 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
5885 * set YQ=1) and the Sink shall ignore the YQ-field."
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005886 *
5887 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
5888 * by non-zero YQ when receiving RGB. There doesn't seem to be any
5889 * good way to tell which version of CEA-861 the sink supports, so
5890 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
5891 * on on CEA-861-F.
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005892 */
Ville Syrjälä13d0add2019-01-08 19:28:25 +02005893 if (!is_hdmi2_sink(connector) ||
Ville Syrjälä9271c0c2017-11-08 17:25:04 +02005894 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
Ville Syrjäläfcc8a222017-01-11 14:57:25 +02005895 frame->ycc_quantization_range =
5896 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
5897 else
5898 frame->ycc_quantization_range =
5899 HDMI_YCC_QUANTIZATION_RANGE_FULL;
Ville Syrjäläa2ce26f2017-01-11 14:57:23 +02005900}
5901EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
5902
Ville Syrjälä076d9a52019-10-08 19:48:13 +03005903/**
5904 * drm_hdmi_avi_infoframe_bars() - fill the HDMI AVI infoframe
5905 * bar information
5906 * @frame: HDMI AVI infoframe
5907 * @conn_state: connector state
5908 */
5909void
5910drm_hdmi_avi_infoframe_bars(struct hdmi_avi_infoframe *frame,
5911 const struct drm_connector_state *conn_state)
5912{
5913 frame->right_bar = conn_state->tv.margins.right;
5914 frame->left_bar = conn_state->tv.margins.left;
5915 frame->top_bar = conn_state->tv.margins.top;
5916 frame->bottom_bar = conn_state->tv.margins.bottom;
5917}
5918EXPORT_SYMBOL(drm_hdmi_avi_infoframe_bars);
5919
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005920static enum hdmi_3d_structure
5921s3d_structure_from_display_mode(const struct drm_display_mode *mode)
5922{
5923 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
5924
5925 switch (layout) {
5926 case DRM_MODE_FLAG_3D_FRAME_PACKING:
5927 return HDMI_3D_STRUCTURE_FRAME_PACKING;
5928 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
5929 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
5930 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
5931 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
5932 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
5933 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
5934 case DRM_MODE_FLAG_3D_L_DEPTH:
5935 return HDMI_3D_STRUCTURE_L_DEPTH;
5936 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
5937 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
5938 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
5939 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
5940 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
5941 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
5942 default:
5943 return HDMI_3D_STRUCTURE_INVALID;
5944 }
5945}
5946
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005947/**
5948 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
5949 * data from a DRM display mode
5950 * @frame: HDMI vendor infoframe
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005951 * @connector: the connector
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005952 * @mode: DRM display mode
5953 *
5954 * Note that there's is a need to send HDMI vendor infoframes only when using a
5955 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
5956 * function will return -EINVAL, error that can be safely ignored.
5957 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02005958 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005959 */
5960int
5961drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
Laurent Pinchart192a3aa2020-05-26 04:14:47 +03005962 const struct drm_connector *connector,
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005963 const struct drm_display_mode *mode)
5964{
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005965 /*
5966 * FIXME: sil-sii8620 doesn't have a connector around when
5967 * we need one, so we have to be prepared for a NULL connector.
5968 */
5969 bool has_hdmi_infoframe = connector ?
5970 connector->display_info.has_hdmi_infoframe : false;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005971 int err;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005972
5973 if (!frame || !mode)
5974 return -EINVAL;
5975
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005976 if (!has_hdmi_infoframe)
5977 return -EINVAL;
5978
Ville Syrjälä949561e2019-10-04 17:19:13 +03005979 err = hdmi_vendor_infoframe_init(frame);
5980 if (err < 0)
5981 return err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01005982
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005983 /*
5984 * Even if it's not absolutely necessary to send the infoframe
5985 * (ie.vic==0 and s3d_struct==0) we will still send it if we
5986 * know that the sink can handle it. This is based on a
5987 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
Cai Huoqing0ae865e2021-07-30 21:27:29 +08005988 * have trouble realizing that they should switch from 3D to 2D
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005989 * mode if the source simply stops sending the infoframe when
5990 * it wants to switch from 3D to 2D.
5991 */
Ville Syrjälä949561e2019-10-04 17:19:13 +03005992 frame->vic = drm_mode_hdmi_vic(connector, mode);
Ville Syrjäläf1781e92017-11-13 19:04:19 +02005993 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01005994
5995 return 0;
5996}
5997EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
Dave Airlie40d9b042014-10-20 16:29:33 +10005998
Ville Syrjälä7f261af2020-05-27 16:03:09 +03005999static void drm_parse_tiled_block(struct drm_connector *connector,
6000 const struct displayid_block *block)
Dave Airlie5e546cd2016-05-03 15:31:12 +10006001{
Ville Syrjälä092c3672020-03-13 18:20:54 +02006002 const struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
Dave Airlie5e546cd2016-05-03 15:31:12 +10006003 u16 w, h;
6004 u8 tile_v_loc, tile_h_loc;
6005 u8 num_v_tile, num_h_tile;
6006 struct drm_tile_group *tg;
6007
6008 w = tile->tile_size[0] | tile->tile_size[1] << 8;
6009 h = tile->tile_size[2] | tile->tile_size[3] << 8;
6010
6011 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
6012 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
6013 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
6014 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
6015
6016 connector->has_tile = true;
6017 if (tile->tile_cap & 0x80)
6018 connector->tile_is_single_monitor = true;
6019
6020 connector->num_h_tile = num_h_tile + 1;
6021 connector->num_v_tile = num_v_tile + 1;
6022 connector->tile_h_loc = tile_h_loc;
6023 connector->tile_v_loc = tile_v_loc;
6024 connector->tile_h_size = w + 1;
6025 connector->tile_v_size = h + 1;
6026
6027 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
6028 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
6029 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
6030 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
6031 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
6032
6033 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
Dave Airlie5e546cd2016-05-03 15:31:12 +10006034 if (!tg)
Dave Airlie5e546cd2016-05-03 15:31:12 +10006035 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
Dave Airlie5e546cd2016-05-03 15:31:12 +10006036 if (!tg)
Ville Syrjälä7f261af2020-05-27 16:03:09 +03006037 return;
Dave Airlie5e546cd2016-05-03 15:31:12 +10006038
6039 if (connector->tile_group != tg) {
6040 /* if we haven't got a pointer,
6041 take the reference, drop ref to old tile group */
Ville Syrjälä392f9fc2020-05-27 16:03:10 +03006042 if (connector->tile_group)
Dave Airlie5e546cd2016-05-03 15:31:12 +10006043 drm_mode_put_tile_group(connector->dev, connector->tile_group);
Dave Airlie5e546cd2016-05-03 15:31:12 +10006044 connector->tile_group = tg;
Ville Syrjälä392f9fc2020-05-27 16:03:10 +03006045 } else {
Dave Airlie5e546cd2016-05-03 15:31:12 +10006046 /* if same tile group, then release the ref we just took. */
6047 drm_mode_put_tile_group(connector->dev, tg);
Ville Syrjälä392f9fc2020-05-27 16:03:10 +03006048 }
Dave Airlie5e546cd2016-05-03 15:31:12 +10006049}
6050
Ville Syrjälä092c3672020-03-13 18:20:54 +02006051void drm_update_tile_info(struct drm_connector *connector,
6052 const struct edid *edid)
Dave Airlie40d9b042014-10-20 16:29:33 +10006053{
Jani Nikulabfd4e192021-03-29 16:37:20 +03006054 const struct displayid_block *block;
6055 struct displayid_iter iter;
Ville Syrjälä36881182020-03-13 18:20:48 +02006056
Dave Airlie40d9b042014-10-20 16:29:33 +10006057 connector->has_tile = false;
Ville Syrjälä7f261af2020-05-27 16:03:09 +03006058
Jani Nikulabfd4e192021-03-29 16:37:20 +03006059 displayid_iter_edid_begin(edid, &iter);
6060 displayid_iter_for_each(block, &iter) {
6061 if (block->tag == DATA_BLOCK_TILED_DISPLAY)
6062 drm_parse_tiled_block(connector, block);
Dave Airlie40d9b042014-10-20 16:29:33 +10006063 }
Jani Nikulabfd4e192021-03-29 16:37:20 +03006064 displayid_iter_end(&iter);
Dave Airlie40d9b042014-10-20 16:29:33 +10006065
Ville Syrjälä7f261af2020-05-27 16:03:09 +03006066 if (!connector->has_tile && connector->tile_group) {
Dave Airlie40d9b042014-10-20 16:29:33 +10006067 drm_mode_put_tile_group(connector->dev, connector->tile_group);
6068 connector->tile_group = NULL;
6069 }
Dave Airlie40d9b042014-10-20 16:29:33 +10006070}