Rev 1125 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1123 | serge | 1 | /* |
2 | * Copyright (c) 2006 Luc Verhaegen (quirks list) |
||
3 | * Copyright (c) 2007-2008 Intel Corporation |
||
4 | * Jesse Barnes |
||
5 | * |
||
6 | * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from |
||
7 | * FB layer. |
||
8 | * Copyright (C) 2006 Dennis Munsie |
||
9 | * |
||
10 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
11 | * copy of this software and associated documentation files (the "Software"), |
||
12 | * to deal in the Software without restriction, including without limitation |
||
13 | * the rights to use, copy, modify, merge, publish, distribute, sub license, |
||
14 | * and/or sell copies of the Software, and to permit persons to whom the |
||
15 | * Software is furnished to do so, subject to the following conditions: |
||
16 | * |
||
17 | * The above copyright notice and this permission notice (including the |
||
18 | * next paragraph) shall be included in all copies or substantial portions |
||
19 | * of the Software. |
||
20 | * |
||
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
24 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
27 | * DEALINGS IN THE SOFTWARE. |
||
28 | */ |
||
29 | //#include |
||
30 | //#include |
||
31 | //#include |
||
32 | #include "drmP.h" |
||
33 | #include "drm_edid.h" |
||
34 | |||
35 | |||
36 | |||
37 | |||
38 | /* |
||
39 | * TODO: |
||
40 | * - support EDID 1.4 (incl. CE blocks) |
||
41 | */ |
||
42 | |||
43 | /* |
||
44 | * EDID blocks out in the wild have a variety of bugs, try to collect |
||
45 | * them here (note that userspace may work around broken monitors first, |
||
46 | * but fixes should make their way here so that the kernel "just works" |
||
47 | * on as many displays as possible). |
||
48 | */ |
||
49 | |||
50 | /* First detailed mode wrong, use largest 60Hz mode */ |
||
51 | #define EDID_QUIRK_PREFER_LARGE_60 (1 << 0) |
||
52 | /* Reported 135MHz pixel clock is too high, needs adjustment */ |
||
53 | #define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1) |
||
54 | /* Prefer the largest mode at 75 Hz */ |
||
55 | #define EDID_QUIRK_PREFER_LARGE_75 (1 << 2) |
||
56 | /* Detail timing is in cm not mm */ |
||
57 | #define EDID_QUIRK_DETAILED_IN_CM (1 << 3) |
||
58 | /* Detailed timing descriptors have bogus size values, so just take the |
||
59 | * maximum size and use that. |
||
60 | */ |
||
61 | #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4) |
||
62 | /* Monitor forgot to set the first detailed is preferred bit. */ |
||
63 | #define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5) |
||
64 | /* use +hsync +vsync for detailed mode */ |
||
65 | #define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6) |
||
66 | |||
67 | static struct edid_quirk { |
||
68 | char *vendor; |
||
69 | int product_id; |
||
70 | u32 quirks; |
||
71 | } edid_quirk_list[] = { |
||
72 | /* Acer AL1706 */ |
||
73 | { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 }, |
||
74 | /* Acer F51 */ |
||
75 | { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 }, |
||
76 | /* Unknown Acer */ |
||
77 | { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED }, |
||
78 | |||
79 | /* Belinea 10 15 55 */ |
||
80 | { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 }, |
||
81 | { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 }, |
||
82 | |||
83 | /* Envision Peripherals, Inc. EN-7100e */ |
||
84 | { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH }, |
||
85 | |||
86 | /* Funai Electronics PM36B */ |
||
87 | { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 | |
||
88 | EDID_QUIRK_DETAILED_IN_CM }, |
||
89 | |||
90 | /* LG Philips LCD LP154W01-A5 */ |
||
91 | { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE }, |
||
92 | { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE }, |
||
93 | |||
94 | /* Philips 107p5 CRT */ |
||
95 | { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED }, |
||
96 | |||
97 | /* Proview AY765C */ |
||
98 | { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED }, |
||
99 | |||
100 | /* Samsung SyncMaster 205BW. Note: irony */ |
||
101 | { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP }, |
||
102 | /* Samsung SyncMaster 22[5-6]BW */ |
||
103 | { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 }, |
||
104 | { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 }, |
||
105 | }; |
||
106 | |||
107 | |||
108 | /* Valid EDID header has these bytes */ |
||
109 | static u8 edid_header[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; |
||
110 | |||
111 | /** |
||
112 | * edid_is_valid - sanity check EDID data |
||
113 | * @edid: EDID data |
||
114 | * |
||
115 | * Sanity check the EDID block by looking at the header, the version number |
||
116 | * and the checksum. Return 0 if the EDID doesn't check out, or 1 if it's |
||
117 | * valid. |
||
118 | */ |
||
119 | static bool edid_is_valid(struct edid *edid) |
||
120 | { |
||
121 | int i; |
||
122 | u8 csum = 0; |
||
123 | u8 *raw_edid = (u8 *)edid; |
||
124 | |||
125 | if (memcmp(edid->header, edid_header, sizeof(edid_header))) |
||
126 | goto bad; |
||
127 | if (edid->version != 1) { |
||
128 | DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version); |
||
129 | goto bad; |
||
130 | } |
||
131 | if (edid->revision > 4) |
||
132 | DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n"); |
||
133 | |||
134 | for (i = 0; i < EDID_LENGTH; i++) |
||
135 | csum += raw_edid[i]; |
||
136 | if (csum) { |
||
137 | DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum); |
||
138 | goto bad; |
||
139 | } |
||
140 | |||
141 | return 1; |
||
142 | |||
143 | bad: |
||
144 | if (raw_edid) { |
||
145 | DRM_ERROR("Raw EDID:\n"); |
||
146 | // print_hex_dump_bytes(KERN_ERR, DUMP_PREFIX_NONE, raw_edid, EDID_LENGTH); |
||
147 | // printk("\n"); |
||
148 | } |
||
149 | return 0; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * edid_vendor - match a string against EDID's obfuscated vendor field |
||
154 | * @edid: EDID to match |
||
155 | * @vendor: vendor string |
||
156 | * |
||
157 | * Returns true if @vendor is in @edid, false otherwise |
||
158 | */ |
||
159 | static bool edid_vendor(struct edid *edid, char *vendor) |
||
160 | { |
||
161 | char edid_vendor[3]; |
||
162 | |||
163 | edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@'; |
||
164 | edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) | |
||
165 | ((edid->mfg_id[1] & 0xe0) >> 5)) + '@'; |
||
166 | edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@'; |
||
167 | |||
168 | return !strncmp(edid_vendor, vendor, 3); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * edid_get_quirks - return quirk flags for a given EDID |
||
173 | * @edid: EDID to process |
||
174 | * |
||
175 | * This tells subsequent routines what fixes they need to apply. |
||
176 | */ |
||
177 | static u32 edid_get_quirks(struct edid *edid) |
||
178 | { |
||
179 | struct edid_quirk *quirk; |
||
180 | int i; |
||
181 | |||
182 | for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) { |
||
183 | quirk = &edid_quirk_list[i]; |
||
184 | |||
185 | if (edid_vendor(edid, quirk->vendor) && |
||
186 | (EDID_PRODUCT_ID(edid) == quirk->product_id)) |
||
187 | return quirk->quirks; |
||
188 | } |
||
189 | |||
190 | return 0; |
||
191 | } |
||
192 | |||
193 | #define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay) |
||
194 | #define MODE_REFRESH_DIFF(m,r) (abs((m)->vrefresh - target_refresh)) |
||
195 | |||
196 | |||
197 | /** |
||
198 | * edid_fixup_preferred - set preferred modes based on quirk list |
||
199 | * @connector: has mode list to fix up |
||
200 | * @quirks: quirks list |
||
201 | * |
||
202 | * Walk the mode list for @connector, clearing the preferred status |
||
203 | * on existing modes and setting it anew for the right mode ala @quirks. |
||
204 | */ |
||
205 | static void edid_fixup_preferred(struct drm_connector *connector, |
||
206 | u32 quirks) |
||
207 | { |
||
208 | struct drm_display_mode *t, *cur_mode, *preferred_mode; |
||
209 | int target_refresh = 0; |
||
210 | |||
211 | if (list_empty(&connector->probed_modes)) |
||
212 | return; |
||
213 | |||
214 | if (quirks & EDID_QUIRK_PREFER_LARGE_60) |
||
215 | target_refresh = 60; |
||
216 | if (quirks & EDID_QUIRK_PREFER_LARGE_75) |
||
217 | target_refresh = 75; |
||
218 | |||
219 | preferred_mode = list_first_entry(&connector->probed_modes, |
||
220 | struct drm_display_mode, head); |
||
221 | |||
222 | list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) { |
||
223 | cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED; |
||
224 | |||
225 | if (cur_mode == preferred_mode) |
||
226 | continue; |
||
227 | |||
228 | /* Largest mode is preferred */ |
||
229 | if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode)) |
||
230 | preferred_mode = cur_mode; |
||
231 | |||
232 | /* At a given size, try to get closest to target refresh */ |
||
233 | if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) && |
||
234 | MODE_REFRESH_DIFF(cur_mode, target_refresh) < |
||
235 | MODE_REFRESH_DIFF(preferred_mode, target_refresh)) { |
||
236 | preferred_mode = cur_mode; |
||
237 | } |
||
238 | } |
||
239 | |||
240 | preferred_mode->type |= DRM_MODE_TYPE_PREFERRED; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * drm_mode_std - convert standard mode info (width, height, refresh) into mode |
||
245 | * @t: standard timing params |
||
246 | * |
||
247 | * Take the standard timing params (in this case width, aspect, and refresh) |
||
248 | * and convert them into a real mode using CVT. |
||
249 | * |
||
250 | * Punts for now, but should eventually use the FB layer's CVT based mode |
||
251 | * generation code. |
||
252 | */ |
||
253 | struct drm_display_mode *drm_mode_std(struct drm_device *dev, |
||
254 | struct std_timing *t) |
||
255 | { |
||
256 | struct drm_display_mode *mode; |
||
257 | int hsize = t->hsize * 8 + 248, vsize; |
||
258 | unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK) |
||
259 | >> EDID_TIMING_ASPECT_SHIFT; |
||
260 | |||
261 | mode = drm_mode_create(dev); |
||
262 | if (!mode) |
||
263 | return NULL; |
||
264 | |||
265 | if (aspect_ratio == 0) |
||
266 | vsize = (hsize * 10) / 16; |
||
267 | else if (aspect_ratio == 1) |
||
268 | vsize = (hsize * 3) / 4; |
||
269 | else if (aspect_ratio == 2) |
||
270 | vsize = (hsize * 4) / 5; |
||
271 | else |
||
272 | vsize = (hsize * 9) / 16; |
||
273 | |||
274 | drm_mode_set_name(mode); |
||
275 | |||
276 | return mode; |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * drm_mode_detailed - create a new mode from an EDID detailed timing section |
||
281 | * @dev: DRM device (needed to create new mode) |
||
282 | * @edid: EDID block |
||
283 | * @timing: EDID detailed timing info |
||
284 | * @quirks: quirks to apply |
||
285 | * |
||
286 | * An EDID detailed timing block contains enough info for us to create and |
||
287 | * return a new struct drm_display_mode. |
||
288 | */ |
||
289 | static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, |
||
290 | struct edid *edid, |
||
291 | struct detailed_timing *timing, |
||
292 | u32 quirks) |
||
293 | { |
||
294 | struct drm_display_mode *mode; |
||
295 | struct detailed_pixel_timing *pt = &timing->data.pixel_data; |
||
296 | unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo; |
||
297 | unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo; |
||
298 | unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo; |
||
299 | unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo; |
||
300 | unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo; |
||
301 | unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo; |
||
302 | unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) >> 2 | pt->vsync_offset_pulse_width_lo >> 4; |
||
303 | unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf); |
||
304 | |||
305 | /* ignore tiny modes */ |
||
306 | if (hactive < 64 || vactive < 64) |
||
307 | return NULL; |
||
308 | |||
309 | if (pt->misc & DRM_EDID_PT_STEREO) { |
||
310 | printk(KERN_WARNING "stereo mode not supported\n"); |
||
311 | return NULL; |
||
312 | } |
||
313 | if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) { |
||
314 | printk(KERN_WARNING "integrated sync not supported\n"); |
||
315 | return NULL; |
||
316 | } |
||
317 | |||
318 | mode = drm_mode_create(dev); |
||
319 | if (!mode) |
||
320 | return NULL; |
||
321 | |||
322 | mode->type = DRM_MODE_TYPE_DRIVER; |
||
323 | |||
324 | if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH) |
||
325 | timing->pixel_clock = cpu_to_le16(1088); |
||
326 | |||
327 | mode->clock = le16_to_cpu(timing->pixel_clock) * 10; |
||
328 | |||
329 | mode->hdisplay = hactive; |
||
330 | mode->hsync_start = mode->hdisplay + hsync_offset; |
||
331 | mode->hsync_end = mode->hsync_start + hsync_pulse_width; |
||
332 | mode->htotal = mode->hdisplay + hblank; |
||
333 | |||
334 | mode->vdisplay = vactive; |
||
335 | mode->vsync_start = mode->vdisplay + vsync_offset; |
||
336 | mode->vsync_end = mode->vsync_start + vsync_pulse_width; |
||
337 | mode->vtotal = mode->vdisplay + vblank; |
||
338 | |||
339 | drm_mode_set_name(mode); |
||
340 | |||
341 | if (pt->misc & DRM_EDID_PT_INTERLACED) |
||
342 | mode->flags |= DRM_MODE_FLAG_INTERLACE; |
||
343 | |||
344 | if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) { |
||
345 | pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE; |
||
346 | } |
||
347 | |||
348 | mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ? |
||
349 | DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC; |
||
350 | mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ? |
||
351 | DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC; |
||
352 | |||
353 | mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4; |
||
354 | mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8; |
||
355 | |||
356 | if (quirks & EDID_QUIRK_DETAILED_IN_CM) { |
||
357 | mode->width_mm *= 10; |
||
358 | mode->height_mm *= 10; |
||
359 | } |
||
360 | |||
361 | if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) { |
||
362 | mode->width_mm = edid->width_cm * 10; |
||
363 | mode->height_mm = edid->height_cm * 10; |
||
364 | } |
||
365 | |||
366 | return mode; |
||
367 | } |
||
368 | |||
369 | /* |
||
370 | * Detailed mode info for the EDID "established modes" data to use. |
||
371 | */ |
||
372 | static struct drm_display_mode edid_est_modes[] = { |
||
373 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840, |
||
374 | 968, 1056, 0, 600, 601, 605, 628, 0, |
||
375 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */ |
||
376 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824, |
||
377 | 896, 1024, 0, 600, 601, 603, 625, 0, |
||
378 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */ |
||
379 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656, |
||
380 | 720, 840, 0, 480, 481, 484, 500, 0, |
||
381 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */ |
||
382 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664, |
||
383 | 704, 832, 0, 480, 489, 491, 520, 0, |
||
384 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */ |
||
385 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704, |
||
386 | 768, 864, 0, 480, 483, 486, 525, 0, |
||
387 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */ |
||
388 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656, |
||
389 | 752, 800, 0, 480, 490, 492, 525, 0, |
||
390 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */ |
||
391 | { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738, |
||
392 | 846, 900, 0, 400, 421, 423, 449, 0, |
||
393 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */ |
||
394 | { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738, |
||
395 | 846, 900, 0, 400, 412, 414, 449, 0, |
||
396 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */ |
||
397 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296, |
||
398 | 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, |
||
399 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */ |
||
400 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040, |
||
401 | 1136, 1312, 0, 768, 769, 772, 800, 0, |
||
402 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */ |
||
403 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048, |
||
404 | 1184, 1328, 0, 768, 771, 777, 806, 0, |
||
405 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */ |
||
406 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, |
||
407 | 1184, 1344, 0, 768, 771, 777, 806, 0, |
||
408 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */ |
||
409 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032, |
||
410 | 1208, 1264, 0, 768, 768, 776, 817, 0, |
||
411 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */ |
||
412 | { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864, |
||
413 | 928, 1152, 0, 624, 625, 628, 667, 0, |
||
414 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */ |
||
415 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816, |
||
416 | 896, 1056, 0, 600, 601, 604, 625, 0, |
||
417 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */ |
||
418 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856, |
||
419 | 976, 1040, 0, 600, 637, 643, 666, 0, |
||
420 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */ |
||
421 | { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, |
||
422 | 1344, 1600, 0, 864, 865, 868, 900, 0, |
||
423 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */ |
||
424 | }; |
||
425 | |||
426 | #define EDID_EST_TIMINGS 16 |
||
427 | #define EDID_STD_TIMINGS 8 |
||
428 | #define EDID_DETAILED_TIMINGS 4 |
||
429 | |||
430 | /** |
||
431 | * add_established_modes - get est. modes from EDID and add them |
||
432 | * @edid: EDID block to scan |
||
433 | * |
||
434 | * Each EDID block contains a bitmap of the supported "established modes" list |
||
435 | * (defined above). Tease them out and add them to the global modes list. |
||
436 | */ |
||
437 | static int add_established_modes(struct drm_connector *connector, struct edid *edid) |
||
438 | { |
||
439 | struct drm_device *dev = connector->dev; |
||
440 | unsigned long est_bits = edid->established_timings.t1 | |
||
441 | (edid->established_timings.t2 << 8) | |
||
442 | ((edid->established_timings.mfg_rsvd & 0x80) << 9); |
||
443 | int i, modes = 0; |
||
444 | |||
445 | for (i = 0; i <= EDID_EST_TIMINGS; i++) |
||
446 | if (est_bits & (1< |
||
447 | struct drm_display_mode *newmode; |
||
448 | newmode = drm_mode_duplicate(dev, &edid_est_modes[i]); |
||
449 | if (newmode) { |
||
450 | drm_mode_probed_add(connector, newmode); |
||
451 | modes++; |
||
452 | } |
||
453 | } |
||
454 | |||
455 | return modes; |
||
456 | } |
||
457 | |||
458 | /** |
||
459 | * add_standard_modes - get std. modes from EDID and add them |
||
460 | * @edid: EDID block to scan |
||
461 | * |
||
462 | * Standard modes can be calculated using the CVT standard. Grab them from |
||
463 | * @edid, calculate them, and add them to the list. |
||
464 | */ |
||
465 | static int add_standard_modes(struct drm_connector *connector, struct edid *edid) |
||
466 | { |
||
467 | struct drm_device *dev = connector->dev; |
||
468 | int i, modes = 0; |
||
469 | |||
470 | for (i = 0; i < EDID_STD_TIMINGS; i++) { |
||
471 | struct std_timing *t = &edid->standard_timings[i]; |
||
472 | struct drm_display_mode *newmode; |
||
473 | |||
474 | /* If std timings bytes are 1, 1 it's empty */ |
||
475 | if (t->hsize == 1 && t->vfreq_aspect == 1) |
||
476 | continue; |
||
477 | |||
478 | newmode = drm_mode_std(dev, &edid->standard_timings[i]); |
||
479 | if (newmode) { |
||
480 | drm_mode_probed_add(connector, newmode); |
||
481 | modes++; |
||
482 | } |
||
483 | } |
||
484 | |||
485 | return modes; |
||
486 | } |
||
487 | |||
488 | /** |
||
489 | * add_detailed_modes - get detailed mode info from EDID data |
||
490 | * @connector: attached connector |
||
491 | * @edid: EDID block to scan |
||
492 | * @quirks: quirks to apply |
||
493 | * |
||
494 | * Some of the detailed timing sections may contain mode information. Grab |
||
495 | * it and add it to the list. |
||
496 | */ |
||
497 | static int add_detailed_info(struct drm_connector *connector, |
||
498 | struct edid *edid, u32 quirks) |
||
499 | { |
||
500 | struct drm_device *dev = connector->dev; |
||
501 | int i, j, modes = 0; |
||
502 | |||
503 | for (i = 0; i < EDID_DETAILED_TIMINGS; i++) { |
||
504 | struct detailed_timing *timing = &edid->detailed_timings[i]; |
||
505 | struct detailed_non_pixel *data = &timing->data.other_data; |
||
506 | struct drm_display_mode *newmode; |
||
507 | |||
508 | /* EDID up to and including 1.2 may put monitor info here */ |
||
509 | if (edid->version == 1 && edid->revision < 3) |
||
510 | continue; |
||
511 | |||
512 | /* Detailed mode timing */ |
||
513 | if (timing->pixel_clock) { |
||
514 | newmode = drm_mode_detailed(dev, edid, timing, quirks); |
||
515 | if (!newmode) |
||
516 | continue; |
||
517 | |||
518 | /* First detailed mode is preferred */ |
||
519 | if (i == 0 && (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING)) |
||
520 | newmode->type |= DRM_MODE_TYPE_PREFERRED; |
||
521 | drm_mode_probed_add(connector, newmode); |
||
522 | |||
523 | modes++; |
||
524 | continue; |
||
525 | } |
||
526 | |||
527 | /* Other timing or info */ |
||
528 | switch (data->type) { |
||
529 | case EDID_DETAIL_MONITOR_SERIAL: |
||
530 | break; |
||
531 | case EDID_DETAIL_MONITOR_STRING: |
||
532 | break; |
||
533 | case EDID_DETAIL_MONITOR_RANGE: |
||
534 | /* Get monitor range data */ |
||
535 | break; |
||
536 | case EDID_DETAIL_MONITOR_NAME: |
||
537 | break; |
||
538 | case EDID_DETAIL_MONITOR_CPDATA: |
||
539 | break; |
||
540 | case EDID_DETAIL_STD_MODES: |
||
541 | /* Five modes per detailed section */ |
||
542 | for (j = 0; j < 5; i++) { |
||
543 | struct std_timing *std; |
||
544 | struct drm_display_mode *newmode; |
||
545 | |||
546 | std = &data->data.timings[j]; |
||
547 | newmode = drm_mode_std(dev, std); |
||
548 | if (newmode) { |
||
549 | drm_mode_probed_add(connector, newmode); |
||
550 | modes++; |
||
551 | } |
||
552 | } |
||
553 | break; |
||
554 | default: |
||
555 | break; |
||
556 | } |
||
557 | } |
||
558 | |||
559 | return modes; |
||
560 | } |
||
561 | |||
562 | #define DDC_ADDR 0x50 |
||
563 | /** |
||
564 | * Get EDID information via I2C. |
||
565 | * |
||
566 | * \param adapter : i2c device adaptor |
||
567 | * \param buf : EDID data buffer to be filled |
||
568 | * \param len : EDID data buffer length |
||
569 | * \return 0 on success or -1 on failure. |
||
570 | * |
||
571 | * Try to fetch EDID information by calling i2c driver function. |
||
572 | */ |
||
573 | int drm_do_probe_ddc_edid(struct i2c_adapter *adapter, |
||
574 | unsigned char *buf, int len) |
||
575 | { |
||
576 | unsigned char start = 0x0; |
||
577 | struct i2c_msg msgs[] = { |
||
578 | { |
||
579 | .addr = DDC_ADDR, |
||
580 | .flags = 0, |
||
581 | .len = 1, |
||
582 | .buf = &start, |
||
583 | }, { |
||
584 | .addr = DDC_ADDR, |
||
585 | .flags = I2C_M_RD, |
||
586 | .len = len, |
||
587 | .buf = buf, |
||
588 | } |
||
589 | }; |
||
590 | |||
591 | if (i2c_transfer(adapter, msgs, 2) == 2) |
||
592 | return 0; |
||
593 | |||
594 | // dev_info(&adapter->dev, "unable to read EDID block.\n"); |
||
595 | return -1; |
||
596 | } |
||
597 | EXPORT_SYMBOL(drm_do_probe_ddc_edid); |
||
598 | |||
599 | static int drm_ddc_read_edid(struct drm_connector *connector, |
||
600 | struct i2c_adapter *adapter, |
||
601 | char *buf, int len) |
||
602 | { |
||
603 | int ret; |
||
604 | |||
605 | ret = drm_do_probe_ddc_edid(adapter, buf, len); |
||
606 | if (ret != 0) { |
||
607 | // dev_info(&connector->dev->pdev->dev, "%s: no EDID data\n", |
||
608 | // drm_get_connector_name(connector)); |
||
609 | goto end; |
||
610 | } |
||
611 | if (!edid_is_valid((struct edid *)buf)) { |
||
612 | // dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n", |
||
613 | // drm_get_connector_name(connector)); |
||
614 | ret = -1; |
||
615 | } |
||
616 | end: |
||
617 | return ret; |
||
618 | } |
||
619 | |||
620 | #define MAX_EDID_EXT_NUM 4 |
||
621 | /** |
||
622 | * drm_get_edid - get EDID data, if available |
||
623 | * @connector: connector we're probing |
||
624 | * @adapter: i2c adapter to use for DDC |
||
625 | * |
||
626 | * Poke the given connector's i2c channel to grab EDID data if possible. |
||
627 | * |
||
628 | * Return edid data or NULL if we couldn't find any. |
||
629 | */ |
||
630 | struct edid *drm_get_edid(struct drm_connector *connector, |
||
631 | struct i2c_adapter *adapter) |
||
632 | { |
||
633 | int ret; |
||
634 | struct edid *edid; |
||
635 | |||
636 | edid = kmalloc(EDID_LENGTH * (MAX_EDID_EXT_NUM + 1), |
||
637 | GFP_KERNEL); |
||
638 | if (edid == NULL) { |
||
639 | // dev_warn(&connector->dev->pdev->dev, |
||
640 | // "Failed to allocate EDID\n"); |
||
641 | goto end; |
||
642 | } |
||
643 | |||
644 | /* Read first EDID block */ |
||
645 | ret = drm_ddc_read_edid(connector, adapter, |
||
646 | (unsigned char *)edid, EDID_LENGTH); |
||
647 | if (ret != 0) |
||
648 | goto clean_up; |
||
649 | |||
650 | /* There are EDID extensions to be read */ |
||
651 | if (edid->extensions != 0) { |
||
652 | int edid_ext_num = edid->extensions; |
||
653 | |||
654 | if (edid_ext_num > MAX_EDID_EXT_NUM) { |
||
655 | // dev_warn(&connector->dev->pdev->dev, |
||
656 | // "The number of extension(%d) is " |
||
657 | // "over max (%d), actually read number (%d)\n", |
||
658 | // edid_ext_num, MAX_EDID_EXT_NUM, |
||
659 | // MAX_EDID_EXT_NUM); |
||
660 | /* Reset EDID extension number to be read */ |
||
661 | edid_ext_num = MAX_EDID_EXT_NUM; |
||
662 | } |
||
663 | /* Read EDID including extensions too */ |
||
664 | ret = drm_ddc_read_edid(connector, adapter, (char *)edid, |
||
665 | EDID_LENGTH * (edid_ext_num + 1)); |
||
666 | if (ret != 0) |
||
667 | goto clean_up; |
||
668 | |||
669 | } |
||
670 | |||
671 | connector->display_info.raw_edid = (char *)edid; |
||
672 | goto end; |
||
673 | |||
674 | clean_up: |
||
675 | kfree(edid); |
||
676 | edid = NULL; |
||
677 | end: |
||
678 | return edid; |
||
679 | |||
680 | } |
||
681 | EXPORT_SYMBOL(drm_get_edid); |
||
682 | |||
683 | #define HDMI_IDENTIFIER 0x000C03 |
||
684 | #define VENDOR_BLOCK 0x03 |
||
685 | /** |
||
686 | * drm_detect_hdmi_monitor - detect whether monitor is hdmi. |
||
687 | * @edid: monitor EDID information |
||
688 | * |
||
689 | * Parse the CEA extension according to CEA-861-B. |
||
690 | * Return true if HDMI, false if not or unknown. |
||
691 | */ |
||
692 | bool drm_detect_hdmi_monitor(struct edid *edid) |
||
693 | { |
||
694 | char *edid_ext = NULL; |
||
695 | int i, hdmi_id, edid_ext_num; |
||
696 | int start_offset, end_offset; |
||
697 | bool is_hdmi = false; |
||
698 | |||
699 | /* No EDID or EDID extensions */ |
||
700 | if (edid == NULL || edid->extensions == 0) |
||
701 | goto end; |
||
702 | |||
703 | /* Chose real EDID extension number */ |
||
704 | edid_ext_num = edid->extensions > MAX_EDID_EXT_NUM ? |
||
705 | MAX_EDID_EXT_NUM : edid->extensions; |
||
706 | |||
707 | /* Find CEA extension */ |
||
708 | for (i = 0; i < edid_ext_num; i++) { |
||
709 | edid_ext = (char *)edid + EDID_LENGTH * (i + 1); |
||
710 | /* This block is CEA extension */ |
||
711 | if (edid_ext[0] == 0x02) |
||
712 | break; |
||
713 | } |
||
714 | |||
715 | if (i == edid_ext_num) |
||
716 | goto end; |
||
717 | |||
718 | /* Data block offset in CEA extension block */ |
||
719 | start_offset = 4; |
||
720 | end_offset = edid_ext[2]; |
||
721 | |||
722 | /* |
||
723 | * Because HDMI identifier is in Vendor Specific Block, |
||
724 | * search it from all data blocks of CEA extension. |
||
725 | */ |
||
726 | for (i = start_offset; i < end_offset; |
||
727 | /* Increased by data block len */ |
||
728 | i += ((edid_ext[i] & 0x1f) + 1)) { |
||
729 | /* Find vendor specific block */ |
||
730 | if ((edid_ext[i] >> 5) == VENDOR_BLOCK) { |
||
731 | hdmi_id = edid_ext[i + 1] | (edid_ext[i + 2] << 8) | |
||
732 | edid_ext[i + 3] << 16; |
||
733 | /* Find HDMI identifier */ |
||
734 | if (hdmi_id == HDMI_IDENTIFIER) |
||
735 | is_hdmi = true; |
||
736 | break; |
||
737 | } |
||
738 | } |
||
739 | |||
740 | end: |
||
741 | return is_hdmi; |
||
742 | } |
||
743 | EXPORT_SYMBOL(drm_detect_hdmi_monitor); |
||
744 | |||
745 | /** |
||
746 | * drm_add_edid_modes - add modes from EDID data, if available |
||
747 | * @connector: connector we're probing |
||
748 | * @edid: edid data |
||
749 | * |
||
750 | * Add the specified modes to the connector's mode list. |
||
751 | * |
||
752 | * Return number of modes added or 0 if we couldn't find any. |
||
753 | */ |
||
754 | int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid) |
||
755 | { |
||
756 | int num_modes = 0; |
||
757 | u32 quirks; |
||
758 | |||
759 | if (edid == NULL) { |
||
760 | return 0; |
||
761 | } |
||
762 | if (!edid_is_valid(edid)) { |
||
763 | // dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n", |
||
764 | // drm_get_connector_name(connector)); |
||
765 | return 0; |
||
766 | } |
||
767 | |||
768 | quirks = edid_get_quirks(edid); |
||
769 | |||
770 | num_modes += add_established_modes(connector, edid); |
||
771 | num_modes += add_standard_modes(connector, edid); |
||
772 | num_modes += add_detailed_info(connector, edid, quirks); |
||
773 | |||
774 | if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75)) |
||
775 | edid_fixup_preferred(connector, quirks); |
||
776 | |||
777 | connector->display_info.serration_vsync = (edid->input & DRM_EDID_INPUT_SERRATION_VSYNC) ? 1 : 0; |
||
778 | connector->display_info.sync_on_green = (edid->input & DRM_EDID_INPUT_SYNC_ON_GREEN) ? 1 : 0; |
||
779 | connector->display_info.composite_sync = (edid->input & DRM_EDID_INPUT_COMPOSITE_SYNC) ? 1 : 0; |
||
780 | connector->display_info.separate_syncs = (edid->input & DRM_EDID_INPUT_SEPARATE_SYNCS) ? 1 : 0; |
||
781 | connector->display_info.blank_to_black = (edid->input & DRM_EDID_INPUT_BLANK_TO_BLACK) ? 1 : 0; |
||
782 | connector->display_info.video_level = (edid->input & DRM_EDID_INPUT_VIDEO_LEVEL) >> 5; |
||
783 | connector->display_info.digital = (edid->input & DRM_EDID_INPUT_DIGITAL) ? 1 : 0; |
||
784 | connector->display_info.width_mm = edid->width_cm * 10; |
||
785 | connector->display_info.height_mm = edid->height_cm * 10; |
||
786 | connector->display_info.gamma = edid->gamma; |
||
787 | connector->display_info.gtf_supported = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF) ? 1 : 0; |
||
788 | connector->display_info.standard_color = (edid->features & DRM_EDID_FEATURE_STANDARD_COLOR) ? 1 : 0; |
||
789 | connector->display_info.display_type = (edid->features & DRM_EDID_FEATURE_DISPLAY_TYPE) >> 3; |
||
790 | connector->display_info.active_off_supported = (edid->features & DRM_EDID_FEATURE_PM_ACTIVE_OFF) ? 1 : 0; |
||
791 | connector->display_info.suspend_supported = (edid->features & DRM_EDID_FEATURE_PM_SUSPEND) ? 1 : 0; |
||
792 | connector->display_info.standby_supported = (edid->features & DRM_EDID_FEATURE_PM_STANDBY) ? 1 : 0; |
||
793 | connector->display_info.gamma = edid->gamma; |
||
794 | |||
795 | return num_modes; |
||
796 | } |
||
797 | EXPORT_SYMBOL(drm_add_edid_modes);><>><>>>>>>>=>><>><>><>><>>>><>><>><>><>><>><>><> |