diff options
Diffstat (limited to 'linux-core/drm_edid.c')
-rw-r--r-- | linux-core/drm_edid.c | 737 |
1 files changed, 0 insertions, 737 deletions
diff --git a/linux-core/drm_edid.c b/linux-core/drm_edid.c deleted file mode 100644 index 07894720..00000000 --- a/linux-core/drm_edid.c +++ /dev/null | |||
@@ -1,737 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2006 Luc Verhaegen (quirks list) | ||
3 | * Copyright (c) 2007 Intel Corporation | ||
4 | * Jesse Barnes <jesse.barnes@intel.com> | ||
5 | * | ||
6 | * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from | ||
7 | * FB layer. | ||
8 | * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com> | ||
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 <linux/kernel.h> | ||
30 | #include <linux/i2c.h> | ||
31 | #include <linux/i2c-algo-bit.h> | ||
32 | #include "drmP.h" | ||
33 | #include "drm_edid.h" | ||
34 | |||
35 | /* | ||
36 | * TODO: | ||
37 | * - support EDID 1.4 | ||
38 | * - port quirks from X server code | ||
39 | */ | ||
40 | |||
41 | /* | ||
42 | * EDID blocks out in the wild have a variety of bugs, try to collect | ||
43 | * them here (note that userspace may work around broken monitors first, | ||
44 | * but fixes should make their way here so that the kernel "just works" | ||
45 | * on as many displays as possible). | ||
46 | */ | ||
47 | |||
48 | /* First detailed mode wrong, use largest 60Hz mode */ | ||
49 | #define EDID_QUIRK_PREFER_LARGE_60 (1 << 0) | ||
50 | /* Reported 135MHz pixel clock is too high, needs adjustment */ | ||
51 | #define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1) | ||
52 | /* Prefer the largest mode at 75 Hz */ | ||
53 | #define EDID_QUIRK_PREFER_LARGE_75 (1 << 2) | ||
54 | /* Detail timing is in cm not mm */ | ||
55 | #define EDID_QUIRK_DETAILED_IN_CM (1 << 3) | ||
56 | /* Detailed timing descriptors have bogus size values, so just take the | ||
57 | * maximum size and use that. | ||
58 | */ | ||
59 | #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4) | ||
60 | /* Monitor forgot to set the first detailed is preferred bit. */ | ||
61 | #define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5) | ||
62 | /* use +hsync +vsync for detailed mode */ | ||
63 | #define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6) | ||
64 | |||
65 | static struct edid_quirk { | ||
66 | char *vendor; | ||
67 | int product_id; | ||
68 | u32 quirks; | ||
69 | } edid_quirk_list[] = { | ||
70 | /* Acer AL1706 */ | ||
71 | { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 }, | ||
72 | /* Acer F51 */ | ||
73 | { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 }, | ||
74 | /* Unknown Acer */ | ||
75 | { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED }, | ||
76 | |||
77 | /* Belinea 10 15 55 */ | ||
78 | { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 }, | ||
79 | { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 }, | ||
80 | |||
81 | /* Envision Peripherals, Inc. EN-7100e */ | ||
82 | { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH }, | ||
83 | |||
84 | /* Funai Electronics PM36B */ | ||
85 | { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 | | ||
86 | EDID_QUIRK_DETAILED_IN_CM }, | ||
87 | |||
88 | /* LG Philips LCD LP154W01-A5 */ | ||
89 | { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE }, | ||
90 | { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE }, | ||
91 | |||
92 | /* Philips 107p5 CRT */ | ||
93 | { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED }, | ||
94 | |||
95 | /* Proview AY765C */ | ||
96 | { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED }, | ||
97 | |||
98 | /* Samsung SyncMaster 205BW. Note: irony */ | ||
99 | { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP }, | ||
100 | /* Samsung SyncMaster 22[5-6]BW */ | ||
101 | { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 }, | ||
102 | { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 }, | ||
103 | }; | ||
104 | |||
105 | |||
106 | /* Valid EDID header has these bytes */ | ||
107 | static u8 edid_header[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; | ||
108 | |||
109 | /** | ||
110 | * edid_is_valid - sanity check EDID data | ||
111 | * @edid: EDID data | ||
112 | * | ||
113 | * Sanity check the EDID block by looking at the header, the version number | ||
114 | * and the checksum. Return 0 if the EDID doesn't check out, or 1 if it's | ||
115 | * valid. | ||
116 | */ | ||
117 | static bool edid_is_valid(struct edid *edid) | ||
118 | { | ||
119 | int i; | ||
120 | u8 csum = 0; | ||
121 | u8 *raw_edid = (u8 *)edid; | ||
122 | |||
123 | if (memcmp(edid->header, edid_header, sizeof(edid_header))) | ||
124 | goto bad; | ||
125 | if (edid->version != 1) { | ||
126 | DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version); | ||
127 | goto bad; | ||
128 | } | ||
129 | if (edid->revision <= 0 || edid->revision > 3) { | ||
130 | DRM_ERROR("EDID has minor version %d, which is not between 0-3\n", edid->revision); | ||
131 | goto bad; | ||
132 | } | ||
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[2] & 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; | ||
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 fb_videomode mode; | ||
257 | |||
258 | // fb_find_mode_cvt(&mode, 0, 0); | ||
259 | /* JJJ: convert to drm_display_mode */ | ||
260 | struct drm_display_mode *mode; | ||
261 | int hsize = t->hsize * 8 + 248, vsize; | ||
262 | |||
263 | mode = drm_mode_create(dev); | ||
264 | if (!mode) | ||
265 | return NULL; | ||
266 | |||
267 | if (t->aspect_ratio == 0) | ||
268 | vsize = (hsize * 10) / 16; | ||
269 | else if (t->aspect_ratio == 1) | ||
270 | vsize = (hsize * 3) / 4; | ||
271 | else if (t->aspect_ratio == 2) | ||
272 | vsize = (hsize * 4) / 5; | ||
273 | else | ||
274 | vsize = (hsize * 9) / 16; | ||
275 | |||
276 | drm_mode_set_name(mode); | ||
277 | |||
278 | return mode; | ||
279 | } | ||
280 | |||
281 | /** | ||
282 | * drm_mode_detailed - create a new mode from an EDID detailed timing section | ||
283 | * @dev: DRM device (needed to create new mode) | ||
284 | * @edid: EDID block | ||
285 | * @timing: EDID detailed timing info | ||
286 | * @quirks: quirks to apply | ||
287 | * | ||
288 | * An EDID detailed timing block contains enough info for us to create and | ||
289 | * return a new struct drm_display_mode. | ||
290 | */ | ||
291 | static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, | ||
292 | struct edid *edid, | ||
293 | struct detailed_timing *timing, | ||
294 | u32 quirks) | ||
295 | { | ||
296 | struct drm_display_mode *mode; | ||
297 | struct detailed_pixel_timing *pt = &timing->data.pixel_data; | ||
298 | |||
299 | if (pt->stereo) { | ||
300 | printk(KERN_WARNING "stereo mode not supported\n"); | ||
301 | return NULL; | ||
302 | } | ||
303 | if (!pt->separate_sync) { | ||
304 | printk(KERN_WARNING "integrated sync not supported\n"); | ||
305 | return NULL; | ||
306 | } | ||
307 | |||
308 | mode = drm_mode_create(dev); | ||
309 | if (!mode) | ||
310 | return NULL; | ||
311 | |||
312 | mode->type = DRM_MODE_TYPE_DRIVER; | ||
313 | |||
314 | if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH) | ||
315 | timing->pixel_clock = 1088; | ||
316 | |||
317 | mode->clock = timing->pixel_clock * 10; | ||
318 | |||
319 | mode->hdisplay = (pt->hactive_hi << 8) | pt->hactive_lo; | ||
320 | mode->hsync_start = mode->hdisplay + ((pt->hsync_offset_hi << 8) | | ||
321 | pt->hsync_offset_lo); | ||
322 | mode->hsync_end = mode->hsync_start + | ||
323 | ((pt->hsync_pulse_width_hi << 8) | | ||
324 | pt->hsync_pulse_width_lo); | ||
325 | mode->htotal = mode->hdisplay + ((pt->hblank_hi << 8) | pt->hblank_lo); | ||
326 | |||
327 | mode->vdisplay = (pt->vactive_hi << 8) | pt->vactive_lo; | ||
328 | mode->vsync_start = mode->vdisplay + ((pt->vsync_offset_hi << 8) | | ||
329 | pt->vsync_offset_lo); | ||
330 | mode->vsync_end = mode->vsync_start + | ||
331 | ((pt->vsync_pulse_width_hi << 8) | | ||
332 | pt->vsync_pulse_width_lo); | ||
333 | mode->vtotal = mode->vdisplay + ((pt->vblank_hi << 8) | pt->vblank_lo); | ||
334 | |||
335 | drm_mode_set_name(mode); | ||
336 | |||
337 | if (pt->interlaced) | ||
338 | mode->flags |= DRM_MODE_FLAG_INTERLACE; | ||
339 | |||
340 | if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) { | ||
341 | pt->hsync_positive = 1; | ||
342 | pt->vsync_positive = 1; | ||
343 | } | ||
344 | |||
345 | mode->flags |= pt->hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC; | ||
346 | mode->flags |= pt->vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC; | ||
347 | |||
348 | mode->width_mm = pt->width_mm_lo | (pt->width_mm_hi << 8); | ||
349 | mode->height_mm = pt->height_mm_lo | (pt->height_mm_hi << 8); | ||
350 | |||
351 | if (quirks & EDID_QUIRK_DETAILED_IN_CM) { | ||
352 | mode->width_mm *= 10; | ||
353 | mode->height_mm *= 10; | ||
354 | } | ||
355 | |||
356 | if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) { | ||
357 | mode->width_mm = edid->width_cm * 10; | ||
358 | mode->height_mm = edid->height_cm * 10; | ||
359 | } | ||
360 | |||
361 | return mode; | ||
362 | } | ||
363 | |||
364 | /* | ||
365 | * Detailed mode info for the EDID "established modes" data to use. | ||
366 | */ | ||
367 | static struct drm_display_mode edid_est_modes[] = { | ||
368 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840, | ||
369 | 968, 1056, 0, 600, 601, 605, 628, 0, | ||
370 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */ | ||
371 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824, | ||
372 | 896, 1024, 0, 600, 601, 603, 625, 0, | ||
373 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */ | ||
374 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656, | ||
375 | 720, 840, 0, 480, 481, 484, 500, 0, | ||
376 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */ | ||
377 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664, | ||
378 | 704, 832, 0, 480, 489, 491, 520, 0, | ||
379 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */ | ||
380 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704, | ||
381 | 768, 864, 0, 480, 483, 486, 525, 0, | ||
382 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */ | ||
383 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656, | ||
384 | 752, 800, 0, 480, 490, 492, 525, 0, | ||
385 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */ | ||
386 | { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738, | ||
387 | 846, 900, 0, 400, 421, 423, 449, 0, | ||
388 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */ | ||
389 | { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738, | ||
390 | 846, 900, 0, 400, 412, 414, 449, 0, | ||
391 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */ | ||
392 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296, | ||
393 | 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, | ||
394 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */ | ||
395 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040, | ||
396 | 1136, 1312, 0, 768, 769, 772, 800, 0, | ||
397 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */ | ||
398 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048, | ||
399 | 1184, 1328, 0, 768, 771, 777, 806, 0, | ||
400 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */ | ||
401 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, | ||
402 | 1184, 1344, 0, 768, 771, 777, 806, 0, | ||
403 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */ | ||
404 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032, | ||
405 | 1208, 1264, 0, 768, 768, 776, 817, 0, | ||
406 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */ | ||
407 | { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864, | ||
408 | 928, 1152, 0, 624, 625, 628, 667, 0, | ||
409 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */ | ||
410 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816, | ||
411 | 896, 1056, 0, 600, 601, 604, 625, 0, | ||
412 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */ | ||
413 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856, | ||
414 | 976, 1040, 0, 600, 637, 643, 666, 0, | ||
415 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */ | ||
416 | { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, | ||
417 | 1344, 1600, 0, 864, 865, 868, 900, 0, | ||
418 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */ | ||
419 | }; | ||
420 | |||
421 | #define EDID_EST_TIMINGS 16 | ||
422 | #define EDID_STD_TIMINGS 8 | ||
423 | #define EDID_DETAILED_TIMINGS 4 | ||
424 | |||
425 | /** | ||
426 | * add_established_modes - get est. modes from EDID and add them | ||
427 | * @edid: EDID block to scan | ||
428 | * | ||
429 | * Each EDID block contains a bitmap of the supported "established modes" list | ||
430 | * (defined above). Tease them out and add them to the global modes list. | ||
431 | */ | ||
432 | static int add_established_modes(struct drm_connector *connector, struct edid *edid) | ||
433 | { | ||
434 | struct drm_device *dev = connector->dev; | ||
435 | unsigned long est_bits = edid->established_timings.t1 | | ||
436 | (edid->established_timings.t2 << 8) | | ||
437 | ((edid->established_timings.mfg_rsvd & 0x80) << 9); | ||
438 | int i, modes = 0; | ||
439 | |||
440 | for (i = 0; i <= EDID_EST_TIMINGS; i++) | ||
441 | if (est_bits & (1<<i)) { | ||
442 | struct drm_display_mode *newmode; | ||
443 | newmode = drm_mode_duplicate(dev, &edid_est_modes[i]); | ||
444 | if (newmode) { | ||
445 | drm_mode_probed_add(connector, newmode); | ||
446 | modes++; | ||
447 | } | ||
448 | } | ||
449 | |||
450 | return modes; | ||
451 | } | ||
452 | |||
453 | /** | ||
454 | * add_standard_modes - get std. modes from EDID and add them | ||
455 | * @edid: EDID block to scan | ||
456 | * | ||
457 | * Standard modes can be calculated using the CVT standard. Grab them from | ||
458 | * @edid, calculate them, and add them to the list. | ||
459 | */ | ||
460 | static int add_standard_modes(struct drm_connector *connector, struct edid *edid) | ||
461 | { | ||
462 | struct drm_device *dev = connector->dev; | ||
463 | int i, modes = 0; | ||
464 | |||
465 | for (i = 0; i < EDID_STD_TIMINGS; i++) { | ||
466 | struct std_timing *t = &edid->standard_timings[i]; | ||
467 | struct drm_display_mode *newmode; | ||
468 | |||
469 | /* If std timings bytes are 1, 1 it's empty */ | ||
470 | if (t->hsize == 1 && (t->aspect_ratio | t->vfreq) == 1) | ||
471 | continue; | ||
472 | |||
473 | newmode = drm_mode_std(dev, &edid->standard_timings[i]); | ||
474 | if (newmode) { | ||
475 | drm_mode_probed_add(connector, newmode); | ||
476 | modes++; | ||
477 | } | ||
478 | } | ||
479 | |||
480 | return modes; | ||
481 | } | ||
482 | |||
483 | /** | ||
484 | * add_detailed_modes - get detailed mode info from EDID data | ||
485 | * @connector: attached connector | ||
486 | * @edid: EDID block to scan | ||
487 | * @quirks: quirks to apply | ||
488 | * | ||
489 | * Some of the detailed timing sections may contain mode information. Grab | ||
490 | * it and add it to the list. | ||
491 | */ | ||
492 | static int add_detailed_info(struct drm_connector *connector, | ||
493 | struct edid *edid, u32 quirks) | ||
494 | { | ||
495 | struct drm_device *dev = connector->dev; | ||
496 | int i, j, modes = 0; | ||
497 | |||
498 | for (i = 0; i < EDID_DETAILED_TIMINGS; i++) { | ||
499 | struct detailed_timing *timing = &edid->detailed_timings[i]; | ||
500 | struct detailed_non_pixel *data = &timing->data.other_data; | ||
501 | struct drm_display_mode *newmode; | ||
502 | |||
503 | /* EDID up to and including 1.2 may put monitor info here */ | ||
504 | if (edid->version == 1 && edid->revision < 3) | ||
505 | continue; | ||
506 | |||
507 | /* Detailed mode timing */ | ||
508 | if (timing->pixel_clock) { | ||
509 | newmode = drm_mode_detailed(dev, edid, timing, quirks); | ||
510 | if (!newmode) | ||
511 | continue; | ||
512 | |||
513 | /* First detailed mode is preferred */ | ||
514 | if (i == 0 && edid->preferred_timing) | ||
515 | newmode->type |= DRM_MODE_TYPE_PREFERRED; | ||
516 | drm_mode_probed_add(connector, newmode); | ||
517 | |||
518 | modes++; | ||
519 | continue; | ||
520 | } | ||
521 | |||
522 | /* Other timing or info */ | ||
523 | switch (data->type) { | ||
524 | case EDID_DETAIL_MONITOR_SERIAL: | ||
525 | break; | ||
526 | case EDID_DETAIL_MONITOR_STRING: | ||
527 | break; | ||
528 | case EDID_DETAIL_MONITOR_RANGE: | ||
529 | /* Get monitor range data */ | ||
530 | break; | ||
531 | case EDID_DETAIL_MONITOR_NAME: | ||
532 | break; | ||
533 | case EDID_DETAIL_MONITOR_CPDATA: | ||
534 | break; | ||
535 | case EDID_DETAIL_STD_MODES: | ||
536 | /* Five modes per detailed section */ | ||
537 | for (j = 0; j < 5; i++) { | ||
538 | struct std_timing *std; | ||
539 | struct drm_display_mode *newmode; | ||
540 | |||
541 | std = &data->data.timings[j]; | ||
542 | newmode = drm_mode_std(dev, std); | ||
543 | if (newmode) { | ||
544 | drm_mode_probed_add(connector, newmode); | ||
545 | modes++; | ||
546 | } | ||
547 | } | ||
548 | break; | ||
549 | default: | ||
550 | break; | ||
551 | } | ||
552 | } | ||
553 | |||
554 | return modes; | ||
555 | } | ||
556 | |||
557 | #define DDC_ADDR 0x50 | ||
558 | |||
559 | unsigned char *drm_do_probe_ddc_edid(struct i2c_adapter *adapter) | ||
560 | { | ||
561 | unsigned char start = 0x0; | ||
562 | unsigned char *buf = kmalloc(EDID_LENGTH, GFP_KERNEL); | ||
563 | struct i2c_msg msgs[] = { | ||
564 | { | ||
565 | .addr = DDC_ADDR, | ||
566 | .flags = 0, | ||
567 | .len = 1, | ||
568 | .buf = &start, | ||
569 | }, { | ||
570 | .addr = DDC_ADDR, | ||
571 | .flags = I2C_M_RD, | ||
572 | .len = EDID_LENGTH, | ||
573 | .buf = buf, | ||
574 | } | ||
575 | }; | ||
576 | |||
577 | if (!buf) { | ||
578 | dev_warn(&adapter->dev, "unable to allocate memory for EDID " | ||
579 | "block.\n"); | ||
580 | return NULL; | ||
581 | } | ||
582 | |||
583 | if (i2c_transfer(adapter, msgs, 2) == 2) | ||
584 | return buf; | ||
585 | |||
586 | dev_info(&adapter->dev, "unable to read EDID block.\n"); | ||
587 | kfree(buf); | ||
588 | return NULL; | ||
589 | } | ||
590 | EXPORT_SYMBOL(drm_do_probe_ddc_edid); | ||
591 | |||
592 | static unsigned char *drm_ddc_read(struct i2c_adapter *adapter) | ||
593 | { | ||
594 | struct i2c_algo_bit_data *algo_data = adapter->algo_data; | ||
595 | unsigned char *edid = NULL; | ||
596 | int i, j; | ||
597 | |||
598 | algo_data->setscl(algo_data->data, 1); | ||
599 | |||
600 | for (i = 0; i < 3; i++) { | ||
601 | /* For some old monitors we need the | ||
602 | * following process to initialize/stop DDC | ||
603 | */ | ||
604 | algo_data->setsda(algo_data->data, 1); | ||
605 | msleep(13); | ||
606 | |||
607 | algo_data->setscl(algo_data->data, 1); | ||
608 | for (j = 0; j < 5; j++) { | ||
609 | msleep(10); | ||
610 | if (algo_data->getscl(algo_data->data)) | ||
611 | break; | ||
612 | } | ||
613 | if (j == 5) | ||
614 | continue; | ||
615 | |||
616 | algo_data->setsda(algo_data->data, 0); | ||
617 | msleep(15); | ||
618 | algo_data->setscl(algo_data->data, 0); | ||
619 | msleep(15); | ||
620 | algo_data->setsda(algo_data->data, 1); | ||
621 | msleep(15); | ||
622 | |||
623 | /* Do the real work */ | ||
624 | edid = drm_do_probe_ddc_edid(adapter); | ||
625 | algo_data->setsda(algo_data->data, 0); | ||
626 | algo_data->setscl(algo_data->data, 0); | ||
627 | msleep(15); | ||
628 | |||
629 | algo_data->setscl(algo_data->data, 1); | ||
630 | for (j = 0; j < 10; j++) { | ||
631 | msleep(10); | ||
632 | if (algo_data->getscl(algo_data->data)) | ||
633 | break; | ||
634 | } | ||
635 | |||
636 | algo_data->setsda(algo_data->data, 1); | ||
637 | msleep(15); | ||
638 | algo_data->setscl(algo_data->data, 0); | ||
639 | algo_data->setsda(algo_data->data, 0); | ||
640 | if (edid) | ||
641 | break; | ||
642 | } | ||
643 | /* Release the DDC lines when done or the Apple Cinema HD display | ||
644 | * will switch off | ||
645 | */ | ||
646 | algo_data->setsda(algo_data->data, 1); | ||
647 | algo_data->setscl(algo_data->data, 1); | ||
648 | |||
649 | return edid; | ||
650 | } | ||
651 | |||
652 | /** | ||
653 | * drm_get_edid - get EDID data, if available | ||
654 | * @connector: connector we're probing | ||
655 | * @adapter: i2c adapter to use for DDC | ||
656 | * | ||
657 | * Poke the given connector's i2c channel to grab EDID data if possible. | ||
658 | * | ||
659 | * Return edid data or NULL if we couldn't find any. | ||
660 | */ | ||
661 | struct edid *drm_get_edid(struct drm_connector *connector, | ||
662 | struct i2c_adapter *adapter) | ||
663 | { | ||
664 | struct edid *edid; | ||
665 | |||
666 | edid = (struct edid *)drm_ddc_read(adapter); | ||
667 | if (!edid) { | ||
668 | dev_warn(&connector->dev->pdev->dev, "%s: no EDID data\n", | ||
669 | drm_get_connector_name(connector)); | ||
670 | return NULL; | ||
671 | } | ||
672 | if (!edid_is_valid(edid)) { | ||
673 | dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n", | ||
674 | drm_get_connector_name(connector)); | ||
675 | kfree(edid); | ||
676 | return NULL; | ||
677 | } | ||
678 | |||
679 | connector->display_info.raw_edid = (char *)edid; | ||
680 | |||
681 | return edid; | ||
682 | } | ||
683 | EXPORT_SYMBOL(drm_get_edid); | ||
684 | |||
685 | /** | ||
686 | * drm_add_edid_modes - add modes from EDID data, if available | ||
687 | * @connector: connector we're probing | ||
688 | * @edid: edid data | ||
689 | * | ||
690 | * Add the specified modes to the connector's mode list. | ||
691 | * | ||
692 | * Return number of modes added or 0 if we couldn't find any. | ||
693 | */ | ||
694 | int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid) | ||
695 | { | ||
696 | int num_modes = 0; | ||
697 | u32 quirks; | ||
698 | |||
699 | if (edid == NULL) { | ||
700 | return 0; | ||
701 | } | ||
702 | if (!edid_is_valid(edid)) { | ||
703 | dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n", | ||
704 | drm_get_connector_name(connector)); | ||
705 | return 0; | ||
706 | } | ||
707 | |||
708 | quirks = edid_get_quirks(edid); | ||
709 | |||
710 | num_modes += add_established_modes(connector, edid); | ||
711 | num_modes += add_standard_modes(connector, edid); | ||
712 | num_modes += add_detailed_info(connector, edid, quirks); | ||
713 | |||
714 | if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75)) | ||
715 | edid_fixup_preferred(connector, quirks); | ||
716 | |||
717 | connector->display_info.serration_vsync = edid->serration_vsync; | ||
718 | connector->display_info.sync_on_green = edid->sync_on_green; | ||
719 | connector->display_info.composite_sync = edid->composite_sync; | ||
720 | connector->display_info.separate_syncs = edid->separate_syncs; | ||
721 | connector->display_info.blank_to_black = edid->blank_to_black; | ||
722 | connector->display_info.video_level = edid->video_level; | ||
723 | connector->display_info.digital = edid->digital; | ||
724 | connector->display_info.width_mm = edid->width_cm * 10; | ||
725 | connector->display_info.height_mm = edid->height_cm * 10; | ||
726 | connector->display_info.gamma = edid->gamma; | ||
727 | connector->display_info.gtf_supported = edid->default_gtf; | ||
728 | connector->display_info.standard_color = edid->standard_color; | ||
729 | connector->display_info.display_type = edid->display_type; | ||
730 | connector->display_info.active_off_supported = edid->pm_active_off; | ||
731 | connector->display_info.suspend_supported = edid->pm_suspend; | ||
732 | connector->display_info.standby_supported = edid->pm_standby; | ||
733 | connector->display_info.gamma = edid->gamma; | ||
734 | |||
735 | return num_modes; | ||
736 | } | ||
737 | EXPORT_SYMBOL(drm_add_edid_modes); | ||