drm_edid.c revision 1.1.1.1.2.8 1 1.1.1.1.2.2 riastrad /*
2 1.1.1.1.2.2 riastrad * Copyright (c) 2006 Luc Verhaegen (quirks list)
3 1.1.1.1.2.2 riastrad * Copyright (c) 2007-2008 Intel Corporation
4 1.1.1.1.2.2 riastrad * Jesse Barnes <jesse.barnes (at) intel.com>
5 1.1.1.1.2.2 riastrad * Copyright 2010 Red Hat, Inc.
6 1.1.1.1.2.2 riastrad *
7 1.1.1.1.2.2 riastrad * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
8 1.1.1.1.2.2 riastrad * FB layer.
9 1.1.1.1.2.2 riastrad * Copyright (C) 2006 Dennis Munsie <dmunsie (at) cecropia.com>
10 1.1.1.1.2.2 riastrad *
11 1.1.1.1.2.2 riastrad * Permission is hereby granted, free of charge, to any person obtaining a
12 1.1.1.1.2.2 riastrad * copy of this software and associated documentation files (the "Software"),
13 1.1.1.1.2.2 riastrad * to deal in the Software without restriction, including without limitation
14 1.1.1.1.2.2 riastrad * the rights to use, copy, modify, merge, publish, distribute, sub license,
15 1.1.1.1.2.2 riastrad * and/or sell copies of the Software, and to permit persons to whom the
16 1.1.1.1.2.2 riastrad * Software is furnished to do so, subject to the following conditions:
17 1.1.1.1.2.2 riastrad *
18 1.1.1.1.2.2 riastrad * The above copyright notice and this permission notice (including the
19 1.1.1.1.2.2 riastrad * next paragraph) shall be included in all copies or substantial portions
20 1.1.1.1.2.2 riastrad * of the Software.
21 1.1.1.1.2.2 riastrad *
22 1.1.1.1.2.2 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 1.1.1.1.2.2 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 1.1.1.1.2.2 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
25 1.1.1.1.2.2 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 1.1.1.1.2.2 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 1.1.1.1.2.2 riastrad * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 1.1.1.1.2.2 riastrad * DEALINGS IN THE SOFTWARE.
29 1.1.1.1.2.2 riastrad */
30 1.1.1.1.2.2 riastrad #include <linux/kernel.h>
31 1.1.1.1.2.2 riastrad #include <linux/slab.h>
32 1.1.1.1.2.2 riastrad #include <linux/i2c.h>
33 1.1.1.1.2.2 riastrad #include <linux/module.h>
34 1.1.1.1.2.3 riastrad #include <linux/moduleparam.h>
35 1.1.1.1.2.3 riastrad #include <linux/export.h>
36 1.1.1.1.2.3 riastrad #include <linux/printk.h>
37 1.1.1.1.2.6 riastrad #include <linux/device.h>
38 1.1.1.1.2.3 riastrad #include <asm/byteorder.h>
39 1.1.1.1.2.2 riastrad #include <drm/drmP.h>
40 1.1.1.1.2.2 riastrad #include <drm/drm_edid.h>
41 1.1.1.1.2.2 riastrad #include "drm_edid_modes.h"
42 1.1.1.1.2.2 riastrad
43 1.1.1.1.2.2 riastrad #define version_greater(edid, maj, min) \
44 1.1.1.1.2.2 riastrad (((edid)->version > (maj)) || \
45 1.1.1.1.2.2 riastrad ((edid)->version == (maj) && (edid)->revision > (min)))
46 1.1.1.1.2.2 riastrad
47 1.1.1.1.2.2 riastrad #define EDID_EST_TIMINGS 16
48 1.1.1.1.2.2 riastrad #define EDID_STD_TIMINGS 8
49 1.1.1.1.2.2 riastrad #define EDID_DETAILED_TIMINGS 4
50 1.1.1.1.2.2 riastrad
51 1.1.1.1.2.2 riastrad /*
52 1.1.1.1.2.2 riastrad * EDID blocks out in the wild have a variety of bugs, try to collect
53 1.1.1.1.2.2 riastrad * them here (note that userspace may work around broken monitors first,
54 1.1.1.1.2.2 riastrad * but fixes should make their way here so that the kernel "just works"
55 1.1.1.1.2.2 riastrad * on as many displays as possible).
56 1.1.1.1.2.2 riastrad */
57 1.1.1.1.2.2 riastrad
58 1.1.1.1.2.2 riastrad /* First detailed mode wrong, use largest 60Hz mode */
59 1.1.1.1.2.2 riastrad #define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
60 1.1.1.1.2.2 riastrad /* Reported 135MHz pixel clock is too high, needs adjustment */
61 1.1.1.1.2.2 riastrad #define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
62 1.1.1.1.2.2 riastrad /* Prefer the largest mode at 75 Hz */
63 1.1.1.1.2.2 riastrad #define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
64 1.1.1.1.2.2 riastrad /* Detail timing is in cm not mm */
65 1.1.1.1.2.2 riastrad #define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
66 1.1.1.1.2.2 riastrad /* Detailed timing descriptors have bogus size values, so just take the
67 1.1.1.1.2.2 riastrad * maximum size and use that.
68 1.1.1.1.2.2 riastrad */
69 1.1.1.1.2.2 riastrad #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
70 1.1.1.1.2.2 riastrad /* Monitor forgot to set the first detailed is preferred bit. */
71 1.1.1.1.2.2 riastrad #define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
72 1.1.1.1.2.2 riastrad /* use +hsync +vsync for detailed mode */
73 1.1.1.1.2.2 riastrad #define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
74 1.1.1.1.2.2 riastrad /* Force reduced-blanking timings for detailed modes */
75 1.1.1.1.2.2 riastrad #define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
76 1.1.1.1.2.2 riastrad
77 1.1.1.1.2.2 riastrad struct detailed_mode_closure {
78 1.1.1.1.2.2 riastrad struct drm_connector *connector;
79 1.1.1.1.2.2 riastrad struct edid *edid;
80 1.1.1.1.2.2 riastrad bool preferred;
81 1.1.1.1.2.2 riastrad u32 quirks;
82 1.1.1.1.2.2 riastrad int modes;
83 1.1.1.1.2.2 riastrad };
84 1.1.1.1.2.2 riastrad
85 1.1.1.1.2.2 riastrad #define LEVEL_DMT 0
86 1.1.1.1.2.2 riastrad #define LEVEL_GTF 1
87 1.1.1.1.2.2 riastrad #define LEVEL_GTF2 2
88 1.1.1.1.2.2 riastrad #define LEVEL_CVT 3
89 1.1.1.1.2.2 riastrad
90 1.1.1.1.2.2 riastrad static struct edid_quirk {
91 1.1.1.1.2.2 riastrad char vendor[4];
92 1.1.1.1.2.2 riastrad int product_id;
93 1.1.1.1.2.2 riastrad u32 quirks;
94 1.1.1.1.2.2 riastrad } edid_quirk_list[] = {
95 1.1.1.1.2.2 riastrad /* ASUS VW222S */
96 1.1.1.1.2.2 riastrad { "ACI", 0x22a2, EDID_QUIRK_FORCE_REDUCED_BLANKING },
97 1.1.1.1.2.2 riastrad
98 1.1.1.1.2.2 riastrad /* Acer AL1706 */
99 1.1.1.1.2.2 riastrad { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
100 1.1.1.1.2.2 riastrad /* Acer F51 */
101 1.1.1.1.2.2 riastrad { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
102 1.1.1.1.2.2 riastrad /* Unknown Acer */
103 1.1.1.1.2.2 riastrad { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
104 1.1.1.1.2.2 riastrad
105 1.1.1.1.2.2 riastrad /* Belinea 10 15 55 */
106 1.1.1.1.2.2 riastrad { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
107 1.1.1.1.2.2 riastrad { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
108 1.1.1.1.2.2 riastrad
109 1.1.1.1.2.2 riastrad /* Envision Peripherals, Inc. EN-7100e */
110 1.1.1.1.2.2 riastrad { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
111 1.1.1.1.2.2 riastrad /* Envision EN2028 */
112 1.1.1.1.2.2 riastrad { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
113 1.1.1.1.2.2 riastrad
114 1.1.1.1.2.2 riastrad /* Funai Electronics PM36B */
115 1.1.1.1.2.2 riastrad { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
116 1.1.1.1.2.2 riastrad EDID_QUIRK_DETAILED_IN_CM },
117 1.1.1.1.2.2 riastrad
118 1.1.1.1.2.2 riastrad /* LG Philips LCD LP154W01-A5 */
119 1.1.1.1.2.2 riastrad { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
120 1.1.1.1.2.2 riastrad { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
121 1.1.1.1.2.2 riastrad
122 1.1.1.1.2.2 riastrad /* Philips 107p5 CRT */
123 1.1.1.1.2.2 riastrad { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
124 1.1.1.1.2.2 riastrad
125 1.1.1.1.2.2 riastrad /* Proview AY765C */
126 1.1.1.1.2.2 riastrad { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
127 1.1.1.1.2.2 riastrad
128 1.1.1.1.2.2 riastrad /* Samsung SyncMaster 205BW. Note: irony */
129 1.1.1.1.2.2 riastrad { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
130 1.1.1.1.2.2 riastrad /* Samsung SyncMaster 22[5-6]BW */
131 1.1.1.1.2.2 riastrad { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
132 1.1.1.1.2.2 riastrad { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
133 1.1.1.1.2.2 riastrad
134 1.1.1.1.2.2 riastrad /* ViewSonic VA2026w */
135 1.1.1.1.2.2 riastrad { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
136 1.1.1.1.2.2 riastrad };
137 1.1.1.1.2.2 riastrad
138 1.1.1.1.2.2 riastrad /*** DDC fetch and block validation ***/
139 1.1.1.1.2.2 riastrad
140 1.1.1.1.2.2 riastrad static const u8 edid_header[] = {
141 1.1.1.1.2.2 riastrad 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
142 1.1.1.1.2.2 riastrad };
143 1.1.1.1.2.2 riastrad
144 1.1.1.1.2.2 riastrad /*
145 1.1.1.1.2.2 riastrad * Sanity check the header of the base EDID block. Return 8 if the header
146 1.1.1.1.2.2 riastrad * is perfect, down to 0 if it's totally wrong.
147 1.1.1.1.2.2 riastrad */
148 1.1.1.1.2.2 riastrad int drm_edid_header_is_valid(const u8 *raw_edid)
149 1.1.1.1.2.2 riastrad {
150 1.1.1.1.2.2 riastrad int i, score = 0;
151 1.1.1.1.2.2 riastrad
152 1.1.1.1.2.2 riastrad for (i = 0; i < sizeof(edid_header); i++)
153 1.1.1.1.2.2 riastrad if (raw_edid[i] == edid_header[i])
154 1.1.1.1.2.2 riastrad score++;
155 1.1.1.1.2.2 riastrad
156 1.1.1.1.2.2 riastrad return score;
157 1.1.1.1.2.2 riastrad }
158 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_edid_header_is_valid);
159 1.1.1.1.2.2 riastrad
160 1.1.1.1.2.2 riastrad static int edid_fixup __read_mostly = 6;
161 1.1.1.1.2.2 riastrad module_param_named(edid_fixup, edid_fixup, int, 0400);
162 1.1.1.1.2.2 riastrad MODULE_PARM_DESC(edid_fixup,
163 1.1.1.1.2.2 riastrad "Minimum number of valid EDID header bytes (0-8, default 6)");
164 1.1.1.1.2.2 riastrad
165 1.1.1.1.2.2 riastrad /*
166 1.1.1.1.2.2 riastrad * Sanity check the EDID block (base or extension). Return 0 if the block
167 1.1.1.1.2.2 riastrad * doesn't check out, or 1 if it's valid.
168 1.1.1.1.2.2 riastrad */
169 1.1.1.1.2.2 riastrad bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid)
170 1.1.1.1.2.2 riastrad {
171 1.1.1.1.2.2 riastrad int i;
172 1.1.1.1.2.2 riastrad u8 csum = 0;
173 1.1.1.1.2.2 riastrad struct edid *edid = (struct edid *)raw_edid;
174 1.1.1.1.2.2 riastrad
175 1.1.1.1.2.2 riastrad if (edid_fixup > 8 || edid_fixup < 0)
176 1.1.1.1.2.2 riastrad edid_fixup = 6;
177 1.1.1.1.2.2 riastrad
178 1.1.1.1.2.2 riastrad if (block == 0) {
179 1.1.1.1.2.2 riastrad int score = drm_edid_header_is_valid(raw_edid);
180 1.1.1.1.2.2 riastrad if (score == 8) ;
181 1.1.1.1.2.2 riastrad else if (score >= edid_fixup) {
182 1.1.1.1.2.2 riastrad DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
183 1.1.1.1.2.2 riastrad memcpy(raw_edid, edid_header, sizeof(edid_header));
184 1.1.1.1.2.2 riastrad } else {
185 1.1.1.1.2.2 riastrad goto bad;
186 1.1.1.1.2.2 riastrad }
187 1.1.1.1.2.2 riastrad }
188 1.1.1.1.2.2 riastrad
189 1.1.1.1.2.2 riastrad for (i = 0; i < EDID_LENGTH; i++)
190 1.1.1.1.2.2 riastrad csum += raw_edid[i];
191 1.1.1.1.2.2 riastrad if (csum) {
192 1.1.1.1.2.2 riastrad if (print_bad_edid) {
193 1.1.1.1.2.2 riastrad DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum);
194 1.1.1.1.2.2 riastrad }
195 1.1.1.1.2.2 riastrad
196 1.1.1.1.2.2 riastrad /* allow CEA to slide through, switches mangle this */
197 1.1.1.1.2.2 riastrad if (raw_edid[0] != 0x02)
198 1.1.1.1.2.2 riastrad goto bad;
199 1.1.1.1.2.2 riastrad }
200 1.1.1.1.2.2 riastrad
201 1.1.1.1.2.2 riastrad /* per-block-type checks */
202 1.1.1.1.2.2 riastrad switch (raw_edid[0]) {
203 1.1.1.1.2.2 riastrad case 0: /* base */
204 1.1.1.1.2.2 riastrad if (edid->version != 1) {
205 1.1.1.1.2.2 riastrad DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version);
206 1.1.1.1.2.2 riastrad goto bad;
207 1.1.1.1.2.2 riastrad }
208 1.1.1.1.2.2 riastrad
209 1.1.1.1.2.2 riastrad if (edid->revision > 4)
210 1.1.1.1.2.2 riastrad DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
211 1.1.1.1.2.2 riastrad break;
212 1.1.1.1.2.2 riastrad
213 1.1.1.1.2.2 riastrad default:
214 1.1.1.1.2.2 riastrad break;
215 1.1.1.1.2.2 riastrad }
216 1.1.1.1.2.2 riastrad
217 1.1.1.1.2.2 riastrad return 1;
218 1.1.1.1.2.2 riastrad
219 1.1.1.1.2.2 riastrad bad:
220 1.1.1.1.2.2 riastrad if (raw_edid && print_bad_edid) {
221 1.1.1.1.2.2 riastrad printk(KERN_ERR "Raw EDID:\n");
222 1.1.1.1.2.4 riastrad #ifdef __NetBSD__
223 1.1.1.1.2.4 riastrad for (i = 0; i < EDID_LENGTH; i++) {
224 1.1.1.1.2.4 riastrad printf("%02x", raw_edid[i]);
225 1.1.1.1.2.4 riastrad if ((i % 16) == 15)
226 1.1.1.1.2.4 riastrad printf("\n");
227 1.1.1.1.2.4 riastrad else
228 1.1.1.1.2.4 riastrad printf(" ");
229 1.1.1.1.2.4 riastrad }
230 1.1.1.1.2.4 riastrad #else
231 1.1.1.1.2.2 riastrad print_hex_dump(KERN_ERR, " \t", DUMP_PREFIX_NONE, 16, 1,
232 1.1.1.1.2.2 riastrad raw_edid, EDID_LENGTH, false);
233 1.1.1.1.2.4 riastrad #endif
234 1.1.1.1.2.2 riastrad }
235 1.1.1.1.2.2 riastrad return 0;
236 1.1.1.1.2.2 riastrad }
237 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_edid_block_valid);
238 1.1.1.1.2.2 riastrad
239 1.1.1.1.2.2 riastrad /**
240 1.1.1.1.2.2 riastrad * drm_edid_is_valid - sanity check EDID data
241 1.1.1.1.2.2 riastrad * @edid: EDID data
242 1.1.1.1.2.2 riastrad *
243 1.1.1.1.2.2 riastrad * Sanity-check an entire EDID record (including extensions)
244 1.1.1.1.2.2 riastrad */
245 1.1.1.1.2.2 riastrad bool drm_edid_is_valid(struct edid *edid)
246 1.1.1.1.2.2 riastrad {
247 1.1.1.1.2.2 riastrad int i;
248 1.1.1.1.2.2 riastrad u8 *raw = (u8 *)edid;
249 1.1.1.1.2.2 riastrad
250 1.1.1.1.2.2 riastrad if (!edid)
251 1.1.1.1.2.2 riastrad return false;
252 1.1.1.1.2.2 riastrad
253 1.1.1.1.2.2 riastrad for (i = 0; i <= edid->extensions; i++)
254 1.1.1.1.2.2 riastrad if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true))
255 1.1.1.1.2.2 riastrad return false;
256 1.1.1.1.2.2 riastrad
257 1.1.1.1.2.2 riastrad return true;
258 1.1.1.1.2.2 riastrad }
259 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_edid_is_valid);
260 1.1.1.1.2.2 riastrad
261 1.1.1.1.2.5 riastrad #ifndef __NetBSD__ /* XXX i2c */
262 1.1.1.1.2.5 riastrad
263 1.1.1.1.2.2 riastrad #define DDC_SEGMENT_ADDR 0x30
264 1.1.1.1.2.2 riastrad /**
265 1.1.1.1.2.2 riastrad * Get EDID information via I2C.
266 1.1.1.1.2.2 riastrad *
267 1.1.1.1.2.2 riastrad * \param adapter : i2c device adaptor
268 1.1.1.1.2.2 riastrad * \param buf : EDID data buffer to be filled
269 1.1.1.1.2.2 riastrad * \param len : EDID data buffer length
270 1.1.1.1.2.2 riastrad * \return 0 on success or -1 on failure.
271 1.1.1.1.2.2 riastrad *
272 1.1.1.1.2.2 riastrad * Try to fetch EDID information by calling i2c driver function.
273 1.1.1.1.2.2 riastrad */
274 1.1.1.1.2.2 riastrad static int
275 1.1.1.1.2.2 riastrad drm_do_probe_ddc_edid(struct i2c_adapter *adapter, unsigned char *buf,
276 1.1.1.1.2.2 riastrad int block, int len)
277 1.1.1.1.2.2 riastrad {
278 1.1.1.1.2.2 riastrad unsigned char start = block * EDID_LENGTH;
279 1.1.1.1.2.2 riastrad unsigned char segment = block >> 1;
280 1.1.1.1.2.2 riastrad unsigned char xfers = segment ? 3 : 2;
281 1.1.1.1.2.2 riastrad int ret, retries = 5;
282 1.1.1.1.2.2 riastrad
283 1.1.1.1.2.2 riastrad /* The core i2c driver will automatically retry the transfer if the
284 1.1.1.1.2.2 riastrad * adapter reports EAGAIN. However, we find that bit-banging transfers
285 1.1.1.1.2.2 riastrad * are susceptible to errors under a heavily loaded machine and
286 1.1.1.1.2.2 riastrad * generate spurious NAKs and timeouts. Retrying the transfer
287 1.1.1.1.2.2 riastrad * of the individual block a few times seems to overcome this.
288 1.1.1.1.2.2 riastrad */
289 1.1.1.1.2.2 riastrad do {
290 1.1.1.1.2.2 riastrad struct i2c_msg msgs[] = {
291 1.1.1.1.2.2 riastrad {
292 1.1.1.1.2.2 riastrad .addr = DDC_SEGMENT_ADDR,
293 1.1.1.1.2.2 riastrad .flags = 0,
294 1.1.1.1.2.2 riastrad .len = 1,
295 1.1.1.1.2.2 riastrad .buf = &segment,
296 1.1.1.1.2.2 riastrad }, {
297 1.1.1.1.2.2 riastrad .addr = DDC_ADDR,
298 1.1.1.1.2.2 riastrad .flags = 0,
299 1.1.1.1.2.2 riastrad .len = 1,
300 1.1.1.1.2.2 riastrad .buf = &start,
301 1.1.1.1.2.2 riastrad }, {
302 1.1.1.1.2.2 riastrad .addr = DDC_ADDR,
303 1.1.1.1.2.2 riastrad .flags = I2C_M_RD,
304 1.1.1.1.2.2 riastrad .len = len,
305 1.1.1.1.2.2 riastrad .buf = buf,
306 1.1.1.1.2.2 riastrad }
307 1.1.1.1.2.2 riastrad };
308 1.1.1.1.2.2 riastrad
309 1.1.1.1.2.2 riastrad /*
310 1.1.1.1.2.2 riastrad * Avoid sending the segment addr to not upset non-compliant ddc
311 1.1.1.1.2.2 riastrad * monitors.
312 1.1.1.1.2.2 riastrad */
313 1.1.1.1.2.2 riastrad ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
314 1.1.1.1.2.2 riastrad
315 1.1.1.1.2.2 riastrad if (ret == -ENXIO) {
316 1.1.1.1.2.2 riastrad DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
317 1.1.1.1.2.2 riastrad adapter->name);
318 1.1.1.1.2.2 riastrad break;
319 1.1.1.1.2.2 riastrad }
320 1.1.1.1.2.2 riastrad } while (ret != xfers && --retries);
321 1.1.1.1.2.2 riastrad
322 1.1.1.1.2.2 riastrad return ret == xfers ? 0 : -1;
323 1.1.1.1.2.2 riastrad }
324 1.1.1.1.2.2 riastrad
325 1.1.1.1.2.2 riastrad static bool drm_edid_is_zero(u8 *in_edid, int length)
326 1.1.1.1.2.2 riastrad {
327 1.1.1.1.2.2 riastrad if (memchr_inv(in_edid, 0, length))
328 1.1.1.1.2.2 riastrad return false;
329 1.1.1.1.2.2 riastrad
330 1.1.1.1.2.2 riastrad return true;
331 1.1.1.1.2.2 riastrad }
332 1.1.1.1.2.2 riastrad
333 1.1.1.1.2.2 riastrad static u8 *
334 1.1.1.1.2.2 riastrad drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
335 1.1.1.1.2.2 riastrad {
336 1.1.1.1.2.2 riastrad int i, j = 0, valid_extensions = 0;
337 1.1.1.1.2.2 riastrad u8 *block, *new;
338 1.1.1.1.2.2 riastrad bool print_bad_edid = !connector->bad_edid_counter || (drm_debug & DRM_UT_KMS);
339 1.1.1.1.2.2 riastrad
340 1.1.1.1.2.2 riastrad if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
341 1.1.1.1.2.2 riastrad return NULL;
342 1.1.1.1.2.2 riastrad
343 1.1.1.1.2.2 riastrad /* base block fetch */
344 1.1.1.1.2.2 riastrad for (i = 0; i < 4; i++) {
345 1.1.1.1.2.2 riastrad if (drm_do_probe_ddc_edid(adapter, block, 0, EDID_LENGTH))
346 1.1.1.1.2.2 riastrad goto out;
347 1.1.1.1.2.2 riastrad if (drm_edid_block_valid(block, 0, print_bad_edid))
348 1.1.1.1.2.2 riastrad break;
349 1.1.1.1.2.2 riastrad if (i == 0 && drm_edid_is_zero(block, EDID_LENGTH)) {
350 1.1.1.1.2.2 riastrad connector->null_edid_counter++;
351 1.1.1.1.2.2 riastrad goto carp;
352 1.1.1.1.2.2 riastrad }
353 1.1.1.1.2.2 riastrad }
354 1.1.1.1.2.2 riastrad if (i == 4)
355 1.1.1.1.2.2 riastrad goto carp;
356 1.1.1.1.2.2 riastrad
357 1.1.1.1.2.2 riastrad /* if there's no extensions, we're done */
358 1.1.1.1.2.2 riastrad if (block[0x7e] == 0)
359 1.1.1.1.2.2 riastrad return block;
360 1.1.1.1.2.2 riastrad
361 1.1.1.1.2.2 riastrad new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL);
362 1.1.1.1.2.2 riastrad if (!new)
363 1.1.1.1.2.2 riastrad goto out;
364 1.1.1.1.2.2 riastrad block = new;
365 1.1.1.1.2.2 riastrad
366 1.1.1.1.2.2 riastrad for (j = 1; j <= block[0x7e]; j++) {
367 1.1.1.1.2.2 riastrad for (i = 0; i < 4; i++) {
368 1.1.1.1.2.2 riastrad if (drm_do_probe_ddc_edid(adapter,
369 1.1.1.1.2.2 riastrad block + (valid_extensions + 1) * EDID_LENGTH,
370 1.1.1.1.2.2 riastrad j, EDID_LENGTH))
371 1.1.1.1.2.2 riastrad goto out;
372 1.1.1.1.2.2 riastrad if (drm_edid_block_valid(block + (valid_extensions + 1) * EDID_LENGTH, j, print_bad_edid)) {
373 1.1.1.1.2.2 riastrad valid_extensions++;
374 1.1.1.1.2.2 riastrad break;
375 1.1.1.1.2.2 riastrad }
376 1.1.1.1.2.2 riastrad }
377 1.1.1.1.2.2 riastrad if (i == 4)
378 1.1.1.1.2.2 riastrad dev_warn(connector->dev->dev,
379 1.1.1.1.2.2 riastrad "%s: Ignoring invalid EDID block %d.\n",
380 1.1.1.1.2.2 riastrad drm_get_connector_name(connector), j);
381 1.1.1.1.2.2 riastrad }
382 1.1.1.1.2.2 riastrad
383 1.1.1.1.2.2 riastrad if (valid_extensions != block[0x7e]) {
384 1.1.1.1.2.2 riastrad block[EDID_LENGTH-1] += block[0x7e] - valid_extensions;
385 1.1.1.1.2.2 riastrad block[0x7e] = valid_extensions;
386 1.1.1.1.2.2 riastrad new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
387 1.1.1.1.2.2 riastrad if (!new)
388 1.1.1.1.2.2 riastrad goto out;
389 1.1.1.1.2.2 riastrad block = new;
390 1.1.1.1.2.2 riastrad }
391 1.1.1.1.2.2 riastrad
392 1.1.1.1.2.2 riastrad return block;
393 1.1.1.1.2.2 riastrad
394 1.1.1.1.2.2 riastrad carp:
395 1.1.1.1.2.2 riastrad if (print_bad_edid) {
396 1.1.1.1.2.2 riastrad dev_warn(connector->dev->dev, "%s: EDID block %d invalid.\n",
397 1.1.1.1.2.2 riastrad drm_get_connector_name(connector), j);
398 1.1.1.1.2.2 riastrad }
399 1.1.1.1.2.2 riastrad connector->bad_edid_counter++;
400 1.1.1.1.2.2 riastrad
401 1.1.1.1.2.2 riastrad out:
402 1.1.1.1.2.2 riastrad kfree(block);
403 1.1.1.1.2.2 riastrad return NULL;
404 1.1.1.1.2.2 riastrad }
405 1.1.1.1.2.2 riastrad
406 1.1.1.1.2.2 riastrad /**
407 1.1.1.1.2.2 riastrad * Probe DDC presence.
408 1.1.1.1.2.2 riastrad *
409 1.1.1.1.2.2 riastrad * \param adapter : i2c device adaptor
410 1.1.1.1.2.2 riastrad * \return 1 on success
411 1.1.1.1.2.2 riastrad */
412 1.1.1.1.2.2 riastrad bool
413 1.1.1.1.2.2 riastrad drm_probe_ddc(struct i2c_adapter *adapter)
414 1.1.1.1.2.2 riastrad {
415 1.1.1.1.2.2 riastrad unsigned char out;
416 1.1.1.1.2.2 riastrad
417 1.1.1.1.2.2 riastrad return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
418 1.1.1.1.2.2 riastrad }
419 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_probe_ddc);
420 1.1.1.1.2.2 riastrad
421 1.1.1.1.2.2 riastrad /**
422 1.1.1.1.2.2 riastrad * drm_get_edid - get EDID data, if available
423 1.1.1.1.2.2 riastrad * @connector: connector we're probing
424 1.1.1.1.2.2 riastrad * @adapter: i2c adapter to use for DDC
425 1.1.1.1.2.2 riastrad *
426 1.1.1.1.2.2 riastrad * Poke the given i2c channel to grab EDID data if possible. If found,
427 1.1.1.1.2.2 riastrad * attach it to the connector.
428 1.1.1.1.2.2 riastrad *
429 1.1.1.1.2.2 riastrad * Return edid data or NULL if we couldn't find any.
430 1.1.1.1.2.2 riastrad */
431 1.1.1.1.2.2 riastrad struct edid *drm_get_edid(struct drm_connector *connector,
432 1.1.1.1.2.2 riastrad struct i2c_adapter *adapter)
433 1.1.1.1.2.2 riastrad {
434 1.1.1.1.2.2 riastrad struct edid *edid = NULL;
435 1.1.1.1.2.2 riastrad
436 1.1.1.1.2.2 riastrad if (drm_probe_ddc(adapter))
437 1.1.1.1.2.2 riastrad edid = (struct edid *)drm_do_get_edid(connector, adapter);
438 1.1.1.1.2.2 riastrad
439 1.1.1.1.2.2 riastrad return edid;
440 1.1.1.1.2.2 riastrad }
441 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_get_edid);
442 1.1.1.1.2.2 riastrad
443 1.1.1.1.2.5 riastrad #endif /* !defined(__NetBSD__) */
444 1.1.1.1.2.5 riastrad
445 1.1.1.1.2.2 riastrad /*** EDID parsing ***/
446 1.1.1.1.2.2 riastrad
447 1.1.1.1.2.2 riastrad /**
448 1.1.1.1.2.2 riastrad * edid_vendor - match a string against EDID's obfuscated vendor field
449 1.1.1.1.2.2 riastrad * @edid: EDID to match
450 1.1.1.1.2.2 riastrad * @vendor: vendor string
451 1.1.1.1.2.2 riastrad *
452 1.1.1.1.2.2 riastrad * Returns true if @vendor is in @edid, false otherwise
453 1.1.1.1.2.2 riastrad */
454 1.1.1.1.2.2 riastrad static bool edid_vendor(struct edid *edid, char *vendor)
455 1.1.1.1.2.2 riastrad {
456 1.1.1.1.2.7 riastrad #ifdef __NetBSD__ /* XXX Avoid shadowing global definition. */
457 1.1.1.1.2.7 riastrad char edidv[3];
458 1.1.1.1.2.7 riastrad
459 1.1.1.1.2.7 riastrad edidv[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
460 1.1.1.1.2.7 riastrad edidv[1] = (((edid->mfg_id[0] & 0x3) << 3) |
461 1.1.1.1.2.7 riastrad ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
462 1.1.1.1.2.7 riastrad edidv[2] = (edid->mfg_id[1] & 0x1f) + '@';
463 1.1.1.1.2.7 riastrad
464 1.1.1.1.2.7 riastrad return !strncmp(edidv, vendor, 3);
465 1.1.1.1.2.7 riastrad #else
466 1.1.1.1.2.2 riastrad char edid_vendor[3];
467 1.1.1.1.2.2 riastrad
468 1.1.1.1.2.2 riastrad edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
469 1.1.1.1.2.2 riastrad edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
470 1.1.1.1.2.2 riastrad ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
471 1.1.1.1.2.2 riastrad edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
472 1.1.1.1.2.2 riastrad
473 1.1.1.1.2.2 riastrad return !strncmp(edid_vendor, vendor, 3);
474 1.1.1.1.2.7 riastrad #endif
475 1.1.1.1.2.2 riastrad }
476 1.1.1.1.2.2 riastrad
477 1.1.1.1.2.2 riastrad /**
478 1.1.1.1.2.2 riastrad * edid_get_quirks - return quirk flags for a given EDID
479 1.1.1.1.2.2 riastrad * @edid: EDID to process
480 1.1.1.1.2.2 riastrad *
481 1.1.1.1.2.2 riastrad * This tells subsequent routines what fixes they need to apply.
482 1.1.1.1.2.2 riastrad */
483 1.1.1.1.2.2 riastrad static u32 edid_get_quirks(struct edid *edid)
484 1.1.1.1.2.2 riastrad {
485 1.1.1.1.2.2 riastrad struct edid_quirk *quirk;
486 1.1.1.1.2.2 riastrad int i;
487 1.1.1.1.2.2 riastrad
488 1.1.1.1.2.2 riastrad for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
489 1.1.1.1.2.2 riastrad quirk = &edid_quirk_list[i];
490 1.1.1.1.2.2 riastrad
491 1.1.1.1.2.2 riastrad if (edid_vendor(edid, quirk->vendor) &&
492 1.1.1.1.2.2 riastrad (EDID_PRODUCT_ID(edid) == quirk->product_id))
493 1.1.1.1.2.2 riastrad return quirk->quirks;
494 1.1.1.1.2.2 riastrad }
495 1.1.1.1.2.2 riastrad
496 1.1.1.1.2.2 riastrad return 0;
497 1.1.1.1.2.2 riastrad }
498 1.1.1.1.2.2 riastrad
499 1.1.1.1.2.2 riastrad #define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
500 1.1.1.1.2.2 riastrad #define MODE_REFRESH_DIFF(m,r) (abs((m)->vrefresh - target_refresh))
501 1.1.1.1.2.2 riastrad
502 1.1.1.1.2.2 riastrad /**
503 1.1.1.1.2.2 riastrad * edid_fixup_preferred - set preferred modes based on quirk list
504 1.1.1.1.2.2 riastrad * @connector: has mode list to fix up
505 1.1.1.1.2.2 riastrad * @quirks: quirks list
506 1.1.1.1.2.2 riastrad *
507 1.1.1.1.2.2 riastrad * Walk the mode list for @connector, clearing the preferred status
508 1.1.1.1.2.2 riastrad * on existing modes and setting it anew for the right mode ala @quirks.
509 1.1.1.1.2.2 riastrad */
510 1.1.1.1.2.2 riastrad static void edid_fixup_preferred(struct drm_connector *connector,
511 1.1.1.1.2.2 riastrad u32 quirks)
512 1.1.1.1.2.2 riastrad {
513 1.1.1.1.2.2 riastrad struct drm_display_mode *t, *cur_mode, *preferred_mode;
514 1.1.1.1.2.2 riastrad int target_refresh = 0;
515 1.1.1.1.2.2 riastrad
516 1.1.1.1.2.2 riastrad if (list_empty(&connector->probed_modes))
517 1.1.1.1.2.2 riastrad return;
518 1.1.1.1.2.2 riastrad
519 1.1.1.1.2.2 riastrad if (quirks & EDID_QUIRK_PREFER_LARGE_60)
520 1.1.1.1.2.2 riastrad target_refresh = 60;
521 1.1.1.1.2.2 riastrad if (quirks & EDID_QUIRK_PREFER_LARGE_75)
522 1.1.1.1.2.2 riastrad target_refresh = 75;
523 1.1.1.1.2.2 riastrad
524 1.1.1.1.2.2 riastrad preferred_mode = list_first_entry(&connector->probed_modes,
525 1.1.1.1.2.2 riastrad struct drm_display_mode, head);
526 1.1.1.1.2.2 riastrad
527 1.1.1.1.2.2 riastrad list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
528 1.1.1.1.2.2 riastrad cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
529 1.1.1.1.2.2 riastrad
530 1.1.1.1.2.2 riastrad if (cur_mode == preferred_mode)
531 1.1.1.1.2.2 riastrad continue;
532 1.1.1.1.2.2 riastrad
533 1.1.1.1.2.2 riastrad /* Largest mode is preferred */
534 1.1.1.1.2.2 riastrad if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
535 1.1.1.1.2.2 riastrad preferred_mode = cur_mode;
536 1.1.1.1.2.2 riastrad
537 1.1.1.1.2.2 riastrad /* At a given size, try to get closest to target refresh */
538 1.1.1.1.2.2 riastrad if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
539 1.1.1.1.2.2 riastrad MODE_REFRESH_DIFF(cur_mode, target_refresh) <
540 1.1.1.1.2.2 riastrad MODE_REFRESH_DIFF(preferred_mode, target_refresh)) {
541 1.1.1.1.2.2 riastrad preferred_mode = cur_mode;
542 1.1.1.1.2.2 riastrad }
543 1.1.1.1.2.2 riastrad }
544 1.1.1.1.2.2 riastrad
545 1.1.1.1.2.2 riastrad preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
546 1.1.1.1.2.2 riastrad }
547 1.1.1.1.2.2 riastrad
548 1.1.1.1.2.2 riastrad static bool
549 1.1.1.1.2.2 riastrad mode_is_rb(const struct drm_display_mode *mode)
550 1.1.1.1.2.2 riastrad {
551 1.1.1.1.2.2 riastrad return (mode->htotal - mode->hdisplay == 160) &&
552 1.1.1.1.2.2 riastrad (mode->hsync_end - mode->hdisplay == 80) &&
553 1.1.1.1.2.2 riastrad (mode->hsync_end - mode->hsync_start == 32) &&
554 1.1.1.1.2.2 riastrad (mode->vsync_start - mode->vdisplay == 3);
555 1.1.1.1.2.2 riastrad }
556 1.1.1.1.2.2 riastrad
557 1.1.1.1.2.2 riastrad /*
558 1.1.1.1.2.2 riastrad * drm_mode_find_dmt - Create a copy of a mode if present in DMT
559 1.1.1.1.2.2 riastrad * @dev: Device to duplicate against
560 1.1.1.1.2.2 riastrad * @hsize: Mode width
561 1.1.1.1.2.2 riastrad * @vsize: Mode height
562 1.1.1.1.2.2 riastrad * @fresh: Mode refresh rate
563 1.1.1.1.2.2 riastrad * @rb: Mode reduced-blanking-ness
564 1.1.1.1.2.2 riastrad *
565 1.1.1.1.2.2 riastrad * Walk the DMT mode list looking for a match for the given parameters.
566 1.1.1.1.2.2 riastrad * Return a newly allocated copy of the mode, or NULL if not found.
567 1.1.1.1.2.2 riastrad */
568 1.1.1.1.2.2 riastrad struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
569 1.1.1.1.2.2 riastrad int hsize, int vsize, int fresh,
570 1.1.1.1.2.2 riastrad bool rb)
571 1.1.1.1.2.2 riastrad {
572 1.1.1.1.2.2 riastrad int i;
573 1.1.1.1.2.2 riastrad
574 1.1.1.1.2.2 riastrad for (i = 0; i < drm_num_dmt_modes; i++) {
575 1.1.1.1.2.2 riastrad const struct drm_display_mode *ptr = &drm_dmt_modes[i];
576 1.1.1.1.2.2 riastrad if (hsize != ptr->hdisplay)
577 1.1.1.1.2.2 riastrad continue;
578 1.1.1.1.2.2 riastrad if (vsize != ptr->vdisplay)
579 1.1.1.1.2.2 riastrad continue;
580 1.1.1.1.2.2 riastrad if (fresh != drm_mode_vrefresh(ptr))
581 1.1.1.1.2.2 riastrad continue;
582 1.1.1.1.2.2 riastrad if (rb != mode_is_rb(ptr))
583 1.1.1.1.2.2 riastrad continue;
584 1.1.1.1.2.2 riastrad
585 1.1.1.1.2.2 riastrad return drm_mode_duplicate(dev, ptr);
586 1.1.1.1.2.2 riastrad }
587 1.1.1.1.2.2 riastrad
588 1.1.1.1.2.2 riastrad return NULL;
589 1.1.1.1.2.2 riastrad }
590 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_mode_find_dmt);
591 1.1.1.1.2.2 riastrad
592 1.1.1.1.2.2 riastrad typedef void detailed_cb(struct detailed_timing *timing, void *closure);
593 1.1.1.1.2.2 riastrad
594 1.1.1.1.2.2 riastrad static void
595 1.1.1.1.2.2 riastrad cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
596 1.1.1.1.2.2 riastrad {
597 1.1.1.1.2.2 riastrad int i, n = 0;
598 1.1.1.1.2.2 riastrad u8 d = ext[0x02];
599 1.1.1.1.2.2 riastrad u8 *det_base = ext + d;
600 1.1.1.1.2.2 riastrad
601 1.1.1.1.2.2 riastrad n = (127 - d) / 18;
602 1.1.1.1.2.2 riastrad for (i = 0; i < n; i++)
603 1.1.1.1.2.2 riastrad cb((struct detailed_timing *)(det_base + 18 * i), closure);
604 1.1.1.1.2.2 riastrad }
605 1.1.1.1.2.2 riastrad
606 1.1.1.1.2.2 riastrad static void
607 1.1.1.1.2.2 riastrad vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
608 1.1.1.1.2.2 riastrad {
609 1.1.1.1.2.2 riastrad unsigned int i, n = min((int)ext[0x02], 6);
610 1.1.1.1.2.2 riastrad u8 *det_base = ext + 5;
611 1.1.1.1.2.2 riastrad
612 1.1.1.1.2.2 riastrad if (ext[0x01] != 1)
613 1.1.1.1.2.2 riastrad return; /* unknown version */
614 1.1.1.1.2.2 riastrad
615 1.1.1.1.2.2 riastrad for (i = 0; i < n; i++)
616 1.1.1.1.2.2 riastrad cb((struct detailed_timing *)(det_base + 18 * i), closure);
617 1.1.1.1.2.2 riastrad }
618 1.1.1.1.2.2 riastrad
619 1.1.1.1.2.2 riastrad static void
620 1.1.1.1.2.2 riastrad drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
621 1.1.1.1.2.2 riastrad {
622 1.1.1.1.2.2 riastrad int i;
623 1.1.1.1.2.2 riastrad struct edid *edid = (struct edid *)raw_edid;
624 1.1.1.1.2.2 riastrad
625 1.1.1.1.2.2 riastrad if (edid == NULL)
626 1.1.1.1.2.2 riastrad return;
627 1.1.1.1.2.2 riastrad
628 1.1.1.1.2.2 riastrad for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
629 1.1.1.1.2.2 riastrad cb(&(edid->detailed_timings[i]), closure);
630 1.1.1.1.2.2 riastrad
631 1.1.1.1.2.2 riastrad for (i = 1; i <= raw_edid[0x7e]; i++) {
632 1.1.1.1.2.2 riastrad u8 *ext = raw_edid + (i * EDID_LENGTH);
633 1.1.1.1.2.2 riastrad switch (*ext) {
634 1.1.1.1.2.2 riastrad case CEA_EXT:
635 1.1.1.1.2.2 riastrad cea_for_each_detailed_block(ext, cb, closure);
636 1.1.1.1.2.2 riastrad break;
637 1.1.1.1.2.2 riastrad case VTB_EXT:
638 1.1.1.1.2.2 riastrad vtb_for_each_detailed_block(ext, cb, closure);
639 1.1.1.1.2.2 riastrad break;
640 1.1.1.1.2.2 riastrad default:
641 1.1.1.1.2.2 riastrad break;
642 1.1.1.1.2.2 riastrad }
643 1.1.1.1.2.2 riastrad }
644 1.1.1.1.2.2 riastrad }
645 1.1.1.1.2.2 riastrad
646 1.1.1.1.2.2 riastrad static void
647 1.1.1.1.2.2 riastrad is_rb(struct detailed_timing *t, void *data)
648 1.1.1.1.2.2 riastrad {
649 1.1.1.1.2.2 riastrad u8 *r = (u8 *)t;
650 1.1.1.1.2.2 riastrad if (r[3] == EDID_DETAIL_MONITOR_RANGE)
651 1.1.1.1.2.2 riastrad if (r[15] & 0x10)
652 1.1.1.1.2.2 riastrad *(bool *)data = true;
653 1.1.1.1.2.2 riastrad }
654 1.1.1.1.2.2 riastrad
655 1.1.1.1.2.2 riastrad /* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
656 1.1.1.1.2.2 riastrad static bool
657 1.1.1.1.2.2 riastrad drm_monitor_supports_rb(struct edid *edid)
658 1.1.1.1.2.2 riastrad {
659 1.1.1.1.2.2 riastrad if (edid->revision >= 4) {
660 1.1.1.1.2.2 riastrad bool ret = false;
661 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
662 1.1.1.1.2.2 riastrad return ret;
663 1.1.1.1.2.2 riastrad }
664 1.1.1.1.2.2 riastrad
665 1.1.1.1.2.2 riastrad return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
666 1.1.1.1.2.2 riastrad }
667 1.1.1.1.2.2 riastrad
668 1.1.1.1.2.2 riastrad static void
669 1.1.1.1.2.2 riastrad find_gtf2(struct detailed_timing *t, void *data)
670 1.1.1.1.2.2 riastrad {
671 1.1.1.1.2.2 riastrad u8 *r = (u8 *)t;
672 1.1.1.1.2.2 riastrad if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
673 1.1.1.1.2.2 riastrad *(u8 **)data = r;
674 1.1.1.1.2.2 riastrad }
675 1.1.1.1.2.2 riastrad
676 1.1.1.1.2.2 riastrad /* Secondary GTF curve kicks in above some break frequency */
677 1.1.1.1.2.2 riastrad static int
678 1.1.1.1.2.2 riastrad drm_gtf2_hbreak(struct edid *edid)
679 1.1.1.1.2.2 riastrad {
680 1.1.1.1.2.2 riastrad u8 *r = NULL;
681 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
682 1.1.1.1.2.2 riastrad return r ? (r[12] * 2) : 0;
683 1.1.1.1.2.2 riastrad }
684 1.1.1.1.2.2 riastrad
685 1.1.1.1.2.2 riastrad static int
686 1.1.1.1.2.2 riastrad drm_gtf2_2c(struct edid *edid)
687 1.1.1.1.2.2 riastrad {
688 1.1.1.1.2.2 riastrad u8 *r = NULL;
689 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
690 1.1.1.1.2.2 riastrad return r ? r[13] : 0;
691 1.1.1.1.2.2 riastrad }
692 1.1.1.1.2.2 riastrad
693 1.1.1.1.2.2 riastrad static int
694 1.1.1.1.2.2 riastrad drm_gtf2_m(struct edid *edid)
695 1.1.1.1.2.2 riastrad {
696 1.1.1.1.2.2 riastrad u8 *r = NULL;
697 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
698 1.1.1.1.2.2 riastrad return r ? (r[15] << 8) + r[14] : 0;
699 1.1.1.1.2.2 riastrad }
700 1.1.1.1.2.2 riastrad
701 1.1.1.1.2.2 riastrad static int
702 1.1.1.1.2.2 riastrad drm_gtf2_k(struct edid *edid)
703 1.1.1.1.2.2 riastrad {
704 1.1.1.1.2.2 riastrad u8 *r = NULL;
705 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
706 1.1.1.1.2.2 riastrad return r ? r[16] : 0;
707 1.1.1.1.2.2 riastrad }
708 1.1.1.1.2.2 riastrad
709 1.1.1.1.2.2 riastrad static int
710 1.1.1.1.2.2 riastrad drm_gtf2_2j(struct edid *edid)
711 1.1.1.1.2.2 riastrad {
712 1.1.1.1.2.2 riastrad u8 *r = NULL;
713 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
714 1.1.1.1.2.2 riastrad return r ? r[17] : 0;
715 1.1.1.1.2.2 riastrad }
716 1.1.1.1.2.2 riastrad
717 1.1.1.1.2.2 riastrad /**
718 1.1.1.1.2.2 riastrad * standard_timing_level - get std. timing level(CVT/GTF/DMT)
719 1.1.1.1.2.2 riastrad * @edid: EDID block to scan
720 1.1.1.1.2.2 riastrad */
721 1.1.1.1.2.2 riastrad static int standard_timing_level(struct edid *edid)
722 1.1.1.1.2.2 riastrad {
723 1.1.1.1.2.2 riastrad if (edid->revision >= 2) {
724 1.1.1.1.2.2 riastrad if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
725 1.1.1.1.2.2 riastrad return LEVEL_CVT;
726 1.1.1.1.2.2 riastrad if (drm_gtf2_hbreak(edid))
727 1.1.1.1.2.2 riastrad return LEVEL_GTF2;
728 1.1.1.1.2.2 riastrad return LEVEL_GTF;
729 1.1.1.1.2.2 riastrad }
730 1.1.1.1.2.2 riastrad return LEVEL_DMT;
731 1.1.1.1.2.2 riastrad }
732 1.1.1.1.2.2 riastrad
733 1.1.1.1.2.2 riastrad /*
734 1.1.1.1.2.2 riastrad * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
735 1.1.1.1.2.2 riastrad * monitors fill with ascii space (0x20) instead.
736 1.1.1.1.2.2 riastrad */
737 1.1.1.1.2.2 riastrad static int
738 1.1.1.1.2.2 riastrad bad_std_timing(u8 a, u8 b)
739 1.1.1.1.2.2 riastrad {
740 1.1.1.1.2.2 riastrad return (a == 0x00 && b == 0x00) ||
741 1.1.1.1.2.2 riastrad (a == 0x01 && b == 0x01) ||
742 1.1.1.1.2.2 riastrad (a == 0x20 && b == 0x20);
743 1.1.1.1.2.2 riastrad }
744 1.1.1.1.2.2 riastrad
745 1.1.1.1.2.2 riastrad /**
746 1.1.1.1.2.2 riastrad * drm_mode_std - convert standard mode info (width, height, refresh) into mode
747 1.1.1.1.2.2 riastrad * @t: standard timing params
748 1.1.1.1.2.2 riastrad * @timing_level: standard timing level
749 1.1.1.1.2.2 riastrad *
750 1.1.1.1.2.2 riastrad * Take the standard timing params (in this case width, aspect, and refresh)
751 1.1.1.1.2.2 riastrad * and convert them into a real mode using CVT/GTF/DMT.
752 1.1.1.1.2.2 riastrad */
753 1.1.1.1.2.2 riastrad static struct drm_display_mode *
754 1.1.1.1.2.2 riastrad drm_mode_std(struct drm_connector *connector, struct edid *edid,
755 1.1.1.1.2.2 riastrad struct std_timing *t, int revision)
756 1.1.1.1.2.2 riastrad {
757 1.1.1.1.2.2 riastrad struct drm_device *dev = connector->dev;
758 1.1.1.1.2.2 riastrad struct drm_display_mode *m, *mode = NULL;
759 1.1.1.1.2.2 riastrad int hsize, vsize;
760 1.1.1.1.2.2 riastrad int vrefresh_rate;
761 1.1.1.1.2.2 riastrad unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
762 1.1.1.1.2.2 riastrad >> EDID_TIMING_ASPECT_SHIFT;
763 1.1.1.1.2.2 riastrad unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
764 1.1.1.1.2.2 riastrad >> EDID_TIMING_VFREQ_SHIFT;
765 1.1.1.1.2.2 riastrad int timing_level = standard_timing_level(edid);
766 1.1.1.1.2.2 riastrad
767 1.1.1.1.2.2 riastrad if (bad_std_timing(t->hsize, t->vfreq_aspect))
768 1.1.1.1.2.2 riastrad return NULL;
769 1.1.1.1.2.2 riastrad
770 1.1.1.1.2.2 riastrad /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
771 1.1.1.1.2.2 riastrad hsize = t->hsize * 8 + 248;
772 1.1.1.1.2.2 riastrad /* vrefresh_rate = vfreq + 60 */
773 1.1.1.1.2.2 riastrad vrefresh_rate = vfreq + 60;
774 1.1.1.1.2.2 riastrad /* the vdisplay is calculated based on the aspect ratio */
775 1.1.1.1.2.2 riastrad if (aspect_ratio == 0) {
776 1.1.1.1.2.2 riastrad if (revision < 3)
777 1.1.1.1.2.2 riastrad vsize = hsize;
778 1.1.1.1.2.2 riastrad else
779 1.1.1.1.2.2 riastrad vsize = (hsize * 10) / 16;
780 1.1.1.1.2.2 riastrad } else if (aspect_ratio == 1)
781 1.1.1.1.2.2 riastrad vsize = (hsize * 3) / 4;
782 1.1.1.1.2.2 riastrad else if (aspect_ratio == 2)
783 1.1.1.1.2.2 riastrad vsize = (hsize * 4) / 5;
784 1.1.1.1.2.2 riastrad else
785 1.1.1.1.2.2 riastrad vsize = (hsize * 9) / 16;
786 1.1.1.1.2.2 riastrad
787 1.1.1.1.2.2 riastrad /* HDTV hack, part 1 */
788 1.1.1.1.2.2 riastrad if (vrefresh_rate == 60 &&
789 1.1.1.1.2.2 riastrad ((hsize == 1360 && vsize == 765) ||
790 1.1.1.1.2.2 riastrad (hsize == 1368 && vsize == 769))) {
791 1.1.1.1.2.2 riastrad hsize = 1366;
792 1.1.1.1.2.2 riastrad vsize = 768;
793 1.1.1.1.2.2 riastrad }
794 1.1.1.1.2.2 riastrad
795 1.1.1.1.2.2 riastrad /*
796 1.1.1.1.2.2 riastrad * If this connector already has a mode for this size and refresh
797 1.1.1.1.2.2 riastrad * rate (because it came from detailed or CVT info), use that
798 1.1.1.1.2.2 riastrad * instead. This way we don't have to guess at interlace or
799 1.1.1.1.2.2 riastrad * reduced blanking.
800 1.1.1.1.2.2 riastrad */
801 1.1.1.1.2.2 riastrad list_for_each_entry(m, &connector->probed_modes, head)
802 1.1.1.1.2.2 riastrad if (m->hdisplay == hsize && m->vdisplay == vsize &&
803 1.1.1.1.2.2 riastrad drm_mode_vrefresh(m) == vrefresh_rate)
804 1.1.1.1.2.2 riastrad return NULL;
805 1.1.1.1.2.2 riastrad
806 1.1.1.1.2.2 riastrad /* HDTV hack, part 2 */
807 1.1.1.1.2.2 riastrad if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
808 1.1.1.1.2.2 riastrad mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
809 1.1.1.1.2.2 riastrad false);
810 1.1.1.1.2.2 riastrad mode->hdisplay = 1366;
811 1.1.1.1.2.2 riastrad mode->hsync_start = mode->hsync_start - 1;
812 1.1.1.1.2.2 riastrad mode->hsync_end = mode->hsync_end - 1;
813 1.1.1.1.2.2 riastrad return mode;
814 1.1.1.1.2.2 riastrad }
815 1.1.1.1.2.2 riastrad
816 1.1.1.1.2.2 riastrad /* check whether it can be found in default mode table */
817 1.1.1.1.2.2 riastrad if (drm_monitor_supports_rb(edid)) {
818 1.1.1.1.2.2 riastrad mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
819 1.1.1.1.2.2 riastrad true);
820 1.1.1.1.2.2 riastrad if (mode)
821 1.1.1.1.2.2 riastrad return mode;
822 1.1.1.1.2.2 riastrad }
823 1.1.1.1.2.2 riastrad mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
824 1.1.1.1.2.2 riastrad if (mode)
825 1.1.1.1.2.2 riastrad return mode;
826 1.1.1.1.2.2 riastrad
827 1.1.1.1.2.2 riastrad /* okay, generate it */
828 1.1.1.1.2.2 riastrad switch (timing_level) {
829 1.1.1.1.2.2 riastrad case LEVEL_DMT:
830 1.1.1.1.2.2 riastrad break;
831 1.1.1.1.2.2 riastrad case LEVEL_GTF:
832 1.1.1.1.2.2 riastrad mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
833 1.1.1.1.2.2 riastrad break;
834 1.1.1.1.2.2 riastrad case LEVEL_GTF2:
835 1.1.1.1.2.2 riastrad /*
836 1.1.1.1.2.2 riastrad * This is potentially wrong if there's ever a monitor with
837 1.1.1.1.2.2 riastrad * more than one ranges section, each claiming a different
838 1.1.1.1.2.2 riastrad * secondary GTF curve. Please don't do that.
839 1.1.1.1.2.2 riastrad */
840 1.1.1.1.2.2 riastrad mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
841 1.1.1.1.2.2 riastrad if (!mode)
842 1.1.1.1.2.2 riastrad return NULL;
843 1.1.1.1.2.2 riastrad if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
844 1.1.1.1.2.2 riastrad drm_mode_destroy(dev, mode);
845 1.1.1.1.2.2 riastrad mode = drm_gtf_mode_complex(dev, hsize, vsize,
846 1.1.1.1.2.2 riastrad vrefresh_rate, 0, 0,
847 1.1.1.1.2.2 riastrad drm_gtf2_m(edid),
848 1.1.1.1.2.2 riastrad drm_gtf2_2c(edid),
849 1.1.1.1.2.2 riastrad drm_gtf2_k(edid),
850 1.1.1.1.2.2 riastrad drm_gtf2_2j(edid));
851 1.1.1.1.2.2 riastrad }
852 1.1.1.1.2.2 riastrad break;
853 1.1.1.1.2.2 riastrad case LEVEL_CVT:
854 1.1.1.1.2.2 riastrad mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
855 1.1.1.1.2.2 riastrad false);
856 1.1.1.1.2.2 riastrad break;
857 1.1.1.1.2.2 riastrad }
858 1.1.1.1.2.2 riastrad return mode;
859 1.1.1.1.2.2 riastrad }
860 1.1.1.1.2.2 riastrad
861 1.1.1.1.2.2 riastrad /*
862 1.1.1.1.2.2 riastrad * EDID is delightfully ambiguous about how interlaced modes are to be
863 1.1.1.1.2.2 riastrad * encoded. Our internal representation is of frame height, but some
864 1.1.1.1.2.2 riastrad * HDTV detailed timings are encoded as field height.
865 1.1.1.1.2.2 riastrad *
866 1.1.1.1.2.2 riastrad * The format list here is from CEA, in frame size. Technically we
867 1.1.1.1.2.2 riastrad * should be checking refresh rate too. Whatever.
868 1.1.1.1.2.2 riastrad */
869 1.1.1.1.2.2 riastrad static void
870 1.1.1.1.2.2 riastrad drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
871 1.1.1.1.2.2 riastrad struct detailed_pixel_timing *pt)
872 1.1.1.1.2.2 riastrad {
873 1.1.1.1.2.2 riastrad int i;
874 1.1.1.1.2.2 riastrad static const struct {
875 1.1.1.1.2.2 riastrad int w, h;
876 1.1.1.1.2.2 riastrad } cea_interlaced[] = {
877 1.1.1.1.2.2 riastrad { 1920, 1080 },
878 1.1.1.1.2.2 riastrad { 720, 480 },
879 1.1.1.1.2.2 riastrad { 1440, 480 },
880 1.1.1.1.2.2 riastrad { 2880, 480 },
881 1.1.1.1.2.2 riastrad { 720, 576 },
882 1.1.1.1.2.2 riastrad { 1440, 576 },
883 1.1.1.1.2.2 riastrad { 2880, 576 },
884 1.1.1.1.2.2 riastrad };
885 1.1.1.1.2.2 riastrad
886 1.1.1.1.2.2 riastrad if (!(pt->misc & DRM_EDID_PT_INTERLACED))
887 1.1.1.1.2.2 riastrad return;
888 1.1.1.1.2.2 riastrad
889 1.1.1.1.2.2 riastrad for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
890 1.1.1.1.2.2 riastrad if ((mode->hdisplay == cea_interlaced[i].w) &&
891 1.1.1.1.2.2 riastrad (mode->vdisplay == cea_interlaced[i].h / 2)) {
892 1.1.1.1.2.2 riastrad mode->vdisplay *= 2;
893 1.1.1.1.2.2 riastrad mode->vsync_start *= 2;
894 1.1.1.1.2.2 riastrad mode->vsync_end *= 2;
895 1.1.1.1.2.2 riastrad mode->vtotal *= 2;
896 1.1.1.1.2.2 riastrad mode->vtotal |= 1;
897 1.1.1.1.2.2 riastrad }
898 1.1.1.1.2.2 riastrad }
899 1.1.1.1.2.2 riastrad
900 1.1.1.1.2.2 riastrad mode->flags |= DRM_MODE_FLAG_INTERLACE;
901 1.1.1.1.2.2 riastrad }
902 1.1.1.1.2.2 riastrad
903 1.1.1.1.2.2 riastrad /**
904 1.1.1.1.2.2 riastrad * drm_mode_detailed - create a new mode from an EDID detailed timing section
905 1.1.1.1.2.2 riastrad * @dev: DRM device (needed to create new mode)
906 1.1.1.1.2.2 riastrad * @edid: EDID block
907 1.1.1.1.2.2 riastrad * @timing: EDID detailed timing info
908 1.1.1.1.2.2 riastrad * @quirks: quirks to apply
909 1.1.1.1.2.2 riastrad *
910 1.1.1.1.2.2 riastrad * An EDID detailed timing block contains enough info for us to create and
911 1.1.1.1.2.2 riastrad * return a new struct drm_display_mode.
912 1.1.1.1.2.2 riastrad */
913 1.1.1.1.2.2 riastrad static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
914 1.1.1.1.2.2 riastrad struct edid *edid,
915 1.1.1.1.2.2 riastrad struct detailed_timing *timing,
916 1.1.1.1.2.2 riastrad u32 quirks)
917 1.1.1.1.2.2 riastrad {
918 1.1.1.1.2.2 riastrad struct drm_display_mode *mode;
919 1.1.1.1.2.2 riastrad struct detailed_pixel_timing *pt = &timing->data.pixel_data;
920 1.1.1.1.2.2 riastrad unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
921 1.1.1.1.2.2 riastrad unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
922 1.1.1.1.2.2 riastrad unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
923 1.1.1.1.2.2 riastrad unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
924 1.1.1.1.2.2 riastrad unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
925 1.1.1.1.2.2 riastrad unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
926 1.1.1.1.2.2 riastrad unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) >> 2 | pt->vsync_offset_pulse_width_lo >> 4;
927 1.1.1.1.2.2 riastrad unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
928 1.1.1.1.2.2 riastrad
929 1.1.1.1.2.2 riastrad /* ignore tiny modes */
930 1.1.1.1.2.2 riastrad if (hactive < 64 || vactive < 64)
931 1.1.1.1.2.2 riastrad return NULL;
932 1.1.1.1.2.2 riastrad
933 1.1.1.1.2.2 riastrad if (pt->misc & DRM_EDID_PT_STEREO) {
934 1.1.1.1.2.2 riastrad printk(KERN_WARNING "stereo mode not supported\n");
935 1.1.1.1.2.2 riastrad return NULL;
936 1.1.1.1.2.2 riastrad }
937 1.1.1.1.2.2 riastrad if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
938 1.1.1.1.2.2 riastrad printk(KERN_WARNING "composite sync not supported\n");
939 1.1.1.1.2.2 riastrad }
940 1.1.1.1.2.2 riastrad
941 1.1.1.1.2.2 riastrad /* it is incorrect if hsync/vsync width is zero */
942 1.1.1.1.2.2 riastrad if (!hsync_pulse_width || !vsync_pulse_width) {
943 1.1.1.1.2.2 riastrad DRM_DEBUG_KMS("Incorrect Detailed timing. "
944 1.1.1.1.2.2 riastrad "Wrong Hsync/Vsync pulse width\n");
945 1.1.1.1.2.2 riastrad return NULL;
946 1.1.1.1.2.2 riastrad }
947 1.1.1.1.2.2 riastrad
948 1.1.1.1.2.2 riastrad if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
949 1.1.1.1.2.2 riastrad mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
950 1.1.1.1.2.2 riastrad if (!mode)
951 1.1.1.1.2.2 riastrad return NULL;
952 1.1.1.1.2.2 riastrad
953 1.1.1.1.2.2 riastrad goto set_size;
954 1.1.1.1.2.2 riastrad }
955 1.1.1.1.2.2 riastrad
956 1.1.1.1.2.2 riastrad mode = drm_mode_create(dev);
957 1.1.1.1.2.2 riastrad if (!mode)
958 1.1.1.1.2.2 riastrad return NULL;
959 1.1.1.1.2.2 riastrad
960 1.1.1.1.2.2 riastrad if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
961 1.1.1.1.2.2 riastrad timing->pixel_clock = cpu_to_le16(1088);
962 1.1.1.1.2.2 riastrad
963 1.1.1.1.2.2 riastrad mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
964 1.1.1.1.2.2 riastrad
965 1.1.1.1.2.2 riastrad mode->hdisplay = hactive;
966 1.1.1.1.2.2 riastrad mode->hsync_start = mode->hdisplay + hsync_offset;
967 1.1.1.1.2.2 riastrad mode->hsync_end = mode->hsync_start + hsync_pulse_width;
968 1.1.1.1.2.2 riastrad mode->htotal = mode->hdisplay + hblank;
969 1.1.1.1.2.2 riastrad
970 1.1.1.1.2.2 riastrad mode->vdisplay = vactive;
971 1.1.1.1.2.2 riastrad mode->vsync_start = mode->vdisplay + vsync_offset;
972 1.1.1.1.2.2 riastrad mode->vsync_end = mode->vsync_start + vsync_pulse_width;
973 1.1.1.1.2.2 riastrad mode->vtotal = mode->vdisplay + vblank;
974 1.1.1.1.2.2 riastrad
975 1.1.1.1.2.2 riastrad /* Some EDIDs have bogus h/vtotal values */
976 1.1.1.1.2.2 riastrad if (mode->hsync_end > mode->htotal)
977 1.1.1.1.2.2 riastrad mode->htotal = mode->hsync_end + 1;
978 1.1.1.1.2.2 riastrad if (mode->vsync_end > mode->vtotal)
979 1.1.1.1.2.2 riastrad mode->vtotal = mode->vsync_end + 1;
980 1.1.1.1.2.2 riastrad
981 1.1.1.1.2.2 riastrad drm_mode_do_interlace_quirk(mode, pt);
982 1.1.1.1.2.2 riastrad
983 1.1.1.1.2.2 riastrad if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
984 1.1.1.1.2.2 riastrad pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
985 1.1.1.1.2.2 riastrad }
986 1.1.1.1.2.2 riastrad
987 1.1.1.1.2.2 riastrad mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
988 1.1.1.1.2.2 riastrad DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
989 1.1.1.1.2.2 riastrad mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
990 1.1.1.1.2.2 riastrad DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
991 1.1.1.1.2.2 riastrad
992 1.1.1.1.2.2 riastrad set_size:
993 1.1.1.1.2.2 riastrad mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
994 1.1.1.1.2.2 riastrad mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
995 1.1.1.1.2.2 riastrad
996 1.1.1.1.2.2 riastrad if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
997 1.1.1.1.2.2 riastrad mode->width_mm *= 10;
998 1.1.1.1.2.2 riastrad mode->height_mm *= 10;
999 1.1.1.1.2.2 riastrad }
1000 1.1.1.1.2.2 riastrad
1001 1.1.1.1.2.2 riastrad if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
1002 1.1.1.1.2.2 riastrad mode->width_mm = edid->width_cm * 10;
1003 1.1.1.1.2.2 riastrad mode->height_mm = edid->height_cm * 10;
1004 1.1.1.1.2.2 riastrad }
1005 1.1.1.1.2.2 riastrad
1006 1.1.1.1.2.2 riastrad mode->type = DRM_MODE_TYPE_DRIVER;
1007 1.1.1.1.2.2 riastrad drm_mode_set_name(mode);
1008 1.1.1.1.2.2 riastrad
1009 1.1.1.1.2.2 riastrad return mode;
1010 1.1.1.1.2.2 riastrad }
1011 1.1.1.1.2.2 riastrad
1012 1.1.1.1.2.2 riastrad static bool
1013 1.1.1.1.2.2 riastrad mode_in_hsync_range(const struct drm_display_mode *mode,
1014 1.1.1.1.2.2 riastrad struct edid *edid, u8 *t)
1015 1.1.1.1.2.2 riastrad {
1016 1.1.1.1.2.2 riastrad int hsync, hmin, hmax;
1017 1.1.1.1.2.2 riastrad
1018 1.1.1.1.2.2 riastrad hmin = t[7];
1019 1.1.1.1.2.2 riastrad if (edid->revision >= 4)
1020 1.1.1.1.2.2 riastrad hmin += ((t[4] & 0x04) ? 255 : 0);
1021 1.1.1.1.2.2 riastrad hmax = t[8];
1022 1.1.1.1.2.2 riastrad if (edid->revision >= 4)
1023 1.1.1.1.2.2 riastrad hmax += ((t[4] & 0x08) ? 255 : 0);
1024 1.1.1.1.2.2 riastrad hsync = drm_mode_hsync(mode);
1025 1.1.1.1.2.2 riastrad
1026 1.1.1.1.2.2 riastrad return (hsync <= hmax && hsync >= hmin);
1027 1.1.1.1.2.2 riastrad }
1028 1.1.1.1.2.2 riastrad
1029 1.1.1.1.2.2 riastrad static bool
1030 1.1.1.1.2.2 riastrad mode_in_vsync_range(const struct drm_display_mode *mode,
1031 1.1.1.1.2.2 riastrad struct edid *edid, u8 *t)
1032 1.1.1.1.2.2 riastrad {
1033 1.1.1.1.2.2 riastrad int vsync, vmin, vmax;
1034 1.1.1.1.2.2 riastrad
1035 1.1.1.1.2.2 riastrad vmin = t[5];
1036 1.1.1.1.2.2 riastrad if (edid->revision >= 4)
1037 1.1.1.1.2.2 riastrad vmin += ((t[4] & 0x01) ? 255 : 0);
1038 1.1.1.1.2.2 riastrad vmax = t[6];
1039 1.1.1.1.2.2 riastrad if (edid->revision >= 4)
1040 1.1.1.1.2.2 riastrad vmax += ((t[4] & 0x02) ? 255 : 0);
1041 1.1.1.1.2.2 riastrad vsync = drm_mode_vrefresh(mode);
1042 1.1.1.1.2.2 riastrad
1043 1.1.1.1.2.2 riastrad return (vsync <= vmax && vsync >= vmin);
1044 1.1.1.1.2.2 riastrad }
1045 1.1.1.1.2.2 riastrad
1046 1.1.1.1.2.2 riastrad static u32
1047 1.1.1.1.2.2 riastrad range_pixel_clock(struct edid *edid, u8 *t)
1048 1.1.1.1.2.2 riastrad {
1049 1.1.1.1.2.2 riastrad /* unspecified */
1050 1.1.1.1.2.2 riastrad if (t[9] == 0 || t[9] == 255)
1051 1.1.1.1.2.2 riastrad return 0;
1052 1.1.1.1.2.2 riastrad
1053 1.1.1.1.2.2 riastrad /* 1.4 with CVT support gives us real precision, yay */
1054 1.1.1.1.2.2 riastrad if (edid->revision >= 4 && t[10] == 0x04)
1055 1.1.1.1.2.2 riastrad return (t[9] * 10000) - ((t[12] >> 2) * 250);
1056 1.1.1.1.2.2 riastrad
1057 1.1.1.1.2.2 riastrad /* 1.3 is pathetic, so fuzz up a bit */
1058 1.1.1.1.2.2 riastrad return t[9] * 10000 + 5001;
1059 1.1.1.1.2.2 riastrad }
1060 1.1.1.1.2.2 riastrad
1061 1.1.1.1.2.2 riastrad static bool
1062 1.1.1.1.2.2 riastrad mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
1063 1.1.1.1.2.2 riastrad struct detailed_timing *timing)
1064 1.1.1.1.2.2 riastrad {
1065 1.1.1.1.2.2 riastrad u32 max_clock;
1066 1.1.1.1.2.2 riastrad u8 *t = (u8 *)timing;
1067 1.1.1.1.2.2 riastrad
1068 1.1.1.1.2.2 riastrad if (!mode_in_hsync_range(mode, edid, t))
1069 1.1.1.1.2.2 riastrad return false;
1070 1.1.1.1.2.2 riastrad
1071 1.1.1.1.2.2 riastrad if (!mode_in_vsync_range(mode, edid, t))
1072 1.1.1.1.2.2 riastrad return false;
1073 1.1.1.1.2.2 riastrad
1074 1.1.1.1.2.2 riastrad if ((max_clock = range_pixel_clock(edid, t)))
1075 1.1.1.1.2.2 riastrad if (mode->clock > max_clock)
1076 1.1.1.1.2.2 riastrad return false;
1077 1.1.1.1.2.2 riastrad
1078 1.1.1.1.2.2 riastrad /* 1.4 max horizontal check */
1079 1.1.1.1.2.2 riastrad if (edid->revision >= 4 && t[10] == 0x04)
1080 1.1.1.1.2.2 riastrad if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
1081 1.1.1.1.2.2 riastrad return false;
1082 1.1.1.1.2.2 riastrad
1083 1.1.1.1.2.2 riastrad if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
1084 1.1.1.1.2.2 riastrad return false;
1085 1.1.1.1.2.2 riastrad
1086 1.1.1.1.2.2 riastrad return true;
1087 1.1.1.1.2.2 riastrad }
1088 1.1.1.1.2.2 riastrad
1089 1.1.1.1.2.2 riastrad static bool valid_inferred_mode(const struct drm_connector *connector,
1090 1.1.1.1.2.2 riastrad const struct drm_display_mode *mode)
1091 1.1.1.1.2.2 riastrad {
1092 1.1.1.1.2.2 riastrad struct drm_display_mode *m;
1093 1.1.1.1.2.2 riastrad bool ok = false;
1094 1.1.1.1.2.2 riastrad
1095 1.1.1.1.2.2 riastrad list_for_each_entry(m, &connector->probed_modes, head) {
1096 1.1.1.1.2.2 riastrad if (mode->hdisplay == m->hdisplay &&
1097 1.1.1.1.2.2 riastrad mode->vdisplay == m->vdisplay &&
1098 1.1.1.1.2.2 riastrad drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
1099 1.1.1.1.2.2 riastrad return false; /* duplicated */
1100 1.1.1.1.2.2 riastrad if (mode->hdisplay <= m->hdisplay &&
1101 1.1.1.1.2.2 riastrad mode->vdisplay <= m->vdisplay)
1102 1.1.1.1.2.2 riastrad ok = true;
1103 1.1.1.1.2.2 riastrad }
1104 1.1.1.1.2.2 riastrad return ok;
1105 1.1.1.1.2.2 riastrad }
1106 1.1.1.1.2.2 riastrad
1107 1.1.1.1.2.2 riastrad static int
1108 1.1.1.1.2.2 riastrad drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
1109 1.1.1.1.2.2 riastrad struct detailed_timing *timing)
1110 1.1.1.1.2.2 riastrad {
1111 1.1.1.1.2.2 riastrad int i, modes = 0;
1112 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1113 1.1.1.1.2.2 riastrad struct drm_device *dev = connector->dev;
1114 1.1.1.1.2.2 riastrad
1115 1.1.1.1.2.2 riastrad for (i = 0; i < drm_num_dmt_modes; i++) {
1116 1.1.1.1.2.2 riastrad if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
1117 1.1.1.1.2.2 riastrad valid_inferred_mode(connector, drm_dmt_modes + i)) {
1118 1.1.1.1.2.2 riastrad newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
1119 1.1.1.1.2.2 riastrad if (newmode) {
1120 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, newmode);
1121 1.1.1.1.2.2 riastrad modes++;
1122 1.1.1.1.2.2 riastrad }
1123 1.1.1.1.2.2 riastrad }
1124 1.1.1.1.2.2 riastrad }
1125 1.1.1.1.2.2 riastrad
1126 1.1.1.1.2.2 riastrad return modes;
1127 1.1.1.1.2.2 riastrad }
1128 1.1.1.1.2.2 riastrad
1129 1.1.1.1.2.2 riastrad /* fix up 1366x768 mode from 1368x768;
1130 1.1.1.1.2.2 riastrad * GFT/CVT can't express 1366 width which isn't dividable by 8
1131 1.1.1.1.2.2 riastrad */
1132 1.1.1.1.2.2 riastrad static void fixup_mode_1366x768(struct drm_display_mode *mode)
1133 1.1.1.1.2.2 riastrad {
1134 1.1.1.1.2.2 riastrad if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
1135 1.1.1.1.2.2 riastrad mode->hdisplay = 1366;
1136 1.1.1.1.2.2 riastrad mode->hsync_start--;
1137 1.1.1.1.2.2 riastrad mode->hsync_end--;
1138 1.1.1.1.2.2 riastrad drm_mode_set_name(mode);
1139 1.1.1.1.2.2 riastrad }
1140 1.1.1.1.2.2 riastrad }
1141 1.1.1.1.2.2 riastrad
1142 1.1.1.1.2.2 riastrad static int
1143 1.1.1.1.2.2 riastrad drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
1144 1.1.1.1.2.2 riastrad struct detailed_timing *timing)
1145 1.1.1.1.2.2 riastrad {
1146 1.1.1.1.2.2 riastrad int i, modes = 0;
1147 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1148 1.1.1.1.2.2 riastrad struct drm_device *dev = connector->dev;
1149 1.1.1.1.2.2 riastrad
1150 1.1.1.1.2.2 riastrad for (i = 0; i < num_extra_modes; i++) {
1151 1.1.1.1.2.2 riastrad const struct minimode *m = &extra_modes[i];
1152 1.1.1.1.2.2 riastrad newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
1153 1.1.1.1.2.2 riastrad if (!newmode)
1154 1.1.1.1.2.2 riastrad return modes;
1155 1.1.1.1.2.2 riastrad
1156 1.1.1.1.2.2 riastrad fixup_mode_1366x768(newmode);
1157 1.1.1.1.2.2 riastrad if (!mode_in_range(newmode, edid, timing) ||
1158 1.1.1.1.2.2 riastrad !valid_inferred_mode(connector, newmode)) {
1159 1.1.1.1.2.2 riastrad drm_mode_destroy(dev, newmode);
1160 1.1.1.1.2.2 riastrad continue;
1161 1.1.1.1.2.2 riastrad }
1162 1.1.1.1.2.2 riastrad
1163 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, newmode);
1164 1.1.1.1.2.2 riastrad modes++;
1165 1.1.1.1.2.2 riastrad }
1166 1.1.1.1.2.2 riastrad
1167 1.1.1.1.2.2 riastrad return modes;
1168 1.1.1.1.2.2 riastrad }
1169 1.1.1.1.2.2 riastrad
1170 1.1.1.1.2.2 riastrad static int
1171 1.1.1.1.2.2 riastrad drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
1172 1.1.1.1.2.2 riastrad struct detailed_timing *timing)
1173 1.1.1.1.2.2 riastrad {
1174 1.1.1.1.2.2 riastrad int i, modes = 0;
1175 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1176 1.1.1.1.2.2 riastrad struct drm_device *dev = connector->dev;
1177 1.1.1.1.2.2 riastrad bool rb = drm_monitor_supports_rb(edid);
1178 1.1.1.1.2.2 riastrad
1179 1.1.1.1.2.2 riastrad for (i = 0; i < num_extra_modes; i++) {
1180 1.1.1.1.2.2 riastrad const struct minimode *m = &extra_modes[i];
1181 1.1.1.1.2.2 riastrad newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
1182 1.1.1.1.2.2 riastrad if (!newmode)
1183 1.1.1.1.2.2 riastrad return modes;
1184 1.1.1.1.2.2 riastrad
1185 1.1.1.1.2.2 riastrad fixup_mode_1366x768(newmode);
1186 1.1.1.1.2.2 riastrad if (!mode_in_range(newmode, edid, timing) ||
1187 1.1.1.1.2.2 riastrad !valid_inferred_mode(connector, newmode)) {
1188 1.1.1.1.2.2 riastrad drm_mode_destroy(dev, newmode);
1189 1.1.1.1.2.2 riastrad continue;
1190 1.1.1.1.2.2 riastrad }
1191 1.1.1.1.2.2 riastrad
1192 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, newmode);
1193 1.1.1.1.2.2 riastrad modes++;
1194 1.1.1.1.2.2 riastrad }
1195 1.1.1.1.2.2 riastrad
1196 1.1.1.1.2.2 riastrad return modes;
1197 1.1.1.1.2.2 riastrad }
1198 1.1.1.1.2.2 riastrad
1199 1.1.1.1.2.2 riastrad static void
1200 1.1.1.1.2.2 riastrad do_inferred_modes(struct detailed_timing *timing, void *c)
1201 1.1.1.1.2.2 riastrad {
1202 1.1.1.1.2.2 riastrad struct detailed_mode_closure *closure = c;
1203 1.1.1.1.2.2 riastrad struct detailed_non_pixel *data = &timing->data.other_data;
1204 1.1.1.1.2.2 riastrad struct detailed_data_monitor_range *range = &data->data.range;
1205 1.1.1.1.2.2 riastrad
1206 1.1.1.1.2.2 riastrad if (data->type != EDID_DETAIL_MONITOR_RANGE)
1207 1.1.1.1.2.2 riastrad return;
1208 1.1.1.1.2.2 riastrad
1209 1.1.1.1.2.2 riastrad closure->modes += drm_dmt_modes_for_range(closure->connector,
1210 1.1.1.1.2.2 riastrad closure->edid,
1211 1.1.1.1.2.2 riastrad timing);
1212 1.1.1.1.2.2 riastrad
1213 1.1.1.1.2.2 riastrad if (!version_greater(closure->edid, 1, 1))
1214 1.1.1.1.2.2 riastrad return; /* GTF not defined yet */
1215 1.1.1.1.2.2 riastrad
1216 1.1.1.1.2.2 riastrad switch (range->flags) {
1217 1.1.1.1.2.2 riastrad case 0x02: /* secondary gtf, XXX could do more */
1218 1.1.1.1.2.2 riastrad case 0x00: /* default gtf */
1219 1.1.1.1.2.2 riastrad closure->modes += drm_gtf_modes_for_range(closure->connector,
1220 1.1.1.1.2.2 riastrad closure->edid,
1221 1.1.1.1.2.2 riastrad timing);
1222 1.1.1.1.2.2 riastrad break;
1223 1.1.1.1.2.2 riastrad case 0x04: /* cvt, only in 1.4+ */
1224 1.1.1.1.2.2 riastrad if (!version_greater(closure->edid, 1, 3))
1225 1.1.1.1.2.2 riastrad break;
1226 1.1.1.1.2.2 riastrad
1227 1.1.1.1.2.2 riastrad closure->modes += drm_cvt_modes_for_range(closure->connector,
1228 1.1.1.1.2.2 riastrad closure->edid,
1229 1.1.1.1.2.2 riastrad timing);
1230 1.1.1.1.2.2 riastrad break;
1231 1.1.1.1.2.2 riastrad case 0x01: /* just the ranges, no formula */
1232 1.1.1.1.2.2 riastrad default:
1233 1.1.1.1.2.2 riastrad break;
1234 1.1.1.1.2.2 riastrad }
1235 1.1.1.1.2.2 riastrad }
1236 1.1.1.1.2.2 riastrad
1237 1.1.1.1.2.2 riastrad static int
1238 1.1.1.1.2.2 riastrad add_inferred_modes(struct drm_connector *connector, struct edid *edid)
1239 1.1.1.1.2.2 riastrad {
1240 1.1.1.1.2.2 riastrad struct detailed_mode_closure closure = {
1241 1.1.1.1.2.2 riastrad connector, edid, 0, 0, 0
1242 1.1.1.1.2.2 riastrad };
1243 1.1.1.1.2.2 riastrad
1244 1.1.1.1.2.2 riastrad if (version_greater(edid, 1, 0))
1245 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
1246 1.1.1.1.2.2 riastrad &closure);
1247 1.1.1.1.2.2 riastrad
1248 1.1.1.1.2.2 riastrad return closure.modes;
1249 1.1.1.1.2.2 riastrad }
1250 1.1.1.1.2.2 riastrad
1251 1.1.1.1.2.2 riastrad static int
1252 1.1.1.1.2.2 riastrad drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
1253 1.1.1.1.2.2 riastrad {
1254 1.1.1.1.2.2 riastrad int i, j, m, modes = 0;
1255 1.1.1.1.2.2 riastrad struct drm_display_mode *mode;
1256 1.1.1.1.2.2 riastrad u8 *est = ((u8 *)timing) + 5;
1257 1.1.1.1.2.2 riastrad
1258 1.1.1.1.2.2 riastrad for (i = 0; i < 6; i++) {
1259 1.1.1.1.2.2 riastrad for (j = 7; j > 0; j--) {
1260 1.1.1.1.2.2 riastrad m = (i * 8) + (7 - j);
1261 1.1.1.1.2.2 riastrad if (m >= ARRAY_SIZE(est3_modes))
1262 1.1.1.1.2.2 riastrad break;
1263 1.1.1.1.2.2 riastrad if (est[i] & (1 << j)) {
1264 1.1.1.1.2.2 riastrad mode = drm_mode_find_dmt(connector->dev,
1265 1.1.1.1.2.2 riastrad est3_modes[m].w,
1266 1.1.1.1.2.2 riastrad est3_modes[m].h,
1267 1.1.1.1.2.2 riastrad est3_modes[m].r,
1268 1.1.1.1.2.2 riastrad est3_modes[m].rb);
1269 1.1.1.1.2.2 riastrad if (mode) {
1270 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, mode);
1271 1.1.1.1.2.2 riastrad modes++;
1272 1.1.1.1.2.2 riastrad }
1273 1.1.1.1.2.2 riastrad }
1274 1.1.1.1.2.2 riastrad }
1275 1.1.1.1.2.2 riastrad }
1276 1.1.1.1.2.2 riastrad
1277 1.1.1.1.2.2 riastrad return modes;
1278 1.1.1.1.2.2 riastrad }
1279 1.1.1.1.2.2 riastrad
1280 1.1.1.1.2.2 riastrad static void
1281 1.1.1.1.2.2 riastrad do_established_modes(struct detailed_timing *timing, void *c)
1282 1.1.1.1.2.2 riastrad {
1283 1.1.1.1.2.2 riastrad struct detailed_mode_closure *closure = c;
1284 1.1.1.1.2.2 riastrad struct detailed_non_pixel *data = &timing->data.other_data;
1285 1.1.1.1.2.2 riastrad
1286 1.1.1.1.2.2 riastrad if (data->type == EDID_DETAIL_EST_TIMINGS)
1287 1.1.1.1.2.2 riastrad closure->modes += drm_est3_modes(closure->connector, timing);
1288 1.1.1.1.2.2 riastrad }
1289 1.1.1.1.2.2 riastrad
1290 1.1.1.1.2.2 riastrad /**
1291 1.1.1.1.2.2 riastrad * add_established_modes - get est. modes from EDID and add them
1292 1.1.1.1.2.2 riastrad * @edid: EDID block to scan
1293 1.1.1.1.2.2 riastrad *
1294 1.1.1.1.2.2 riastrad * Each EDID block contains a bitmap of the supported "established modes" list
1295 1.1.1.1.2.2 riastrad * (defined above). Tease them out and add them to the global modes list.
1296 1.1.1.1.2.2 riastrad */
1297 1.1.1.1.2.2 riastrad static int
1298 1.1.1.1.2.2 riastrad add_established_modes(struct drm_connector *connector, struct edid *edid)
1299 1.1.1.1.2.2 riastrad {
1300 1.1.1.1.2.2 riastrad struct drm_device *dev = connector->dev;
1301 1.1.1.1.2.2 riastrad unsigned long est_bits = edid->established_timings.t1 |
1302 1.1.1.1.2.2 riastrad (edid->established_timings.t2 << 8) |
1303 1.1.1.1.2.2 riastrad ((edid->established_timings.mfg_rsvd & 0x80) << 9);
1304 1.1.1.1.2.2 riastrad int i, modes = 0;
1305 1.1.1.1.2.2 riastrad struct detailed_mode_closure closure = {
1306 1.1.1.1.2.2 riastrad connector, edid, 0, 0, 0
1307 1.1.1.1.2.2 riastrad };
1308 1.1.1.1.2.2 riastrad
1309 1.1.1.1.2.2 riastrad for (i = 0; i <= EDID_EST_TIMINGS; i++) {
1310 1.1.1.1.2.2 riastrad if (est_bits & (1<<i)) {
1311 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1312 1.1.1.1.2.2 riastrad newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
1313 1.1.1.1.2.2 riastrad if (newmode) {
1314 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, newmode);
1315 1.1.1.1.2.2 riastrad modes++;
1316 1.1.1.1.2.2 riastrad }
1317 1.1.1.1.2.2 riastrad }
1318 1.1.1.1.2.2 riastrad }
1319 1.1.1.1.2.2 riastrad
1320 1.1.1.1.2.2 riastrad if (version_greater(edid, 1, 0))
1321 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid,
1322 1.1.1.1.2.2 riastrad do_established_modes, &closure);
1323 1.1.1.1.2.2 riastrad
1324 1.1.1.1.2.2 riastrad return modes + closure.modes;
1325 1.1.1.1.2.2 riastrad }
1326 1.1.1.1.2.2 riastrad
1327 1.1.1.1.2.2 riastrad static void
1328 1.1.1.1.2.2 riastrad do_standard_modes(struct detailed_timing *timing, void *c)
1329 1.1.1.1.2.2 riastrad {
1330 1.1.1.1.2.2 riastrad struct detailed_mode_closure *closure = c;
1331 1.1.1.1.2.2 riastrad struct detailed_non_pixel *data = &timing->data.other_data;
1332 1.1.1.1.2.2 riastrad struct drm_connector *connector = closure->connector;
1333 1.1.1.1.2.2 riastrad struct edid *edid = closure->edid;
1334 1.1.1.1.2.2 riastrad
1335 1.1.1.1.2.2 riastrad if (data->type == EDID_DETAIL_STD_MODES) {
1336 1.1.1.1.2.2 riastrad int i;
1337 1.1.1.1.2.2 riastrad for (i = 0; i < 6; i++) {
1338 1.1.1.1.2.2 riastrad struct std_timing *std;
1339 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1340 1.1.1.1.2.2 riastrad
1341 1.1.1.1.2.2 riastrad std = &data->data.timings[i];
1342 1.1.1.1.2.2 riastrad newmode = drm_mode_std(connector, edid, std,
1343 1.1.1.1.2.2 riastrad edid->revision);
1344 1.1.1.1.2.2 riastrad if (newmode) {
1345 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, newmode);
1346 1.1.1.1.2.2 riastrad closure->modes++;
1347 1.1.1.1.2.2 riastrad }
1348 1.1.1.1.2.2 riastrad }
1349 1.1.1.1.2.2 riastrad }
1350 1.1.1.1.2.2 riastrad }
1351 1.1.1.1.2.2 riastrad
1352 1.1.1.1.2.2 riastrad /**
1353 1.1.1.1.2.2 riastrad * add_standard_modes - get std. modes from EDID and add them
1354 1.1.1.1.2.2 riastrad * @edid: EDID block to scan
1355 1.1.1.1.2.2 riastrad *
1356 1.1.1.1.2.2 riastrad * Standard modes can be calculated using the appropriate standard (DMT,
1357 1.1.1.1.2.2 riastrad * GTF or CVT. Grab them from @edid and add them to the list.
1358 1.1.1.1.2.2 riastrad */
1359 1.1.1.1.2.2 riastrad static int
1360 1.1.1.1.2.2 riastrad add_standard_modes(struct drm_connector *connector, struct edid *edid)
1361 1.1.1.1.2.2 riastrad {
1362 1.1.1.1.2.2 riastrad int i, modes = 0;
1363 1.1.1.1.2.2 riastrad struct detailed_mode_closure closure = {
1364 1.1.1.1.2.2 riastrad connector, edid, 0, 0, 0
1365 1.1.1.1.2.2 riastrad };
1366 1.1.1.1.2.2 riastrad
1367 1.1.1.1.2.2 riastrad for (i = 0; i < EDID_STD_TIMINGS; i++) {
1368 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1369 1.1.1.1.2.2 riastrad
1370 1.1.1.1.2.2 riastrad newmode = drm_mode_std(connector, edid,
1371 1.1.1.1.2.2 riastrad &edid->standard_timings[i],
1372 1.1.1.1.2.2 riastrad edid->revision);
1373 1.1.1.1.2.2 riastrad if (newmode) {
1374 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, newmode);
1375 1.1.1.1.2.2 riastrad modes++;
1376 1.1.1.1.2.2 riastrad }
1377 1.1.1.1.2.2 riastrad }
1378 1.1.1.1.2.2 riastrad
1379 1.1.1.1.2.2 riastrad if (version_greater(edid, 1, 0))
1380 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
1381 1.1.1.1.2.2 riastrad &closure);
1382 1.1.1.1.2.2 riastrad
1383 1.1.1.1.2.2 riastrad /* XXX should also look for standard codes in VTB blocks */
1384 1.1.1.1.2.2 riastrad
1385 1.1.1.1.2.2 riastrad return modes + closure.modes;
1386 1.1.1.1.2.2 riastrad }
1387 1.1.1.1.2.2 riastrad
1388 1.1.1.1.2.2 riastrad static int drm_cvt_modes(struct drm_connector *connector,
1389 1.1.1.1.2.2 riastrad struct detailed_timing *timing)
1390 1.1.1.1.2.2 riastrad {
1391 1.1.1.1.2.2 riastrad int i, j, modes = 0;
1392 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1393 1.1.1.1.2.2 riastrad struct drm_device *dev = connector->dev;
1394 1.1.1.1.2.2 riastrad struct cvt_timing *cvt;
1395 1.1.1.1.2.2 riastrad const int rates[] = { 60, 85, 75, 60, 50 };
1396 1.1.1.1.2.2 riastrad const u8 empty[3] = { 0, 0, 0 };
1397 1.1.1.1.2.2 riastrad
1398 1.1.1.1.2.2 riastrad for (i = 0; i < 4; i++) {
1399 1.1.1.1.2.2 riastrad int uninitialized_var(width), height;
1400 1.1.1.1.2.2 riastrad cvt = &(timing->data.other_data.data.cvt[i]);
1401 1.1.1.1.2.2 riastrad
1402 1.1.1.1.2.2 riastrad if (!memcmp(cvt->code, empty, 3))
1403 1.1.1.1.2.2 riastrad continue;
1404 1.1.1.1.2.2 riastrad
1405 1.1.1.1.2.2 riastrad height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
1406 1.1.1.1.2.2 riastrad switch (cvt->code[1] & 0x0c) {
1407 1.1.1.1.2.2 riastrad case 0x00:
1408 1.1.1.1.2.2 riastrad width = height * 4 / 3;
1409 1.1.1.1.2.2 riastrad break;
1410 1.1.1.1.2.2 riastrad case 0x04:
1411 1.1.1.1.2.2 riastrad width = height * 16 / 9;
1412 1.1.1.1.2.2 riastrad break;
1413 1.1.1.1.2.2 riastrad case 0x08:
1414 1.1.1.1.2.2 riastrad width = height * 16 / 10;
1415 1.1.1.1.2.2 riastrad break;
1416 1.1.1.1.2.2 riastrad case 0x0c:
1417 1.1.1.1.2.2 riastrad width = height * 15 / 9;
1418 1.1.1.1.2.2 riastrad break;
1419 1.1.1.1.2.2 riastrad }
1420 1.1.1.1.2.2 riastrad
1421 1.1.1.1.2.2 riastrad for (j = 1; j < 5; j++) {
1422 1.1.1.1.2.2 riastrad if (cvt->code[2] & (1 << j)) {
1423 1.1.1.1.2.2 riastrad newmode = drm_cvt_mode(dev, width, height,
1424 1.1.1.1.2.2 riastrad rates[j], j == 0,
1425 1.1.1.1.2.2 riastrad false, false);
1426 1.1.1.1.2.2 riastrad if (newmode) {
1427 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, newmode);
1428 1.1.1.1.2.2 riastrad modes++;
1429 1.1.1.1.2.2 riastrad }
1430 1.1.1.1.2.2 riastrad }
1431 1.1.1.1.2.2 riastrad }
1432 1.1.1.1.2.2 riastrad }
1433 1.1.1.1.2.2 riastrad
1434 1.1.1.1.2.2 riastrad return modes;
1435 1.1.1.1.2.2 riastrad }
1436 1.1.1.1.2.2 riastrad
1437 1.1.1.1.2.2 riastrad static void
1438 1.1.1.1.2.2 riastrad do_cvt_mode(struct detailed_timing *timing, void *c)
1439 1.1.1.1.2.2 riastrad {
1440 1.1.1.1.2.2 riastrad struct detailed_mode_closure *closure = c;
1441 1.1.1.1.2.2 riastrad struct detailed_non_pixel *data = &timing->data.other_data;
1442 1.1.1.1.2.2 riastrad
1443 1.1.1.1.2.2 riastrad if (data->type == EDID_DETAIL_CVT_3BYTE)
1444 1.1.1.1.2.2 riastrad closure->modes += drm_cvt_modes(closure->connector, timing);
1445 1.1.1.1.2.2 riastrad }
1446 1.1.1.1.2.2 riastrad
1447 1.1.1.1.2.2 riastrad static int
1448 1.1.1.1.2.2 riastrad add_cvt_modes(struct drm_connector *connector, struct edid *edid)
1449 1.1.1.1.2.2 riastrad {
1450 1.1.1.1.2.2 riastrad struct detailed_mode_closure closure = {
1451 1.1.1.1.2.2 riastrad connector, edid, 0, 0, 0
1452 1.1.1.1.2.2 riastrad };
1453 1.1.1.1.2.2 riastrad
1454 1.1.1.1.2.2 riastrad if (version_greater(edid, 1, 2))
1455 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
1456 1.1.1.1.2.2 riastrad
1457 1.1.1.1.2.2 riastrad /* XXX should also look for CVT codes in VTB blocks */
1458 1.1.1.1.2.2 riastrad
1459 1.1.1.1.2.2 riastrad return closure.modes;
1460 1.1.1.1.2.2 riastrad }
1461 1.1.1.1.2.2 riastrad
1462 1.1.1.1.2.2 riastrad static void
1463 1.1.1.1.2.2 riastrad do_detailed_mode(struct detailed_timing *timing, void *c)
1464 1.1.1.1.2.2 riastrad {
1465 1.1.1.1.2.2 riastrad struct detailed_mode_closure *closure = c;
1466 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1467 1.1.1.1.2.2 riastrad
1468 1.1.1.1.2.2 riastrad if (timing->pixel_clock) {
1469 1.1.1.1.2.2 riastrad newmode = drm_mode_detailed(closure->connector->dev,
1470 1.1.1.1.2.2 riastrad closure->edid, timing,
1471 1.1.1.1.2.2 riastrad closure->quirks);
1472 1.1.1.1.2.2 riastrad if (!newmode)
1473 1.1.1.1.2.2 riastrad return;
1474 1.1.1.1.2.2 riastrad
1475 1.1.1.1.2.2 riastrad if (closure->preferred)
1476 1.1.1.1.2.2 riastrad newmode->type |= DRM_MODE_TYPE_PREFERRED;
1477 1.1.1.1.2.2 riastrad
1478 1.1.1.1.2.2 riastrad drm_mode_probed_add(closure->connector, newmode);
1479 1.1.1.1.2.2 riastrad closure->modes++;
1480 1.1.1.1.2.2 riastrad closure->preferred = 0;
1481 1.1.1.1.2.2 riastrad }
1482 1.1.1.1.2.2 riastrad }
1483 1.1.1.1.2.2 riastrad
1484 1.1.1.1.2.2 riastrad /*
1485 1.1.1.1.2.2 riastrad * add_detailed_modes - Add modes from detailed timings
1486 1.1.1.1.2.2 riastrad * @connector: attached connector
1487 1.1.1.1.2.2 riastrad * @edid: EDID block to scan
1488 1.1.1.1.2.2 riastrad * @quirks: quirks to apply
1489 1.1.1.1.2.2 riastrad */
1490 1.1.1.1.2.2 riastrad static int
1491 1.1.1.1.2.2 riastrad add_detailed_modes(struct drm_connector *connector, struct edid *edid,
1492 1.1.1.1.2.2 riastrad u32 quirks)
1493 1.1.1.1.2.2 riastrad {
1494 1.1.1.1.2.2 riastrad struct detailed_mode_closure closure = {
1495 1.1.1.1.2.2 riastrad connector,
1496 1.1.1.1.2.2 riastrad edid,
1497 1.1.1.1.2.2 riastrad 1,
1498 1.1.1.1.2.2 riastrad quirks,
1499 1.1.1.1.2.2 riastrad 0
1500 1.1.1.1.2.2 riastrad };
1501 1.1.1.1.2.2 riastrad
1502 1.1.1.1.2.2 riastrad if (closure.preferred && !version_greater(edid, 1, 3))
1503 1.1.1.1.2.2 riastrad closure.preferred =
1504 1.1.1.1.2.2 riastrad (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
1505 1.1.1.1.2.2 riastrad
1506 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
1507 1.1.1.1.2.2 riastrad
1508 1.1.1.1.2.2 riastrad return closure.modes;
1509 1.1.1.1.2.2 riastrad }
1510 1.1.1.1.2.2 riastrad
1511 1.1.1.1.2.2 riastrad #define HDMI_IDENTIFIER 0x000C03
1512 1.1.1.1.2.2 riastrad #define AUDIO_BLOCK 0x01
1513 1.1.1.1.2.2 riastrad #define VIDEO_BLOCK 0x02
1514 1.1.1.1.2.2 riastrad #define VENDOR_BLOCK 0x03
1515 1.1.1.1.2.2 riastrad #define SPEAKER_BLOCK 0x04
1516 1.1.1.1.2.2 riastrad #define EDID_BASIC_AUDIO (1 << 6)
1517 1.1.1.1.2.2 riastrad #define EDID_CEA_YCRCB444 (1 << 5)
1518 1.1.1.1.2.2 riastrad #define EDID_CEA_YCRCB422 (1 << 4)
1519 1.1.1.1.2.2 riastrad
1520 1.1.1.1.2.2 riastrad /**
1521 1.1.1.1.2.2 riastrad * Search EDID for CEA extension block.
1522 1.1.1.1.2.2 riastrad */
1523 1.1.1.1.2.2 riastrad u8 *drm_find_cea_extension(struct edid *edid)
1524 1.1.1.1.2.2 riastrad {
1525 1.1.1.1.2.2 riastrad u8 *edid_ext = NULL;
1526 1.1.1.1.2.2 riastrad int i;
1527 1.1.1.1.2.2 riastrad
1528 1.1.1.1.2.2 riastrad /* No EDID or EDID extensions */
1529 1.1.1.1.2.2 riastrad if (edid == NULL || edid->extensions == 0)
1530 1.1.1.1.2.2 riastrad return NULL;
1531 1.1.1.1.2.2 riastrad
1532 1.1.1.1.2.2 riastrad /* Find CEA extension */
1533 1.1.1.1.2.2 riastrad for (i = 0; i < edid->extensions; i++) {
1534 1.1.1.1.2.2 riastrad edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
1535 1.1.1.1.2.2 riastrad if (edid_ext[0] == CEA_EXT)
1536 1.1.1.1.2.2 riastrad break;
1537 1.1.1.1.2.2 riastrad }
1538 1.1.1.1.2.2 riastrad
1539 1.1.1.1.2.2 riastrad if (i == edid->extensions)
1540 1.1.1.1.2.2 riastrad return NULL;
1541 1.1.1.1.2.2 riastrad
1542 1.1.1.1.2.2 riastrad return edid_ext;
1543 1.1.1.1.2.2 riastrad }
1544 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_find_cea_extension);
1545 1.1.1.1.2.2 riastrad
1546 1.1.1.1.2.2 riastrad /*
1547 1.1.1.1.2.2 riastrad * Looks for a CEA mode matching given drm_display_mode.
1548 1.1.1.1.2.2 riastrad * Returns its CEA Video ID code, or 0 if not found.
1549 1.1.1.1.2.2 riastrad */
1550 1.1.1.1.2.2 riastrad u8 drm_match_cea_mode(struct drm_display_mode *to_match)
1551 1.1.1.1.2.2 riastrad {
1552 1.1.1.1.2.8 riastrad #ifdef __NetBSD__
1553 1.1.1.1.2.8 riastrad const struct drm_display_mode *cea_mode;
1554 1.1.1.1.2.8 riastrad #else
1555 1.1.1.1.2.2 riastrad struct drm_display_mode *cea_mode;
1556 1.1.1.1.2.8 riastrad #endif
1557 1.1.1.1.2.2 riastrad u8 mode;
1558 1.1.1.1.2.2 riastrad
1559 1.1.1.1.2.2 riastrad for (mode = 0; mode < drm_num_cea_modes; mode++) {
1560 1.1.1.1.2.8 riastrad #ifdef __NetBSD__
1561 1.1.1.1.2.8 riastrad cea_mode = &edid_cea_modes[mode];
1562 1.1.1.1.2.8 riastrad #else
1563 1.1.1.1.2.2 riastrad cea_mode = (struct drm_display_mode *)&edid_cea_modes[mode];
1564 1.1.1.1.2.8 riastrad #endif
1565 1.1.1.1.2.2 riastrad
1566 1.1.1.1.2.2 riastrad if (drm_mode_equal(to_match, cea_mode))
1567 1.1.1.1.2.2 riastrad return mode + 1;
1568 1.1.1.1.2.2 riastrad }
1569 1.1.1.1.2.2 riastrad return 0;
1570 1.1.1.1.2.2 riastrad }
1571 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_match_cea_mode);
1572 1.1.1.1.2.2 riastrad
1573 1.1.1.1.2.2 riastrad
1574 1.1.1.1.2.2 riastrad static int
1575 1.1.1.1.2.2 riastrad do_cea_modes (struct drm_connector *connector, u8 *db, u8 len)
1576 1.1.1.1.2.2 riastrad {
1577 1.1.1.1.2.2 riastrad struct drm_device *dev = connector->dev;
1578 1.1.1.1.2.2 riastrad u8 * mode, cea_mode;
1579 1.1.1.1.2.2 riastrad int modes = 0;
1580 1.1.1.1.2.2 riastrad
1581 1.1.1.1.2.2 riastrad for (mode = db; mode < db + len; mode++) {
1582 1.1.1.1.2.2 riastrad cea_mode = (*mode & 127) - 1; /* CEA modes are numbered 1..127 */
1583 1.1.1.1.2.2 riastrad if (cea_mode < drm_num_cea_modes) {
1584 1.1.1.1.2.2 riastrad struct drm_display_mode *newmode;
1585 1.1.1.1.2.2 riastrad newmode = drm_mode_duplicate(dev,
1586 1.1.1.1.2.2 riastrad &edid_cea_modes[cea_mode]);
1587 1.1.1.1.2.2 riastrad if (newmode) {
1588 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, newmode);
1589 1.1.1.1.2.2 riastrad modes++;
1590 1.1.1.1.2.2 riastrad }
1591 1.1.1.1.2.2 riastrad }
1592 1.1.1.1.2.2 riastrad }
1593 1.1.1.1.2.2 riastrad
1594 1.1.1.1.2.2 riastrad return modes;
1595 1.1.1.1.2.2 riastrad }
1596 1.1.1.1.2.2 riastrad
1597 1.1.1.1.2.2 riastrad static int
1598 1.1.1.1.2.2 riastrad cea_db_payload_len(const u8 *db)
1599 1.1.1.1.2.2 riastrad {
1600 1.1.1.1.2.2 riastrad return db[0] & 0x1f;
1601 1.1.1.1.2.2 riastrad }
1602 1.1.1.1.2.2 riastrad
1603 1.1.1.1.2.2 riastrad static int
1604 1.1.1.1.2.2 riastrad cea_db_tag(const u8 *db)
1605 1.1.1.1.2.2 riastrad {
1606 1.1.1.1.2.2 riastrad return db[0] >> 5;
1607 1.1.1.1.2.2 riastrad }
1608 1.1.1.1.2.2 riastrad
1609 1.1.1.1.2.2 riastrad static int
1610 1.1.1.1.2.2 riastrad cea_revision(const u8 *cea)
1611 1.1.1.1.2.2 riastrad {
1612 1.1.1.1.2.2 riastrad return cea[1];
1613 1.1.1.1.2.2 riastrad }
1614 1.1.1.1.2.2 riastrad
1615 1.1.1.1.2.2 riastrad static int
1616 1.1.1.1.2.2 riastrad cea_db_offsets(const u8 *cea, int *start, int *end)
1617 1.1.1.1.2.2 riastrad {
1618 1.1.1.1.2.2 riastrad /* Data block offset in CEA extension block */
1619 1.1.1.1.2.2 riastrad *start = 4;
1620 1.1.1.1.2.2 riastrad *end = cea[2];
1621 1.1.1.1.2.2 riastrad if (*end == 0)
1622 1.1.1.1.2.2 riastrad *end = 127;
1623 1.1.1.1.2.2 riastrad if (*end < 4 || *end > 127)
1624 1.1.1.1.2.2 riastrad return -ERANGE;
1625 1.1.1.1.2.2 riastrad return 0;
1626 1.1.1.1.2.2 riastrad }
1627 1.1.1.1.2.2 riastrad
1628 1.1.1.1.2.2 riastrad #define for_each_cea_db(cea, i, start, end) \
1629 1.1.1.1.2.2 riastrad for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
1630 1.1.1.1.2.2 riastrad
1631 1.1.1.1.2.2 riastrad static int
1632 1.1.1.1.2.2 riastrad add_cea_modes(struct drm_connector *connector, struct edid *edid)
1633 1.1.1.1.2.2 riastrad {
1634 1.1.1.1.2.2 riastrad u8 * cea = drm_find_cea_extension(edid);
1635 1.1.1.1.2.2 riastrad u8 * db, dbl;
1636 1.1.1.1.2.2 riastrad int modes = 0;
1637 1.1.1.1.2.2 riastrad
1638 1.1.1.1.2.2 riastrad if (cea && cea_revision(cea) >= 3) {
1639 1.1.1.1.2.2 riastrad int i, start, end;
1640 1.1.1.1.2.2 riastrad
1641 1.1.1.1.2.2 riastrad if (cea_db_offsets(cea, &start, &end))
1642 1.1.1.1.2.2 riastrad return 0;
1643 1.1.1.1.2.2 riastrad
1644 1.1.1.1.2.2 riastrad for_each_cea_db(cea, i, start, end) {
1645 1.1.1.1.2.2 riastrad db = &cea[i];
1646 1.1.1.1.2.2 riastrad dbl = cea_db_payload_len(db);
1647 1.1.1.1.2.2 riastrad
1648 1.1.1.1.2.2 riastrad if (cea_db_tag(db) == VIDEO_BLOCK)
1649 1.1.1.1.2.2 riastrad modes += do_cea_modes (connector, db+1, dbl);
1650 1.1.1.1.2.2 riastrad }
1651 1.1.1.1.2.2 riastrad }
1652 1.1.1.1.2.2 riastrad
1653 1.1.1.1.2.2 riastrad return modes;
1654 1.1.1.1.2.2 riastrad }
1655 1.1.1.1.2.2 riastrad
1656 1.1.1.1.2.2 riastrad static void
1657 1.1.1.1.2.2 riastrad parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db)
1658 1.1.1.1.2.2 riastrad {
1659 1.1.1.1.2.2 riastrad u8 len = cea_db_payload_len(db);
1660 1.1.1.1.2.2 riastrad
1661 1.1.1.1.2.2 riastrad if (len >= 6) {
1662 1.1.1.1.2.2 riastrad connector->eld[5] |= (db[6] >> 7) << 1; /* Supports_AI */
1663 1.1.1.1.2.2 riastrad connector->dvi_dual = db[6] & 1;
1664 1.1.1.1.2.2 riastrad }
1665 1.1.1.1.2.2 riastrad if (len >= 7)
1666 1.1.1.1.2.2 riastrad connector->max_tmds_clock = db[7] * 5;
1667 1.1.1.1.2.2 riastrad if (len >= 8) {
1668 1.1.1.1.2.2 riastrad connector->latency_present[0] = db[8] >> 7;
1669 1.1.1.1.2.2 riastrad connector->latency_present[1] = (db[8] >> 6) & 1;
1670 1.1.1.1.2.2 riastrad }
1671 1.1.1.1.2.2 riastrad if (len >= 9)
1672 1.1.1.1.2.2 riastrad connector->video_latency[0] = db[9];
1673 1.1.1.1.2.2 riastrad if (len >= 10)
1674 1.1.1.1.2.2 riastrad connector->audio_latency[0] = db[10];
1675 1.1.1.1.2.2 riastrad if (len >= 11)
1676 1.1.1.1.2.2 riastrad connector->video_latency[1] = db[11];
1677 1.1.1.1.2.2 riastrad if (len >= 12)
1678 1.1.1.1.2.2 riastrad connector->audio_latency[1] = db[12];
1679 1.1.1.1.2.2 riastrad
1680 1.1.1.1.2.2 riastrad DRM_DEBUG_KMS("HDMI: DVI dual %d, "
1681 1.1.1.1.2.2 riastrad "max TMDS clock %d, "
1682 1.1.1.1.2.2 riastrad "latency present %d %d, "
1683 1.1.1.1.2.2 riastrad "video latency %d %d, "
1684 1.1.1.1.2.2 riastrad "audio latency %d %d\n",
1685 1.1.1.1.2.2 riastrad connector->dvi_dual,
1686 1.1.1.1.2.2 riastrad connector->max_tmds_clock,
1687 1.1.1.1.2.2 riastrad (int) connector->latency_present[0],
1688 1.1.1.1.2.2 riastrad (int) connector->latency_present[1],
1689 1.1.1.1.2.2 riastrad connector->video_latency[0],
1690 1.1.1.1.2.2 riastrad connector->video_latency[1],
1691 1.1.1.1.2.2 riastrad connector->audio_latency[0],
1692 1.1.1.1.2.2 riastrad connector->audio_latency[1]);
1693 1.1.1.1.2.2 riastrad }
1694 1.1.1.1.2.2 riastrad
1695 1.1.1.1.2.2 riastrad static void
1696 1.1.1.1.2.2 riastrad monitor_name(struct detailed_timing *t, void *data)
1697 1.1.1.1.2.2 riastrad {
1698 1.1.1.1.2.2 riastrad if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
1699 1.1.1.1.2.2 riastrad *(u8 **)data = t->data.other_data.data.str.str;
1700 1.1.1.1.2.2 riastrad }
1701 1.1.1.1.2.2 riastrad
1702 1.1.1.1.2.2 riastrad static bool cea_db_is_hdmi_vsdb(const u8 *db)
1703 1.1.1.1.2.2 riastrad {
1704 1.1.1.1.2.2 riastrad int hdmi_id;
1705 1.1.1.1.2.2 riastrad
1706 1.1.1.1.2.2 riastrad if (cea_db_tag(db) != VENDOR_BLOCK)
1707 1.1.1.1.2.2 riastrad return false;
1708 1.1.1.1.2.2 riastrad
1709 1.1.1.1.2.2 riastrad if (cea_db_payload_len(db) < 5)
1710 1.1.1.1.2.2 riastrad return false;
1711 1.1.1.1.2.2 riastrad
1712 1.1.1.1.2.2 riastrad hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
1713 1.1.1.1.2.2 riastrad
1714 1.1.1.1.2.2 riastrad return hdmi_id == HDMI_IDENTIFIER;
1715 1.1.1.1.2.2 riastrad }
1716 1.1.1.1.2.2 riastrad
1717 1.1.1.1.2.2 riastrad /**
1718 1.1.1.1.2.2 riastrad * drm_edid_to_eld - build ELD from EDID
1719 1.1.1.1.2.2 riastrad * @connector: connector corresponding to the HDMI/DP sink
1720 1.1.1.1.2.2 riastrad * @edid: EDID to parse
1721 1.1.1.1.2.2 riastrad *
1722 1.1.1.1.2.2 riastrad * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver.
1723 1.1.1.1.2.2 riastrad * Some ELD fields are left to the graphics driver caller:
1724 1.1.1.1.2.2 riastrad * - Conn_Type
1725 1.1.1.1.2.2 riastrad * - HDCP
1726 1.1.1.1.2.2 riastrad * - Port_ID
1727 1.1.1.1.2.2 riastrad */
1728 1.1.1.1.2.2 riastrad void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
1729 1.1.1.1.2.2 riastrad {
1730 1.1.1.1.2.2 riastrad uint8_t *eld = connector->eld;
1731 1.1.1.1.2.2 riastrad u8 *cea;
1732 1.1.1.1.2.2 riastrad u8 *name;
1733 1.1.1.1.2.2 riastrad u8 *db;
1734 1.1.1.1.2.2 riastrad int sad_count = 0;
1735 1.1.1.1.2.2 riastrad int mnl;
1736 1.1.1.1.2.2 riastrad int dbl;
1737 1.1.1.1.2.2 riastrad
1738 1.1.1.1.2.2 riastrad memset(eld, 0, sizeof(connector->eld));
1739 1.1.1.1.2.2 riastrad
1740 1.1.1.1.2.2 riastrad cea = drm_find_cea_extension(edid);
1741 1.1.1.1.2.2 riastrad if (!cea) {
1742 1.1.1.1.2.2 riastrad DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
1743 1.1.1.1.2.2 riastrad return;
1744 1.1.1.1.2.2 riastrad }
1745 1.1.1.1.2.2 riastrad
1746 1.1.1.1.2.2 riastrad name = NULL;
1747 1.1.1.1.2.2 riastrad drm_for_each_detailed_block((u8 *)edid, monitor_name, &name);
1748 1.1.1.1.2.2 riastrad for (mnl = 0; name && mnl < 13; mnl++) {
1749 1.1.1.1.2.2 riastrad if (name[mnl] == 0x0a)
1750 1.1.1.1.2.2 riastrad break;
1751 1.1.1.1.2.2 riastrad eld[20 + mnl] = name[mnl];
1752 1.1.1.1.2.2 riastrad }
1753 1.1.1.1.2.2 riastrad eld[4] = (cea[1] << 5) | mnl;
1754 1.1.1.1.2.2 riastrad DRM_DEBUG_KMS("ELD monitor %s\n", eld + 20);
1755 1.1.1.1.2.2 riastrad
1756 1.1.1.1.2.2 riastrad eld[0] = 2 << 3; /* ELD version: 2 */
1757 1.1.1.1.2.2 riastrad
1758 1.1.1.1.2.2 riastrad eld[16] = edid->mfg_id[0];
1759 1.1.1.1.2.2 riastrad eld[17] = edid->mfg_id[1];
1760 1.1.1.1.2.2 riastrad eld[18] = edid->prod_code[0];
1761 1.1.1.1.2.2 riastrad eld[19] = edid->prod_code[1];
1762 1.1.1.1.2.2 riastrad
1763 1.1.1.1.2.2 riastrad if (cea_revision(cea) >= 3) {
1764 1.1.1.1.2.2 riastrad int i, start, end;
1765 1.1.1.1.2.2 riastrad
1766 1.1.1.1.2.2 riastrad if (cea_db_offsets(cea, &start, &end)) {
1767 1.1.1.1.2.2 riastrad start = 0;
1768 1.1.1.1.2.2 riastrad end = 0;
1769 1.1.1.1.2.2 riastrad }
1770 1.1.1.1.2.2 riastrad
1771 1.1.1.1.2.2 riastrad for_each_cea_db(cea, i, start, end) {
1772 1.1.1.1.2.2 riastrad db = &cea[i];
1773 1.1.1.1.2.2 riastrad dbl = cea_db_payload_len(db);
1774 1.1.1.1.2.2 riastrad
1775 1.1.1.1.2.2 riastrad switch (cea_db_tag(db)) {
1776 1.1.1.1.2.2 riastrad case AUDIO_BLOCK:
1777 1.1.1.1.2.2 riastrad /* Audio Data Block, contains SADs */
1778 1.1.1.1.2.2 riastrad sad_count = dbl / 3;
1779 1.1.1.1.2.2 riastrad if (dbl >= 1)
1780 1.1.1.1.2.2 riastrad memcpy(eld + 20 + mnl, &db[1], dbl);
1781 1.1.1.1.2.2 riastrad break;
1782 1.1.1.1.2.2 riastrad case SPEAKER_BLOCK:
1783 1.1.1.1.2.2 riastrad /* Speaker Allocation Data Block */
1784 1.1.1.1.2.2 riastrad if (dbl >= 1)
1785 1.1.1.1.2.2 riastrad eld[7] = db[1];
1786 1.1.1.1.2.2 riastrad break;
1787 1.1.1.1.2.2 riastrad case VENDOR_BLOCK:
1788 1.1.1.1.2.2 riastrad /* HDMI Vendor-Specific Data Block */
1789 1.1.1.1.2.2 riastrad if (cea_db_is_hdmi_vsdb(db))
1790 1.1.1.1.2.2 riastrad parse_hdmi_vsdb(connector, db);
1791 1.1.1.1.2.2 riastrad break;
1792 1.1.1.1.2.2 riastrad default:
1793 1.1.1.1.2.2 riastrad break;
1794 1.1.1.1.2.2 riastrad }
1795 1.1.1.1.2.2 riastrad }
1796 1.1.1.1.2.2 riastrad }
1797 1.1.1.1.2.2 riastrad eld[5] |= sad_count << 4;
1798 1.1.1.1.2.2 riastrad eld[2] = (20 + mnl + sad_count * 3 + 3) / 4;
1799 1.1.1.1.2.2 riastrad
1800 1.1.1.1.2.2 riastrad DRM_DEBUG_KMS("ELD size %d, SAD count %d\n", (int)eld[2], sad_count);
1801 1.1.1.1.2.2 riastrad }
1802 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_edid_to_eld);
1803 1.1.1.1.2.2 riastrad
1804 1.1.1.1.2.2 riastrad /**
1805 1.1.1.1.2.2 riastrad * drm_av_sync_delay - HDMI/DP sink audio-video sync delay in millisecond
1806 1.1.1.1.2.2 riastrad * @connector: connector associated with the HDMI/DP sink
1807 1.1.1.1.2.2 riastrad * @mode: the display mode
1808 1.1.1.1.2.2 riastrad */
1809 1.1.1.1.2.2 riastrad int drm_av_sync_delay(struct drm_connector *connector,
1810 1.1.1.1.2.2 riastrad struct drm_display_mode *mode)
1811 1.1.1.1.2.2 riastrad {
1812 1.1.1.1.2.2 riastrad int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
1813 1.1.1.1.2.2 riastrad int a, v;
1814 1.1.1.1.2.2 riastrad
1815 1.1.1.1.2.2 riastrad if (!connector->latency_present[0])
1816 1.1.1.1.2.2 riastrad return 0;
1817 1.1.1.1.2.2 riastrad if (!connector->latency_present[1])
1818 1.1.1.1.2.2 riastrad i = 0;
1819 1.1.1.1.2.2 riastrad
1820 1.1.1.1.2.2 riastrad a = connector->audio_latency[i];
1821 1.1.1.1.2.2 riastrad v = connector->video_latency[i];
1822 1.1.1.1.2.2 riastrad
1823 1.1.1.1.2.2 riastrad /*
1824 1.1.1.1.2.2 riastrad * HDMI/DP sink doesn't support audio or video?
1825 1.1.1.1.2.2 riastrad */
1826 1.1.1.1.2.2 riastrad if (a == 255 || v == 255)
1827 1.1.1.1.2.2 riastrad return 0;
1828 1.1.1.1.2.2 riastrad
1829 1.1.1.1.2.2 riastrad /*
1830 1.1.1.1.2.2 riastrad * Convert raw EDID values to millisecond.
1831 1.1.1.1.2.2 riastrad * Treat unknown latency as 0ms.
1832 1.1.1.1.2.2 riastrad */
1833 1.1.1.1.2.2 riastrad if (a)
1834 1.1.1.1.2.2 riastrad a = min(2 * (a - 1), 500);
1835 1.1.1.1.2.2 riastrad if (v)
1836 1.1.1.1.2.2 riastrad v = min(2 * (v - 1), 500);
1837 1.1.1.1.2.2 riastrad
1838 1.1.1.1.2.2 riastrad return max(v - a, 0);
1839 1.1.1.1.2.2 riastrad }
1840 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_av_sync_delay);
1841 1.1.1.1.2.2 riastrad
1842 1.1.1.1.2.2 riastrad /**
1843 1.1.1.1.2.2 riastrad * drm_select_eld - select one ELD from multiple HDMI/DP sinks
1844 1.1.1.1.2.2 riastrad * @encoder: the encoder just changed display mode
1845 1.1.1.1.2.2 riastrad * @mode: the adjusted display mode
1846 1.1.1.1.2.2 riastrad *
1847 1.1.1.1.2.2 riastrad * It's possible for one encoder to be associated with multiple HDMI/DP sinks.
1848 1.1.1.1.2.2 riastrad * The policy is now hard coded to simply use the first HDMI/DP sink's ELD.
1849 1.1.1.1.2.2 riastrad */
1850 1.1.1.1.2.2 riastrad struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
1851 1.1.1.1.2.2 riastrad struct drm_display_mode *mode)
1852 1.1.1.1.2.2 riastrad {
1853 1.1.1.1.2.2 riastrad struct drm_connector *connector;
1854 1.1.1.1.2.2 riastrad struct drm_device *dev = encoder->dev;
1855 1.1.1.1.2.2 riastrad
1856 1.1.1.1.2.2 riastrad list_for_each_entry(connector, &dev->mode_config.connector_list, head)
1857 1.1.1.1.2.2 riastrad if (connector->encoder == encoder && connector->eld[0])
1858 1.1.1.1.2.2 riastrad return connector;
1859 1.1.1.1.2.2 riastrad
1860 1.1.1.1.2.2 riastrad return NULL;
1861 1.1.1.1.2.2 riastrad }
1862 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_select_eld);
1863 1.1.1.1.2.2 riastrad
1864 1.1.1.1.2.2 riastrad /**
1865 1.1.1.1.2.2 riastrad * drm_detect_hdmi_monitor - detect whether monitor is hdmi.
1866 1.1.1.1.2.2 riastrad * @edid: monitor EDID information
1867 1.1.1.1.2.2 riastrad *
1868 1.1.1.1.2.2 riastrad * Parse the CEA extension according to CEA-861-B.
1869 1.1.1.1.2.2 riastrad * Return true if HDMI, false if not or unknown.
1870 1.1.1.1.2.2 riastrad */
1871 1.1.1.1.2.2 riastrad bool drm_detect_hdmi_monitor(struct edid *edid)
1872 1.1.1.1.2.2 riastrad {
1873 1.1.1.1.2.2 riastrad u8 *edid_ext;
1874 1.1.1.1.2.2 riastrad int i;
1875 1.1.1.1.2.2 riastrad int start_offset, end_offset;
1876 1.1.1.1.2.2 riastrad
1877 1.1.1.1.2.2 riastrad edid_ext = drm_find_cea_extension(edid);
1878 1.1.1.1.2.2 riastrad if (!edid_ext)
1879 1.1.1.1.2.2 riastrad return false;
1880 1.1.1.1.2.2 riastrad
1881 1.1.1.1.2.2 riastrad if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
1882 1.1.1.1.2.2 riastrad return false;
1883 1.1.1.1.2.2 riastrad
1884 1.1.1.1.2.2 riastrad /*
1885 1.1.1.1.2.2 riastrad * Because HDMI identifier is in Vendor Specific Block,
1886 1.1.1.1.2.2 riastrad * search it from all data blocks of CEA extension.
1887 1.1.1.1.2.2 riastrad */
1888 1.1.1.1.2.2 riastrad for_each_cea_db(edid_ext, i, start_offset, end_offset) {
1889 1.1.1.1.2.2 riastrad if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
1890 1.1.1.1.2.2 riastrad return true;
1891 1.1.1.1.2.2 riastrad }
1892 1.1.1.1.2.2 riastrad
1893 1.1.1.1.2.2 riastrad return false;
1894 1.1.1.1.2.2 riastrad }
1895 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_detect_hdmi_monitor);
1896 1.1.1.1.2.2 riastrad
1897 1.1.1.1.2.2 riastrad /**
1898 1.1.1.1.2.2 riastrad * drm_detect_monitor_audio - check monitor audio capability
1899 1.1.1.1.2.2 riastrad *
1900 1.1.1.1.2.2 riastrad * Monitor should have CEA extension block.
1901 1.1.1.1.2.2 riastrad * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
1902 1.1.1.1.2.2 riastrad * audio' only. If there is any audio extension block and supported
1903 1.1.1.1.2.2 riastrad * audio format, assume at least 'basic audio' support, even if 'basic
1904 1.1.1.1.2.2 riastrad * audio' is not defined in EDID.
1905 1.1.1.1.2.2 riastrad *
1906 1.1.1.1.2.2 riastrad */
1907 1.1.1.1.2.2 riastrad bool drm_detect_monitor_audio(struct edid *edid)
1908 1.1.1.1.2.2 riastrad {
1909 1.1.1.1.2.2 riastrad u8 *edid_ext;
1910 1.1.1.1.2.2 riastrad int i, j;
1911 1.1.1.1.2.2 riastrad bool has_audio = false;
1912 1.1.1.1.2.2 riastrad int start_offset, end_offset;
1913 1.1.1.1.2.2 riastrad
1914 1.1.1.1.2.2 riastrad edid_ext = drm_find_cea_extension(edid);
1915 1.1.1.1.2.2 riastrad if (!edid_ext)
1916 1.1.1.1.2.2 riastrad goto end;
1917 1.1.1.1.2.2 riastrad
1918 1.1.1.1.2.2 riastrad has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
1919 1.1.1.1.2.2 riastrad
1920 1.1.1.1.2.2 riastrad if (has_audio) {
1921 1.1.1.1.2.2 riastrad DRM_DEBUG_KMS("Monitor has basic audio support\n");
1922 1.1.1.1.2.2 riastrad goto end;
1923 1.1.1.1.2.2 riastrad }
1924 1.1.1.1.2.2 riastrad
1925 1.1.1.1.2.2 riastrad if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
1926 1.1.1.1.2.2 riastrad goto end;
1927 1.1.1.1.2.2 riastrad
1928 1.1.1.1.2.2 riastrad for_each_cea_db(edid_ext, i, start_offset, end_offset) {
1929 1.1.1.1.2.2 riastrad if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
1930 1.1.1.1.2.2 riastrad has_audio = true;
1931 1.1.1.1.2.2 riastrad for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
1932 1.1.1.1.2.2 riastrad DRM_DEBUG_KMS("CEA audio format %d\n",
1933 1.1.1.1.2.2 riastrad (edid_ext[i + j] >> 3) & 0xf);
1934 1.1.1.1.2.2 riastrad goto end;
1935 1.1.1.1.2.2 riastrad }
1936 1.1.1.1.2.2 riastrad }
1937 1.1.1.1.2.2 riastrad end:
1938 1.1.1.1.2.2 riastrad return has_audio;
1939 1.1.1.1.2.2 riastrad }
1940 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_detect_monitor_audio);
1941 1.1.1.1.2.2 riastrad
1942 1.1.1.1.2.2 riastrad /**
1943 1.1.1.1.2.2 riastrad * drm_add_display_info - pull display info out if present
1944 1.1.1.1.2.2 riastrad * @edid: EDID data
1945 1.1.1.1.2.2 riastrad * @info: display info (attached to connector)
1946 1.1.1.1.2.2 riastrad *
1947 1.1.1.1.2.2 riastrad * Grab any available display info and stuff it into the drm_display_info
1948 1.1.1.1.2.2 riastrad * structure that's part of the connector. Useful for tracking bpp and
1949 1.1.1.1.2.2 riastrad * color spaces.
1950 1.1.1.1.2.2 riastrad */
1951 1.1.1.1.2.2 riastrad static void drm_add_display_info(struct edid *edid,
1952 1.1.1.1.2.2 riastrad struct drm_display_info *info)
1953 1.1.1.1.2.2 riastrad {
1954 1.1.1.1.2.2 riastrad u8 *edid_ext;
1955 1.1.1.1.2.2 riastrad
1956 1.1.1.1.2.2 riastrad info->width_mm = edid->width_cm * 10;
1957 1.1.1.1.2.2 riastrad info->height_mm = edid->height_cm * 10;
1958 1.1.1.1.2.2 riastrad
1959 1.1.1.1.2.2 riastrad /* driver figures it out in this case */
1960 1.1.1.1.2.2 riastrad info->bpc = 0;
1961 1.1.1.1.2.2 riastrad info->color_formats = 0;
1962 1.1.1.1.2.2 riastrad
1963 1.1.1.1.2.2 riastrad if (edid->revision < 3)
1964 1.1.1.1.2.2 riastrad return;
1965 1.1.1.1.2.2 riastrad
1966 1.1.1.1.2.2 riastrad if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
1967 1.1.1.1.2.2 riastrad return;
1968 1.1.1.1.2.2 riastrad
1969 1.1.1.1.2.2 riastrad /* Get data from CEA blocks if present */
1970 1.1.1.1.2.2 riastrad edid_ext = drm_find_cea_extension(edid);
1971 1.1.1.1.2.2 riastrad if (edid_ext) {
1972 1.1.1.1.2.2 riastrad info->cea_rev = edid_ext[1];
1973 1.1.1.1.2.2 riastrad
1974 1.1.1.1.2.2 riastrad /* The existence of a CEA block should imply RGB support */
1975 1.1.1.1.2.2 riastrad info->color_formats = DRM_COLOR_FORMAT_RGB444;
1976 1.1.1.1.2.2 riastrad if (edid_ext[3] & EDID_CEA_YCRCB444)
1977 1.1.1.1.2.2 riastrad info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
1978 1.1.1.1.2.2 riastrad if (edid_ext[3] & EDID_CEA_YCRCB422)
1979 1.1.1.1.2.2 riastrad info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
1980 1.1.1.1.2.2 riastrad }
1981 1.1.1.1.2.2 riastrad
1982 1.1.1.1.2.2 riastrad /* Only defined for 1.4 with digital displays */
1983 1.1.1.1.2.2 riastrad if (edid->revision < 4)
1984 1.1.1.1.2.2 riastrad return;
1985 1.1.1.1.2.2 riastrad
1986 1.1.1.1.2.2 riastrad switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
1987 1.1.1.1.2.2 riastrad case DRM_EDID_DIGITAL_DEPTH_6:
1988 1.1.1.1.2.2 riastrad info->bpc = 6;
1989 1.1.1.1.2.2 riastrad break;
1990 1.1.1.1.2.2 riastrad case DRM_EDID_DIGITAL_DEPTH_8:
1991 1.1.1.1.2.2 riastrad info->bpc = 8;
1992 1.1.1.1.2.2 riastrad break;
1993 1.1.1.1.2.2 riastrad case DRM_EDID_DIGITAL_DEPTH_10:
1994 1.1.1.1.2.2 riastrad info->bpc = 10;
1995 1.1.1.1.2.2 riastrad break;
1996 1.1.1.1.2.2 riastrad case DRM_EDID_DIGITAL_DEPTH_12:
1997 1.1.1.1.2.2 riastrad info->bpc = 12;
1998 1.1.1.1.2.2 riastrad break;
1999 1.1.1.1.2.2 riastrad case DRM_EDID_DIGITAL_DEPTH_14:
2000 1.1.1.1.2.2 riastrad info->bpc = 14;
2001 1.1.1.1.2.2 riastrad break;
2002 1.1.1.1.2.2 riastrad case DRM_EDID_DIGITAL_DEPTH_16:
2003 1.1.1.1.2.2 riastrad info->bpc = 16;
2004 1.1.1.1.2.2 riastrad break;
2005 1.1.1.1.2.2 riastrad case DRM_EDID_DIGITAL_DEPTH_UNDEF:
2006 1.1.1.1.2.2 riastrad default:
2007 1.1.1.1.2.2 riastrad info->bpc = 0;
2008 1.1.1.1.2.2 riastrad break;
2009 1.1.1.1.2.2 riastrad }
2010 1.1.1.1.2.2 riastrad
2011 1.1.1.1.2.2 riastrad info->color_formats |= DRM_COLOR_FORMAT_RGB444;
2012 1.1.1.1.2.2 riastrad if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
2013 1.1.1.1.2.2 riastrad info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
2014 1.1.1.1.2.2 riastrad if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
2015 1.1.1.1.2.2 riastrad info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
2016 1.1.1.1.2.2 riastrad }
2017 1.1.1.1.2.2 riastrad
2018 1.1.1.1.2.2 riastrad /**
2019 1.1.1.1.2.2 riastrad * drm_add_edid_modes - add modes from EDID data, if available
2020 1.1.1.1.2.2 riastrad * @connector: connector we're probing
2021 1.1.1.1.2.2 riastrad * @edid: edid data
2022 1.1.1.1.2.2 riastrad *
2023 1.1.1.1.2.2 riastrad * Add the specified modes to the connector's mode list.
2024 1.1.1.1.2.2 riastrad *
2025 1.1.1.1.2.2 riastrad * Return number of modes added or 0 if we couldn't find any.
2026 1.1.1.1.2.2 riastrad */
2027 1.1.1.1.2.2 riastrad int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
2028 1.1.1.1.2.2 riastrad {
2029 1.1.1.1.2.2 riastrad int num_modes = 0;
2030 1.1.1.1.2.2 riastrad u32 quirks;
2031 1.1.1.1.2.2 riastrad
2032 1.1.1.1.2.2 riastrad if (edid == NULL) {
2033 1.1.1.1.2.2 riastrad return 0;
2034 1.1.1.1.2.2 riastrad }
2035 1.1.1.1.2.2 riastrad if (!drm_edid_is_valid(edid)) {
2036 1.1.1.1.2.2 riastrad dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
2037 1.1.1.1.2.2 riastrad drm_get_connector_name(connector));
2038 1.1.1.1.2.2 riastrad return 0;
2039 1.1.1.1.2.2 riastrad }
2040 1.1.1.1.2.2 riastrad
2041 1.1.1.1.2.2 riastrad quirks = edid_get_quirks(edid);
2042 1.1.1.1.2.2 riastrad
2043 1.1.1.1.2.2 riastrad /*
2044 1.1.1.1.2.2 riastrad * EDID spec says modes should be preferred in this order:
2045 1.1.1.1.2.2 riastrad * - preferred detailed mode
2046 1.1.1.1.2.2 riastrad * - other detailed modes from base block
2047 1.1.1.1.2.2 riastrad * - detailed modes from extension blocks
2048 1.1.1.1.2.2 riastrad * - CVT 3-byte code modes
2049 1.1.1.1.2.2 riastrad * - standard timing codes
2050 1.1.1.1.2.2 riastrad * - established timing codes
2051 1.1.1.1.2.2 riastrad * - modes inferred from GTF or CVT range information
2052 1.1.1.1.2.2 riastrad *
2053 1.1.1.1.2.2 riastrad * We get this pretty much right.
2054 1.1.1.1.2.2 riastrad *
2055 1.1.1.1.2.2 riastrad * XXX order for additional mode types in extension blocks?
2056 1.1.1.1.2.2 riastrad */
2057 1.1.1.1.2.2 riastrad num_modes += add_detailed_modes(connector, edid, quirks);
2058 1.1.1.1.2.2 riastrad num_modes += add_cvt_modes(connector, edid);
2059 1.1.1.1.2.2 riastrad num_modes += add_standard_modes(connector, edid);
2060 1.1.1.1.2.2 riastrad num_modes += add_established_modes(connector, edid);
2061 1.1.1.1.2.2 riastrad num_modes += add_inferred_modes(connector, edid);
2062 1.1.1.1.2.2 riastrad num_modes += add_cea_modes(connector, edid);
2063 1.1.1.1.2.2 riastrad
2064 1.1.1.1.2.2 riastrad if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
2065 1.1.1.1.2.2 riastrad edid_fixup_preferred(connector, quirks);
2066 1.1.1.1.2.2 riastrad
2067 1.1.1.1.2.2 riastrad drm_add_display_info(edid, &connector->display_info);
2068 1.1.1.1.2.2 riastrad
2069 1.1.1.1.2.2 riastrad return num_modes;
2070 1.1.1.1.2.2 riastrad }
2071 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_add_edid_modes);
2072 1.1.1.1.2.2 riastrad
2073 1.1.1.1.2.2 riastrad /**
2074 1.1.1.1.2.2 riastrad * drm_add_modes_noedid - add modes for the connectors without EDID
2075 1.1.1.1.2.2 riastrad * @connector: connector we're probing
2076 1.1.1.1.2.2 riastrad * @hdisplay: the horizontal display limit
2077 1.1.1.1.2.2 riastrad * @vdisplay: the vertical display limit
2078 1.1.1.1.2.2 riastrad *
2079 1.1.1.1.2.2 riastrad * Add the specified modes to the connector's mode list. Only when the
2080 1.1.1.1.2.2 riastrad * hdisplay/vdisplay is not beyond the given limit, it will be added.
2081 1.1.1.1.2.2 riastrad *
2082 1.1.1.1.2.2 riastrad * Return number of modes added or 0 if we couldn't find any.
2083 1.1.1.1.2.2 riastrad */
2084 1.1.1.1.2.2 riastrad int drm_add_modes_noedid(struct drm_connector *connector,
2085 1.1.1.1.2.2 riastrad int hdisplay, int vdisplay)
2086 1.1.1.1.2.2 riastrad {
2087 1.1.1.1.2.2 riastrad int i, count, num_modes = 0;
2088 1.1.1.1.2.2 riastrad struct drm_display_mode *mode;
2089 1.1.1.1.2.2 riastrad struct drm_device *dev = connector->dev;
2090 1.1.1.1.2.2 riastrad
2091 1.1.1.1.2.2 riastrad count = sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
2092 1.1.1.1.2.2 riastrad if (hdisplay < 0)
2093 1.1.1.1.2.2 riastrad hdisplay = 0;
2094 1.1.1.1.2.2 riastrad if (vdisplay < 0)
2095 1.1.1.1.2.2 riastrad vdisplay = 0;
2096 1.1.1.1.2.2 riastrad
2097 1.1.1.1.2.2 riastrad for (i = 0; i < count; i++) {
2098 1.1.1.1.2.2 riastrad const struct drm_display_mode *ptr = &drm_dmt_modes[i];
2099 1.1.1.1.2.2 riastrad if (hdisplay && vdisplay) {
2100 1.1.1.1.2.2 riastrad /*
2101 1.1.1.1.2.2 riastrad * Only when two are valid, they will be used to check
2102 1.1.1.1.2.2 riastrad * whether the mode should be added to the mode list of
2103 1.1.1.1.2.2 riastrad * the connector.
2104 1.1.1.1.2.2 riastrad */
2105 1.1.1.1.2.2 riastrad if (ptr->hdisplay > hdisplay ||
2106 1.1.1.1.2.2 riastrad ptr->vdisplay > vdisplay)
2107 1.1.1.1.2.2 riastrad continue;
2108 1.1.1.1.2.2 riastrad }
2109 1.1.1.1.2.2 riastrad if (drm_mode_vrefresh(ptr) > 61)
2110 1.1.1.1.2.2 riastrad continue;
2111 1.1.1.1.2.2 riastrad mode = drm_mode_duplicate(dev, ptr);
2112 1.1.1.1.2.2 riastrad if (mode) {
2113 1.1.1.1.2.2 riastrad drm_mode_probed_add(connector, mode);
2114 1.1.1.1.2.2 riastrad num_modes++;
2115 1.1.1.1.2.2 riastrad }
2116 1.1.1.1.2.2 riastrad }
2117 1.1.1.1.2.2 riastrad return num_modes;
2118 1.1.1.1.2.2 riastrad }
2119 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_add_modes_noedid);
2120 1.1.1.1.2.2 riastrad
2121 1.1.1.1.2.2 riastrad /**
2122 1.1.1.1.2.2 riastrad * drm_mode_cea_vic - return the CEA-861 VIC of a given mode
2123 1.1.1.1.2.2 riastrad * @mode: mode
2124 1.1.1.1.2.2 riastrad *
2125 1.1.1.1.2.2 riastrad * RETURNS:
2126 1.1.1.1.2.2 riastrad * The VIC number, 0 in case it's not a CEA-861 mode.
2127 1.1.1.1.2.2 riastrad */
2128 1.1.1.1.2.2 riastrad uint8_t drm_mode_cea_vic(const struct drm_display_mode *mode)
2129 1.1.1.1.2.2 riastrad {
2130 1.1.1.1.2.2 riastrad uint8_t i;
2131 1.1.1.1.2.2 riastrad
2132 1.1.1.1.2.2 riastrad for (i = 0; i < drm_num_cea_modes; i++)
2133 1.1.1.1.2.2 riastrad if (drm_mode_equal(mode, &edid_cea_modes[i]))
2134 1.1.1.1.2.2 riastrad return i + 1;
2135 1.1.1.1.2.2 riastrad
2136 1.1.1.1.2.2 riastrad return 0;
2137 1.1.1.1.2.2 riastrad }
2138 1.1.1.1.2.2 riastrad EXPORT_SYMBOL(drm_mode_cea_vic);
2139