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