diff options
author | Dave Airlie <airlied@redhat.com> | 2010-04-19 23:14:38 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2010-04-19 23:14:38 -0400 |
commit | c9c2625ff4fc4ce652e686f895059d2902c01ca0 (patch) | |
tree | 243c07b0380d60d15566064843acb2213b0cacdf /drivers/gpu/drm/drm_edid.c | |
parent | c2b41276da65481d36311a13d69020d150861c43 (diff) | |
parent | 522032da7ed3068cf79f733fb836118d908b7719 (diff) |
Merge branch 'drm-edid-fixes' into drm-core-next
* drm-edid-fixes:
drm/edid: When checking duplicate standard modes, walked the probed list
drm/edid: Fix sync polarity for secondary GTF curve
drm/modes: Fix interlaced mode names
drm/edid: Add secondary GTF curve support
drm/edid: Strengthen the algorithm for standard mode codes
drm/edid: Fix the HDTV hack.
drm/edid: Extend range-based mode addition for EDID 1.4
drm/edid: Add test for monitor reduced blanking support.
drm/edid: Fix preferred mode parse for EDID 1.4
drm/edid: Remove some silly comments
drm/edid: Remove arbitrary EDID extension limit
drm/edid: Add modes for Established Timings III section
drm/edid: Reshuffle mode list construction to closer match the spec
drm/edid: Remove a redundant check
drm/edid: Remove some misleading comments
drm/edid: Fix secondary block fetch.
Diffstat (limited to 'drivers/gpu/drm/drm_edid.c')
-rw-r--r-- | drivers/gpu/drm/drm_edid.c | 789 |
1 files changed, 543 insertions, 246 deletions
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 18f41d7061f0..71886749fa2c 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * Copyright (c) 2006 Luc Verhaegen (quirks list) | 2 | * Copyright (c) 2006 Luc Verhaegen (quirks list) |
3 | * Copyright (c) 2007-2008 Intel Corporation | 3 | * Copyright (c) 2007-2008 Intel Corporation |
4 | * Jesse Barnes <jesse.barnes@intel.com> | 4 | * Jesse Barnes <jesse.barnes@intel.com> |
5 | * Copyright 2010 Red Hat, Inc. | ||
5 | * | 6 | * |
6 | * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from | 7 | * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from |
7 | * FB layer. | 8 | * FB layer. |
@@ -33,10 +34,9 @@ | |||
33 | #include "drmP.h" | 34 | #include "drmP.h" |
34 | #include "drm_edid.h" | 35 | #include "drm_edid.h" |
35 | 36 | ||
36 | /* | 37 | #define EDID_EST_TIMINGS 16 |
37 | * TODO: | 38 | #define EDID_STD_TIMINGS 8 |
38 | * - support EDID 1.4 (incl. CE blocks) | 39 | #define EDID_DETAILED_TIMINGS 4 |
39 | */ | ||
40 | 40 | ||
41 | /* | 41 | /* |
42 | * EDID blocks out in the wild have a variety of bugs, try to collect | 42 | * EDID blocks out in the wild have a variety of bugs, try to collect |
@@ -65,7 +65,8 @@ | |||
65 | 65 | ||
66 | #define LEVEL_DMT 0 | 66 | #define LEVEL_DMT 0 |
67 | #define LEVEL_GTF 1 | 67 | #define LEVEL_GTF 1 |
68 | #define LEVEL_CVT 2 | 68 | #define LEVEL_GTF2 2 |
69 | #define LEVEL_CVT 3 | ||
69 | 70 | ||
70 | static struct edid_quirk { | 71 | static struct edid_quirk { |
71 | char *vendor; | 72 | char *vendor; |
@@ -109,36 +110,38 @@ static struct edid_quirk { | |||
109 | { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 }, | 110 | { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 }, |
110 | }; | 111 | }; |
111 | 112 | ||
113 | /*** DDC fetch and block validation ***/ | ||
112 | 114 | ||
113 | /* Valid EDID header has these bytes */ | ||
114 | static const u8 edid_header[] = { | 115 | static const u8 edid_header[] = { |
115 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 | 116 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 |
116 | }; | 117 | }; |
117 | 118 | ||
118 | /** | 119 | /* |
119 | * drm_edid_is_valid - sanity check EDID data | 120 | * Sanity check the EDID block (base or extension). Return 0 if the block |
120 | * @edid: EDID data | 121 | * doesn't check out, or 1 if it's valid. |
121 | * | ||
122 | * Sanity check the EDID block by looking at the header, the version number | ||
123 | * and the checksum. Return 0 if the EDID doesn't check out, or 1 if it's | ||
124 | * valid. | ||
125 | */ | 122 | */ |
126 | bool drm_edid_is_valid(struct edid *edid) | 123 | static bool |
124 | drm_edid_block_valid(u8 *raw_edid) | ||
127 | { | 125 | { |
128 | int i, score = 0; | 126 | int i; |
129 | u8 csum = 0; | 127 | u8 csum = 0; |
130 | u8 *raw_edid = (u8 *)edid; | 128 | struct edid *edid = (struct edid *)raw_edid; |
131 | 129 | ||
132 | for (i = 0; i < sizeof(edid_header); i++) | 130 | if (raw_edid[0] == 0x00) { |
133 | if (raw_edid[i] == edid_header[i]) | 131 | int score = 0; |
134 | score++; | ||
135 | 132 | ||
136 | if (score == 8) ; | 133 | for (i = 0; i < sizeof(edid_header); i++) |
137 | else if (score >= 6) { | 134 | if (raw_edid[i] == edid_header[i]) |
138 | DRM_DEBUG("Fixing EDID header, your hardware may be failing\n"); | 135 | score++; |
139 | memcpy(raw_edid, edid_header, sizeof(edid_header)); | 136 | |
140 | } else | 137 | if (score == 8) ; |
141 | goto bad; | 138 | else if (score >= 6) { |
139 | DRM_DEBUG("Fixing EDID header, your hardware may be failing\n"); | ||
140 | memcpy(raw_edid, edid_header, sizeof(edid_header)); | ||
141 | } else { | ||
142 | goto bad; | ||
143 | } | ||
144 | } | ||
142 | 145 | ||
143 | for (i = 0; i < EDID_LENGTH; i++) | 146 | for (i = 0; i < EDID_LENGTH; i++) |
144 | csum += raw_edid[i]; | 147 | csum += raw_edid[i]; |
@@ -147,13 +150,21 @@ bool drm_edid_is_valid(struct edid *edid) | |||
147 | goto bad; | 150 | goto bad; |
148 | } | 151 | } |
149 | 152 | ||
150 | if (edid->version != 1) { | 153 | /* per-block-type checks */ |
151 | DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version); | 154 | switch (raw_edid[0]) { |
152 | goto bad; | 155 | case 0: /* base */ |
153 | } | 156 | if (edid->version != 1) { |
157 | DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version); | ||
158 | goto bad; | ||
159 | } | ||
160 | |||
161 | if (edid->revision > 4) | ||
162 | DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n"); | ||
163 | break; | ||
154 | 164 | ||
155 | if (edid->revision > 4) | 165 | default: |
156 | DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n"); | 166 | break; |
167 | } | ||
157 | 168 | ||
158 | return 1; | 169 | return 1; |
159 | 170 | ||
@@ -165,8 +176,158 @@ bad: | |||
165 | } | 176 | } |
166 | return 0; | 177 | return 0; |
167 | } | 178 | } |
179 | |||
180 | /** | ||
181 | * drm_edid_is_valid - sanity check EDID data | ||
182 | * @edid: EDID data | ||
183 | * | ||
184 | * Sanity-check an entire EDID record (including extensions) | ||
185 | */ | ||
186 | bool drm_edid_is_valid(struct edid *edid) | ||
187 | { | ||
188 | int i; | ||
189 | u8 *raw = (u8 *)edid; | ||
190 | |||
191 | if (!edid) | ||
192 | return false; | ||
193 | |||
194 | for (i = 0; i <= edid->extensions; i++) | ||
195 | if (!drm_edid_block_valid(raw + i * EDID_LENGTH)) | ||
196 | return false; | ||
197 | |||
198 | return true; | ||
199 | } | ||
168 | EXPORT_SYMBOL(drm_edid_is_valid); | 200 | EXPORT_SYMBOL(drm_edid_is_valid); |
169 | 201 | ||
202 | #define DDC_ADDR 0x50 | ||
203 | #define DDC_SEGMENT_ADDR 0x30 | ||
204 | /** | ||
205 | * Get EDID information via I2C. | ||
206 | * | ||
207 | * \param adapter : i2c device adaptor | ||
208 | * \param buf : EDID data buffer to be filled | ||
209 | * \param len : EDID data buffer length | ||
210 | * \return 0 on success or -1 on failure. | ||
211 | * | ||
212 | * Try to fetch EDID information by calling i2c driver function. | ||
213 | */ | ||
214 | static int | ||
215 | drm_do_probe_ddc_edid(struct i2c_adapter *adapter, unsigned char *buf, | ||
216 | int block, int len) | ||
217 | { | ||
218 | unsigned char start = block * EDID_LENGTH; | ||
219 | struct i2c_msg msgs[] = { | ||
220 | { | ||
221 | .addr = DDC_ADDR, | ||
222 | .flags = 0, | ||
223 | .len = 1, | ||
224 | .buf = &start, | ||
225 | }, { | ||
226 | .addr = DDC_ADDR, | ||
227 | .flags = I2C_M_RD, | ||
228 | .len = len, | ||
229 | .buf = buf + start, | ||
230 | } | ||
231 | }; | ||
232 | |||
233 | if (i2c_transfer(adapter, msgs, 2) == 2) | ||
234 | return 0; | ||
235 | |||
236 | return -1; | ||
237 | } | ||
238 | |||
239 | static u8 * | ||
240 | drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) | ||
241 | { | ||
242 | int i, j = 0; | ||
243 | u8 *block, *new; | ||
244 | |||
245 | if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL) | ||
246 | return NULL; | ||
247 | |||
248 | /* base block fetch */ | ||
249 | for (i = 0; i < 4; i++) { | ||
250 | if (drm_do_probe_ddc_edid(adapter, block, 0, EDID_LENGTH)) | ||
251 | goto out; | ||
252 | if (drm_edid_block_valid(block)) | ||
253 | break; | ||
254 | } | ||
255 | if (i == 4) | ||
256 | goto carp; | ||
257 | |||
258 | /* if there's no extensions, we're done */ | ||
259 | if (block[0x7e] == 0) | ||
260 | return block; | ||
261 | |||
262 | new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL); | ||
263 | if (!new) | ||
264 | goto out; | ||
265 | block = new; | ||
266 | |||
267 | for (j = 1; j <= block[0x7e]; j++) { | ||
268 | for (i = 0; i < 4; i++) { | ||
269 | if (drm_do_probe_ddc_edid(adapter, block, j, | ||
270 | EDID_LENGTH)) | ||
271 | goto out; | ||
272 | if (drm_edid_block_valid(block + j * EDID_LENGTH)) | ||
273 | break; | ||
274 | } | ||
275 | if (i == 4) | ||
276 | goto carp; | ||
277 | } | ||
278 | |||
279 | return block; | ||
280 | |||
281 | carp: | ||
282 | dev_warn(&connector->dev->pdev->dev, "%s: EDID block %d invalid.\n", | ||
283 | drm_get_connector_name(connector), j); | ||
284 | |||
285 | out: | ||
286 | kfree(block); | ||
287 | return NULL; | ||
288 | } | ||
289 | |||
290 | /** | ||
291 | * Probe DDC presence. | ||
292 | * | ||
293 | * \param adapter : i2c device adaptor | ||
294 | * \return 1 on success | ||
295 | */ | ||
296 | static bool | ||
297 | drm_probe_ddc(struct i2c_adapter *adapter) | ||
298 | { | ||
299 | unsigned char out; | ||
300 | |||
301 | return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0); | ||
302 | } | ||
303 | |||
304 | /** | ||
305 | * drm_get_edid - get EDID data, if available | ||
306 | * @connector: connector we're probing | ||
307 | * @adapter: i2c adapter to use for DDC | ||
308 | * | ||
309 | * Poke the given i2c channel to grab EDID data if possible. If found, | ||
310 | * attach it to the connector. | ||
311 | * | ||
312 | * Return edid data or NULL if we couldn't find any. | ||
313 | */ | ||
314 | struct edid *drm_get_edid(struct drm_connector *connector, | ||
315 | struct i2c_adapter *adapter) | ||
316 | { | ||
317 | struct edid *edid = NULL; | ||
318 | |||
319 | if (drm_probe_ddc(adapter)) | ||
320 | edid = (struct edid *)drm_do_get_edid(connector, adapter); | ||
321 | |||
322 | connector->display_info.raw_edid = (char *)edid; | ||
323 | |||
324 | return edid; | ||
325 | |||
326 | } | ||
327 | EXPORT_SYMBOL(drm_get_edid); | ||
328 | |||
329 | /*** EDID parsing ***/ | ||
330 | |||
170 | /** | 331 | /** |
171 | * edid_vendor - match a string against EDID's obfuscated vendor field | 332 | * edid_vendor - match a string against EDID's obfuscated vendor field |
172 | * @edid: EDID to match | 333 | * @edid: EDID to match |
@@ -517,6 +678,110 @@ static struct drm_display_mode *drm_find_dmt(struct drm_device *dev, | |||
517 | return mode; | 678 | return mode; |
518 | } | 679 | } |
519 | 680 | ||
681 | typedef void detailed_cb(struct detailed_timing *timing, void *closure); | ||
682 | |||
683 | static void | ||
684 | drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) | ||
685 | { | ||
686 | int i; | ||
687 | struct edid *edid = (struct edid *)raw_edid; | ||
688 | |||
689 | if (edid == NULL) | ||
690 | return; | ||
691 | |||
692 | for (i = 0; i < EDID_DETAILED_TIMINGS; i++) | ||
693 | cb(&(edid->detailed_timings[i]), closure); | ||
694 | |||
695 | /* XXX extension block walk */ | ||
696 | } | ||
697 | |||
698 | static void | ||
699 | is_rb(struct detailed_timing *t, void *data) | ||
700 | { | ||
701 | u8 *r = (u8 *)t; | ||
702 | if (r[3] == EDID_DETAIL_MONITOR_RANGE) | ||
703 | if (r[15] & 0x10) | ||
704 | *(bool *)data = true; | ||
705 | } | ||
706 | |||
707 | /* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */ | ||
708 | static bool | ||
709 | drm_monitor_supports_rb(struct edid *edid) | ||
710 | { | ||
711 | if (edid->revision >= 4) { | ||
712 | bool ret; | ||
713 | drm_for_each_detailed_block((u8 *)edid, is_rb, &ret); | ||
714 | return ret; | ||
715 | } | ||
716 | |||
717 | return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0); | ||
718 | } | ||
719 | |||
720 | static void | ||
721 | find_gtf2(struct detailed_timing *t, void *data) | ||
722 | { | ||
723 | u8 *r = (u8 *)t; | ||
724 | if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02) | ||
725 | *(u8 **)data = r; | ||
726 | } | ||
727 | |||
728 | /* Secondary GTF curve kicks in above some break frequency */ | ||
729 | static int | ||
730 | drm_gtf2_hbreak(struct edid *edid) | ||
731 | { | ||
732 | u8 *r = NULL; | ||
733 | drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); | ||
734 | return r ? (r[12] * 2) : 0; | ||
735 | } | ||
736 | |||
737 | static int | ||
738 | drm_gtf2_2c(struct edid *edid) | ||
739 | { | ||
740 | u8 *r = NULL; | ||
741 | drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); | ||
742 | return r ? r[13] : 0; | ||
743 | } | ||
744 | |||
745 | static int | ||
746 | drm_gtf2_m(struct edid *edid) | ||
747 | { | ||
748 | u8 *r = NULL; | ||
749 | drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); | ||
750 | return r ? (r[15] << 8) + r[14] : 0; | ||
751 | } | ||
752 | |||
753 | static int | ||
754 | drm_gtf2_k(struct edid *edid) | ||
755 | { | ||
756 | u8 *r = NULL; | ||
757 | drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); | ||
758 | return r ? r[16] : 0; | ||
759 | } | ||
760 | |||
761 | static int | ||
762 | drm_gtf2_2j(struct edid *edid) | ||
763 | { | ||
764 | u8 *r = NULL; | ||
765 | drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); | ||
766 | return r ? r[17] : 0; | ||
767 | } | ||
768 | |||
769 | /** | ||
770 | * standard_timing_level - get std. timing level(CVT/GTF/DMT) | ||
771 | * @edid: EDID block to scan | ||
772 | */ | ||
773 | static int standard_timing_level(struct edid *edid) | ||
774 | { | ||
775 | if (edid->revision >= 2) { | ||
776 | if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)) | ||
777 | return LEVEL_CVT; | ||
778 | if (drm_gtf2_hbreak(edid)) | ||
779 | return LEVEL_GTF2; | ||
780 | return LEVEL_GTF; | ||
781 | } | ||
782 | return LEVEL_DMT; | ||
783 | } | ||
784 | |||
520 | /* | 785 | /* |
521 | * 0 is reserved. The spec says 0x01 fill for unused timings. Some old | 786 | * 0 is reserved. The spec says 0x01 fill for unused timings. Some old |
522 | * monitors fill with ascii space (0x20) instead. | 787 | * monitors fill with ascii space (0x20) instead. |
@@ -536,22 +801,20 @@ bad_std_timing(u8 a, u8 b) | |||
536 | * | 801 | * |
537 | * Take the standard timing params (in this case width, aspect, and refresh) | 802 | * Take the standard timing params (in this case width, aspect, and refresh) |
538 | * and convert them into a real mode using CVT/GTF/DMT. | 803 | * and convert them into a real mode using CVT/GTF/DMT. |
539 | * | ||
540 | * Punts for now, but should eventually use the FB layer's CVT based mode | ||
541 | * generation code. | ||
542 | */ | 804 | */ |
543 | struct drm_display_mode *drm_mode_std(struct drm_device *dev, | 805 | static struct drm_display_mode * |
544 | struct std_timing *t, | 806 | drm_mode_std(struct drm_connector *connector, struct edid *edid, |
545 | int revision, | 807 | struct std_timing *t, int revision) |
546 | int timing_level) | ||
547 | { | 808 | { |
548 | struct drm_display_mode *mode; | 809 | struct drm_device *dev = connector->dev; |
810 | struct drm_display_mode *m, *mode = NULL; | ||
549 | int hsize, vsize; | 811 | int hsize, vsize; |
550 | int vrefresh_rate; | 812 | int vrefresh_rate; |
551 | unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK) | 813 | unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK) |
552 | >> EDID_TIMING_ASPECT_SHIFT; | 814 | >> EDID_TIMING_ASPECT_SHIFT; |
553 | unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK) | 815 | unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK) |
554 | >> EDID_TIMING_VFREQ_SHIFT; | 816 | >> EDID_TIMING_VFREQ_SHIFT; |
817 | int timing_level = standard_timing_level(edid); | ||
555 | 818 | ||
556 | if (bad_std_timing(t->hsize, t->vfreq_aspect)) | 819 | if (bad_std_timing(t->hsize, t->vfreq_aspect)) |
557 | return NULL; | 820 | return NULL; |
@@ -572,16 +835,36 @@ struct drm_display_mode *drm_mode_std(struct drm_device *dev, | |||
572 | vsize = (hsize * 4) / 5; | 835 | vsize = (hsize * 4) / 5; |
573 | else | 836 | else |
574 | vsize = (hsize * 9) / 16; | 837 | vsize = (hsize * 9) / 16; |
575 | /* HDTV hack */ | 838 | |
576 | if (hsize == 1360 && vsize == 765 && vrefresh_rate == 60) { | 839 | /* HDTV hack, part 1 */ |
577 | mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0, | 840 | if (vrefresh_rate == 60 && |
841 | ((hsize == 1360 && vsize == 765) || | ||
842 | (hsize == 1368 && vsize == 769))) { | ||
843 | hsize = 1366; | ||
844 | vsize = 768; | ||
845 | } | ||
846 | |||
847 | /* | ||
848 | * If this connector already has a mode for this size and refresh | ||
849 | * rate (because it came from detailed or CVT info), use that | ||
850 | * instead. This way we don't have to guess at interlace or | ||
851 | * reduced blanking. | ||
852 | */ | ||
853 | list_for_each_entry(m, &connector->probed_modes, head) | ||
854 | if (m->hdisplay == hsize && m->vdisplay == vsize && | ||
855 | drm_mode_vrefresh(m) == vrefresh_rate) | ||
856 | return NULL; | ||
857 | |||
858 | /* HDTV hack, part 2 */ | ||
859 | if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) { | ||
860 | mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0, | ||
578 | false); | 861 | false); |
579 | mode->hdisplay = 1366; | 862 | mode->hdisplay = 1366; |
580 | mode->vsync_start = mode->vsync_start - 1; | 863 | mode->vsync_start = mode->vsync_start - 1; |
581 | mode->vsync_end = mode->vsync_end - 1; | 864 | mode->vsync_end = mode->vsync_end - 1; |
582 | return mode; | 865 | return mode; |
583 | } | 866 | } |
584 | mode = NULL; | 867 | |
585 | /* check whether it can be found in default mode table */ | 868 | /* check whether it can be found in default mode table */ |
586 | mode = drm_find_dmt(dev, hsize, vsize, vrefresh_rate); | 869 | mode = drm_find_dmt(dev, hsize, vsize, vrefresh_rate); |
587 | if (mode) | 870 | if (mode) |
@@ -593,6 +876,23 @@ struct drm_display_mode *drm_mode_std(struct drm_device *dev, | |||
593 | case LEVEL_GTF: | 876 | case LEVEL_GTF: |
594 | mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0); | 877 | mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0); |
595 | break; | 878 | break; |
879 | case LEVEL_GTF2: | ||
880 | /* | ||
881 | * This is potentially wrong if there's ever a monitor with | ||
882 | * more than one ranges section, each claiming a different | ||
883 | * secondary GTF curve. Please don't do that. | ||
884 | */ | ||
885 | mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0); | ||
886 | if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) { | ||
887 | kfree(mode); | ||
888 | mode = drm_gtf_mode_complex(dev, hsize, vsize, | ||
889 | vrefresh_rate, 0, 0, | ||
890 | drm_gtf2_m(edid), | ||
891 | drm_gtf2_2c(edid), | ||
892 | drm_gtf2_k(edid), | ||
893 | drm_gtf2_2j(edid)); | ||
894 | } | ||
895 | break; | ||
596 | case LEVEL_CVT: | 896 | case LEVEL_CVT: |
597 | mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0, | 897 | mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0, |
598 | false); | 898 | false); |
@@ -716,10 +1016,10 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, | |||
716 | if (mode->vsync_end > mode->vtotal) | 1016 | if (mode->vsync_end > mode->vtotal) |
717 | mode->vtotal = mode->vsync_end + 1; | 1017 | mode->vtotal = mode->vsync_end + 1; |
718 | 1018 | ||
719 | drm_mode_set_name(mode); | ||
720 | |||
721 | drm_mode_do_interlace_quirk(mode, pt); | 1019 | drm_mode_do_interlace_quirk(mode, pt); |
722 | 1020 | ||
1021 | drm_mode_set_name(mode); | ||
1022 | |||
723 | if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) { | 1023 | if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) { |
724 | pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE; | 1024 | pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE; |
725 | } | 1025 | } |
@@ -802,10 +1102,6 @@ static struct drm_display_mode edid_est_modes[] = { | |||
802 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */ | 1102 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */ |
803 | }; | 1103 | }; |
804 | 1104 | ||
805 | #define EDID_EST_TIMINGS 16 | ||
806 | #define EDID_STD_TIMINGS 8 | ||
807 | #define EDID_DETAILED_TIMINGS 4 | ||
808 | |||
809 | /** | 1105 | /** |
810 | * add_established_modes - get est. modes from EDID and add them | 1106 | * add_established_modes - get est. modes from EDID and add them |
811 | * @edid: EDID block to scan | 1107 | * @edid: EDID block to scan |
@@ -833,19 +1129,6 @@ static int add_established_modes(struct drm_connector *connector, struct edid *e | |||
833 | 1129 | ||
834 | return modes; | 1130 | return modes; |
835 | } | 1131 | } |
836 | /** | ||
837 | * stanard_timing_level - get std. timing level(CVT/GTF/DMT) | ||
838 | * @edid: EDID block to scan | ||
839 | */ | ||
840 | static int standard_timing_level(struct edid *edid) | ||
841 | { | ||
842 | if (edid->revision >= 2) { | ||
843 | if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)) | ||
844 | return LEVEL_CVT; | ||
845 | return LEVEL_GTF; | ||
846 | } | ||
847 | return LEVEL_DMT; | ||
848 | } | ||
849 | 1132 | ||
850 | /** | 1133 | /** |
851 | * add_standard_modes - get std. modes from EDID and add them | 1134 | * add_standard_modes - get std. modes from EDID and add them |
@@ -856,22 +1139,14 @@ static int standard_timing_level(struct edid *edid) | |||
856 | */ | 1139 | */ |
857 | static int add_standard_modes(struct drm_connector *connector, struct edid *edid) | 1140 | static int add_standard_modes(struct drm_connector *connector, struct edid *edid) |
858 | { | 1141 | { |
859 | struct drm_device *dev = connector->dev; | ||
860 | int i, modes = 0; | 1142 | int i, modes = 0; |
861 | int timing_level; | ||
862 | |||
863 | timing_level = standard_timing_level(edid); | ||
864 | 1143 | ||
865 | for (i = 0; i < EDID_STD_TIMINGS; i++) { | 1144 | for (i = 0; i < EDID_STD_TIMINGS; i++) { |
866 | struct std_timing *t = &edid->standard_timings[i]; | ||
867 | struct drm_display_mode *newmode; | 1145 | struct drm_display_mode *newmode; |
868 | 1146 | ||
869 | /* If std timings bytes are 1, 1 it's empty */ | 1147 | newmode = drm_mode_std(connector, edid, |
870 | if (t->hsize == 1 && t->vfreq_aspect == 1) | 1148 | &edid->standard_timings[i], |
871 | continue; | 1149 | edid->revision); |
872 | |||
873 | newmode = drm_mode_std(dev, &edid->standard_timings[i], | ||
874 | edid->revision, timing_level); | ||
875 | if (newmode) { | 1150 | if (newmode) { |
876 | drm_mode_probed_add(connector, newmode); | 1151 | drm_mode_probed_add(connector, newmode); |
877 | modes++; | 1152 | modes++; |
@@ -881,36 +1156,86 @@ static int add_standard_modes(struct drm_connector *connector, struct edid *edid | |||
881 | return modes; | 1156 | return modes; |
882 | } | 1157 | } |
883 | 1158 | ||
884 | /* | ||
885 | * XXX fix this for: | ||
886 | * - GTF secondary curve formula | ||
887 | * - EDID 1.4 range offsets | ||
888 | * - CVT extended bits | ||
889 | */ | ||
890 | static bool | 1159 | static bool |
891 | mode_in_range(struct drm_display_mode *mode, struct detailed_timing *timing) | 1160 | mode_is_rb(struct drm_display_mode *mode) |
892 | { | 1161 | { |
893 | struct detailed_data_monitor_range *range; | 1162 | return (mode->htotal - mode->hdisplay == 160) && |
894 | int hsync, vrefresh; | 1163 | (mode->hsync_end - mode->hdisplay == 80) && |
895 | 1164 | (mode->hsync_end - mode->hsync_start == 32) && | |
896 | range = &timing->data.other_data.data.range; | 1165 | (mode->vsync_start - mode->vdisplay == 3); |
1166 | } | ||
897 | 1167 | ||
1168 | static bool | ||
1169 | mode_in_hsync_range(struct drm_display_mode *mode, struct edid *edid, u8 *t) | ||
1170 | { | ||
1171 | int hsync, hmin, hmax; | ||
1172 | |||
1173 | hmin = t[7]; | ||
1174 | if (edid->revision >= 4) | ||
1175 | hmin += ((t[4] & 0x04) ? 255 : 0); | ||
1176 | hmax = t[8]; | ||
1177 | if (edid->revision >= 4) | ||
1178 | hmax += ((t[4] & 0x08) ? 255 : 0); | ||
898 | hsync = drm_mode_hsync(mode); | 1179 | hsync = drm_mode_hsync(mode); |
899 | vrefresh = drm_mode_vrefresh(mode); | ||
900 | 1180 | ||
901 | if (hsync < range->min_hfreq_khz || hsync > range->max_hfreq_khz) | 1181 | return (hsync <= hmax && hsync >= hmin); |
1182 | } | ||
1183 | |||
1184 | static bool | ||
1185 | mode_in_vsync_range(struct drm_display_mode *mode, struct edid *edid, u8 *t) | ||
1186 | { | ||
1187 | int vsync, vmin, vmax; | ||
1188 | |||
1189 | vmin = t[5]; | ||
1190 | if (edid->revision >= 4) | ||
1191 | vmin += ((t[4] & 0x01) ? 255 : 0); | ||
1192 | vmax = t[6]; | ||
1193 | if (edid->revision >= 4) | ||
1194 | vmax += ((t[4] & 0x02) ? 255 : 0); | ||
1195 | vsync = drm_mode_vrefresh(mode); | ||
1196 | |||
1197 | return (vsync <= vmax && vsync >= vmin); | ||
1198 | } | ||
1199 | |||
1200 | static u32 | ||
1201 | range_pixel_clock(struct edid *edid, u8 *t) | ||
1202 | { | ||
1203 | /* unspecified */ | ||
1204 | if (t[9] == 0 || t[9] == 255) | ||
1205 | return 0; | ||
1206 | |||
1207 | /* 1.4 with CVT support gives us real precision, yay */ | ||
1208 | if (edid->revision >= 4 && t[10] == 0x04) | ||
1209 | return (t[9] * 10000) - ((t[12] >> 2) * 250); | ||
1210 | |||
1211 | /* 1.3 is pathetic, so fuzz up a bit */ | ||
1212 | return t[9] * 10000 + 5001; | ||
1213 | } | ||
1214 | |||
1215 | static bool | ||
1216 | mode_in_range(struct drm_display_mode *mode, struct edid *edid, | ||
1217 | struct detailed_timing *timing) | ||
1218 | { | ||
1219 | u32 max_clock; | ||
1220 | u8 *t = (u8 *)timing; | ||
1221 | |||
1222 | if (!mode_in_hsync_range(mode, edid, t)) | ||
902 | return false; | 1223 | return false; |
903 | 1224 | ||
904 | if (vrefresh < range->min_vfreq || vrefresh > range->max_vfreq) | 1225 | if (!mode_in_vsync_range(mode, edid, t)) |
905 | return false; | 1226 | return false; |
906 | 1227 | ||
907 | if (range->pixel_clock_mhz && range->pixel_clock_mhz != 0xff) { | 1228 | if ((max_clock = range_pixel_clock(edid, t))) |
908 | /* be forgiving since it's in units of 10MHz */ | ||
909 | int max_clock = range->pixel_clock_mhz * 10 + 9; | ||
910 | max_clock *= 1000; | ||
911 | if (mode->clock > max_clock) | 1229 | if (mode->clock > max_clock) |
912 | return false; | 1230 | return false; |
913 | } | 1231 | |
1232 | /* 1.4 max horizontal check */ | ||
1233 | if (edid->revision >= 4 && t[10] == 0x04) | ||
1234 | if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3)))) | ||
1235 | return false; | ||
1236 | |||
1237 | if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid)) | ||
1238 | return false; | ||
914 | 1239 | ||
915 | return true; | 1240 | return true; |
916 | } | 1241 | } |
@@ -919,15 +1244,16 @@ mode_in_range(struct drm_display_mode *mode, struct detailed_timing *timing) | |||
919 | * XXX If drm_dmt_modes ever regrows the CVT-R modes (and it will) this will | 1244 | * XXX If drm_dmt_modes ever regrows the CVT-R modes (and it will) this will |
920 | * need to account for them. | 1245 | * need to account for them. |
921 | */ | 1246 | */ |
922 | static int drm_gtf_modes_for_range(struct drm_connector *connector, | 1247 | static int |
923 | struct detailed_timing *timing) | 1248 | drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid, |
1249 | struct detailed_timing *timing) | ||
924 | { | 1250 | { |
925 | int i, modes = 0; | 1251 | int i, modes = 0; |
926 | struct drm_display_mode *newmode; | 1252 | struct drm_display_mode *newmode; |
927 | struct drm_device *dev = connector->dev; | 1253 | struct drm_device *dev = connector->dev; |
928 | 1254 | ||
929 | for (i = 0; i < drm_num_dmt_modes; i++) { | 1255 | for (i = 0; i < drm_num_dmt_modes; i++) { |
930 | if (mode_in_range(drm_dmt_modes + i, timing)) { | 1256 | if (mode_in_range(drm_dmt_modes + i, edid, timing)) { |
931 | newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]); | 1257 | newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]); |
932 | if (newmode) { | 1258 | if (newmode) { |
933 | drm_mode_probed_add(connector, newmode); | 1259 | drm_mode_probed_add(connector, newmode); |
@@ -988,13 +1314,100 @@ static int drm_cvt_modes(struct drm_connector *connector, | |||
988 | return modes; | 1314 | return modes; |
989 | } | 1315 | } |
990 | 1316 | ||
1317 | static const struct { | ||
1318 | short w; | ||
1319 | short h; | ||
1320 | short r; | ||
1321 | short rb; | ||
1322 | } est3_modes[] = { | ||
1323 | /* byte 6 */ | ||
1324 | { 640, 350, 85, 0 }, | ||
1325 | { 640, 400, 85, 0 }, | ||
1326 | { 720, 400, 85, 0 }, | ||
1327 | { 640, 480, 85, 0 }, | ||
1328 | { 848, 480, 60, 0 }, | ||
1329 | { 800, 600, 85, 0 }, | ||
1330 | { 1024, 768, 85, 0 }, | ||
1331 | { 1152, 864, 75, 0 }, | ||
1332 | /* byte 7 */ | ||
1333 | { 1280, 768, 60, 1 }, | ||
1334 | { 1280, 768, 60, 0 }, | ||
1335 | { 1280, 768, 75, 0 }, | ||
1336 | { 1280, 768, 85, 0 }, | ||
1337 | { 1280, 960, 60, 0 }, | ||
1338 | { 1280, 960, 85, 0 }, | ||
1339 | { 1280, 1024, 60, 0 }, | ||
1340 | { 1280, 1024, 85, 0 }, | ||
1341 | /* byte 8 */ | ||
1342 | { 1360, 768, 60, 0 }, | ||
1343 | { 1440, 900, 60, 1 }, | ||
1344 | { 1440, 900, 60, 0 }, | ||
1345 | { 1440, 900, 75, 0 }, | ||
1346 | { 1440, 900, 85, 0 }, | ||
1347 | { 1400, 1050, 60, 1 }, | ||
1348 | { 1400, 1050, 60, 0 }, | ||
1349 | { 1400, 1050, 75, 0 }, | ||
1350 | /* byte 9 */ | ||
1351 | { 1400, 1050, 85, 0 }, | ||
1352 | { 1680, 1050, 60, 1 }, | ||
1353 | { 1680, 1050, 60, 0 }, | ||
1354 | { 1680, 1050, 75, 0 }, | ||
1355 | { 1680, 1050, 85, 0 }, | ||
1356 | { 1600, 1200, 60, 0 }, | ||
1357 | { 1600, 1200, 65, 0 }, | ||
1358 | { 1600, 1200, 70, 0 }, | ||
1359 | /* byte 10 */ | ||
1360 | { 1600, 1200, 75, 0 }, | ||
1361 | { 1600, 1200, 85, 0 }, | ||
1362 | { 1792, 1344, 60, 0 }, | ||
1363 | { 1792, 1344, 85, 0 }, | ||
1364 | { 1856, 1392, 60, 0 }, | ||
1365 | { 1856, 1392, 75, 0 }, | ||
1366 | { 1920, 1200, 60, 1 }, | ||
1367 | { 1920, 1200, 60, 0 }, | ||
1368 | /* byte 11 */ | ||
1369 | { 1920, 1200, 75, 0 }, | ||
1370 | { 1920, 1200, 85, 0 }, | ||
1371 | { 1920, 1440, 60, 0 }, | ||
1372 | { 1920, 1440, 75, 0 }, | ||
1373 | }; | ||
1374 | static const int num_est3_modes = sizeof(est3_modes) / sizeof(est3_modes[0]); | ||
1375 | |||
1376 | static int | ||
1377 | drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing) | ||
1378 | { | ||
1379 | int i, j, m, modes = 0; | ||
1380 | struct drm_display_mode *mode; | ||
1381 | u8 *est = ((u8 *)timing) + 5; | ||
1382 | |||
1383 | for (i = 0; i < 6; i++) { | ||
1384 | for (j = 7; j > 0; j--) { | ||
1385 | m = (i * 8) + (7 - j); | ||
1386 | if (m > num_est3_modes) | ||
1387 | break; | ||
1388 | if (est[i] & (1 << j)) { | ||
1389 | mode = drm_find_dmt(connector->dev, | ||
1390 | est3_modes[m].w, | ||
1391 | est3_modes[m].h, | ||
1392 | est3_modes[m].r | ||
1393 | /*, est3_modes[m].rb */); | ||
1394 | if (mode) { | ||
1395 | drm_mode_probed_add(connector, mode); | ||
1396 | modes++; | ||
1397 | } | ||
1398 | } | ||
1399 | } | ||
1400 | } | ||
1401 | |||
1402 | return modes; | ||
1403 | } | ||
1404 | |||
991 | static int add_detailed_modes(struct drm_connector *connector, | 1405 | static int add_detailed_modes(struct drm_connector *connector, |
992 | struct detailed_timing *timing, | 1406 | struct detailed_timing *timing, |
993 | struct edid *edid, u32 quirks, int preferred) | 1407 | struct edid *edid, u32 quirks, int preferred) |
994 | { | 1408 | { |
995 | int i, modes = 0; | 1409 | int i, modes = 0; |
996 | struct detailed_non_pixel *data = &timing->data.other_data; | 1410 | struct detailed_non_pixel *data = &timing->data.other_data; |
997 | int timing_level = standard_timing_level(edid); | ||
998 | int gtf = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF); | 1411 | int gtf = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF); |
999 | struct drm_display_mode *newmode; | 1412 | struct drm_display_mode *newmode; |
1000 | struct drm_device *dev = connector->dev; | 1413 | struct drm_device *dev = connector->dev; |
@@ -1015,7 +1428,8 @@ static int add_detailed_modes(struct drm_connector *connector, | |||
1015 | switch (data->type) { | 1428 | switch (data->type) { |
1016 | case EDID_DETAIL_MONITOR_RANGE: | 1429 | case EDID_DETAIL_MONITOR_RANGE: |
1017 | if (gtf) | 1430 | if (gtf) |
1018 | modes += drm_gtf_modes_for_range(connector, timing); | 1431 | modes += drm_gtf_modes_for_range(connector, edid, |
1432 | timing); | ||
1019 | break; | 1433 | break; |
1020 | case EDID_DETAIL_STD_MODES: | 1434 | case EDID_DETAIL_STD_MODES: |
1021 | /* Six modes per detailed section */ | 1435 | /* Six modes per detailed section */ |
@@ -1024,8 +1438,8 @@ static int add_detailed_modes(struct drm_connector *connector, | |||
1024 | struct drm_display_mode *newmode; | 1438 | struct drm_display_mode *newmode; |
1025 | 1439 | ||
1026 | std = &data->data.timings[i]; | 1440 | std = &data->data.timings[i]; |
1027 | newmode = drm_mode_std(dev, std, edid->revision, | 1441 | newmode = drm_mode_std(connector, edid, std, |
1028 | timing_level); | 1442 | edid->revision); |
1029 | if (newmode) { | 1443 | if (newmode) { |
1030 | drm_mode_probed_add(connector, newmode); | 1444 | drm_mode_probed_add(connector, newmode); |
1031 | modes++; | 1445 | modes++; |
@@ -1035,6 +1449,9 @@ static int add_detailed_modes(struct drm_connector *connector, | |||
1035 | case EDID_DETAIL_CVT_3BYTE: | 1449 | case EDID_DETAIL_CVT_3BYTE: |
1036 | modes += drm_cvt_modes(connector, timing); | 1450 | modes += drm_cvt_modes(connector, timing); |
1037 | break; | 1451 | break; |
1452 | case EDID_DETAIL_EST_TIMINGS: | ||
1453 | modes += drm_est3_modes(connector, timing); | ||
1454 | break; | ||
1038 | default: | 1455 | default: |
1039 | break; | 1456 | break; |
1040 | } | 1457 | } |
@@ -1058,7 +1475,10 @@ static int add_detailed_info(struct drm_connector *connector, | |||
1058 | 1475 | ||
1059 | for (i = 0; i < EDID_DETAILED_TIMINGS; i++) { | 1476 | for (i = 0; i < EDID_DETAILED_TIMINGS; i++) { |
1060 | struct detailed_timing *timing = &edid->detailed_timings[i]; | 1477 | struct detailed_timing *timing = &edid->detailed_timings[i]; |
1061 | int preferred = (i == 0) && (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING); | 1478 | int preferred = (i == 0); |
1479 | |||
1480 | if (preferred && edid->version == 1 && edid->revision < 4) | ||
1481 | preferred = (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING); | ||
1062 | 1482 | ||
1063 | /* In 1.0, only timings are allowed */ | 1483 | /* In 1.0, only timings are allowed */ |
1064 | if (!timing->pixel_clock && edid->version == 1 && | 1484 | if (!timing->pixel_clock && edid->version == 1 && |
@@ -1088,39 +1508,23 @@ static int add_detailed_info_eedid(struct drm_connector *connector, | |||
1088 | int i, modes = 0; | 1508 | int i, modes = 0; |
1089 | char *edid_ext = NULL; | 1509 | char *edid_ext = NULL; |
1090 | struct detailed_timing *timing; | 1510 | struct detailed_timing *timing; |
1091 | int edid_ext_num; | ||
1092 | int start_offset, end_offset; | 1511 | int start_offset, end_offset; |
1093 | int timing_level; | 1512 | int timing_level; |
1094 | 1513 | ||
1095 | if (edid->version == 1 && edid->revision < 3) { | 1514 | if (edid->version == 1 && edid->revision < 3) |
1096 | /* If the EDID version is less than 1.3, there is no | ||
1097 | * extension EDID. | ||
1098 | */ | ||
1099 | return 0; | 1515 | return 0; |
1100 | } | 1516 | if (!edid->extensions) |
1101 | if (!edid->extensions) { | ||
1102 | /* if there is no extension EDID, it is unnecessary to | ||
1103 | * parse the E-EDID to get detailed info | ||
1104 | */ | ||
1105 | return 0; | 1517 | return 0; |
1106 | } | ||
1107 | |||
1108 | /* Chose real EDID extension number */ | ||
1109 | edid_ext_num = edid->extensions > DRM_MAX_EDID_EXT_NUM ? | ||
1110 | DRM_MAX_EDID_EXT_NUM : edid->extensions; | ||
1111 | 1518 | ||
1112 | /* Find CEA extension */ | 1519 | /* Find CEA extension */ |
1113 | for (i = 0; i < edid_ext_num; i++) { | 1520 | for (i = 0; i < edid->extensions; i++) { |
1114 | edid_ext = (char *)edid + EDID_LENGTH * (i + 1); | 1521 | edid_ext = (char *)edid + EDID_LENGTH * (i + 1); |
1115 | /* This block is CEA extension */ | ||
1116 | if (edid_ext[0] == 0x02) | 1522 | if (edid_ext[0] == 0x02) |
1117 | break; | 1523 | break; |
1118 | } | 1524 | } |
1119 | 1525 | ||
1120 | if (i == edid_ext_num) { | 1526 | if (i == edid->extensions) |
1121 | /* if there is no additional timing EDID block, return */ | ||
1122 | return 0; | 1527 | return 0; |
1123 | } | ||
1124 | 1528 | ||
1125 | /* Get the start offset of detailed timing block */ | 1529 | /* Get the start offset of detailed timing block */ |
1126 | start_offset = edid_ext[2]; | 1530 | start_offset = edid_ext[2]; |
@@ -1144,123 +1548,6 @@ static int add_detailed_info_eedid(struct drm_connector *connector, | |||
1144 | return modes; | 1548 | return modes; |
1145 | } | 1549 | } |
1146 | 1550 | ||
1147 | #define DDC_ADDR 0x50 | ||
1148 | /** | ||
1149 | * Get EDID information via I2C. | ||
1150 | * | ||
1151 | * \param adapter : i2c device adaptor | ||
1152 | * \param buf : EDID data buffer to be filled | ||
1153 | * \param len : EDID data buffer length | ||
1154 | * \return 0 on success or -1 on failure. | ||
1155 | * | ||
1156 | * Try to fetch EDID information by calling i2c driver function. | ||
1157 | */ | ||
1158 | int drm_do_probe_ddc_edid(struct i2c_adapter *adapter, | ||
1159 | unsigned char *buf, int len) | ||
1160 | { | ||
1161 | unsigned char start = 0x0; | ||
1162 | struct i2c_msg msgs[] = { | ||
1163 | { | ||
1164 | .addr = DDC_ADDR, | ||
1165 | .flags = 0, | ||
1166 | .len = 1, | ||
1167 | .buf = &start, | ||
1168 | }, { | ||
1169 | .addr = DDC_ADDR, | ||
1170 | .flags = I2C_M_RD, | ||
1171 | .len = len, | ||
1172 | .buf = buf, | ||
1173 | } | ||
1174 | }; | ||
1175 | |||
1176 | if (i2c_transfer(adapter, msgs, 2) == 2) | ||
1177 | return 0; | ||
1178 | |||
1179 | return -1; | ||
1180 | } | ||
1181 | EXPORT_SYMBOL(drm_do_probe_ddc_edid); | ||
1182 | |||
1183 | static int drm_ddc_read_edid(struct drm_connector *connector, | ||
1184 | struct i2c_adapter *adapter, | ||
1185 | char *buf, int len) | ||
1186 | { | ||
1187 | int i; | ||
1188 | |||
1189 | for (i = 0; i < 4; i++) { | ||
1190 | if (drm_do_probe_ddc_edid(adapter, buf, len)) | ||
1191 | return -1; | ||
1192 | if (drm_edid_is_valid((struct edid *)buf)) | ||
1193 | return 0; | ||
1194 | } | ||
1195 | |||
1196 | /* repeated checksum failures; warn, but carry on */ | ||
1197 | dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n", | ||
1198 | drm_get_connector_name(connector)); | ||
1199 | return -1; | ||
1200 | } | ||
1201 | |||
1202 | /** | ||
1203 | * drm_get_edid - get EDID data, if available | ||
1204 | * @connector: connector we're probing | ||
1205 | * @adapter: i2c adapter to use for DDC | ||
1206 | * | ||
1207 | * Poke the given connector's i2c channel to grab EDID data if possible. | ||
1208 | * | ||
1209 | * Return edid data or NULL if we couldn't find any. | ||
1210 | */ | ||
1211 | struct edid *drm_get_edid(struct drm_connector *connector, | ||
1212 | struct i2c_adapter *adapter) | ||
1213 | { | ||
1214 | int ret; | ||
1215 | struct edid *edid; | ||
1216 | |||
1217 | edid = kmalloc(EDID_LENGTH * (DRM_MAX_EDID_EXT_NUM + 1), | ||
1218 | GFP_KERNEL); | ||
1219 | if (edid == NULL) { | ||
1220 | dev_warn(&connector->dev->pdev->dev, | ||
1221 | "Failed to allocate EDID\n"); | ||
1222 | goto end; | ||
1223 | } | ||
1224 | |||
1225 | /* Read first EDID block */ | ||
1226 | ret = drm_ddc_read_edid(connector, adapter, | ||
1227 | (unsigned char *)edid, EDID_LENGTH); | ||
1228 | if (ret != 0) | ||
1229 | goto clean_up; | ||
1230 | |||
1231 | /* There are EDID extensions to be read */ | ||
1232 | if (edid->extensions != 0) { | ||
1233 | int edid_ext_num = edid->extensions; | ||
1234 | |||
1235 | if (edid_ext_num > DRM_MAX_EDID_EXT_NUM) { | ||
1236 | dev_warn(&connector->dev->pdev->dev, | ||
1237 | "The number of extension(%d) is " | ||
1238 | "over max (%d), actually read number (%d)\n", | ||
1239 | edid_ext_num, DRM_MAX_EDID_EXT_NUM, | ||
1240 | DRM_MAX_EDID_EXT_NUM); | ||
1241 | /* Reset EDID extension number to be read */ | ||
1242 | edid_ext_num = DRM_MAX_EDID_EXT_NUM; | ||
1243 | } | ||
1244 | /* Read EDID including extensions too */ | ||
1245 | ret = drm_ddc_read_edid(connector, adapter, (char *)edid, | ||
1246 | EDID_LENGTH * (edid_ext_num + 1)); | ||
1247 | if (ret != 0) | ||
1248 | goto clean_up; | ||
1249 | |||
1250 | } | ||
1251 | |||
1252 | connector->display_info.raw_edid = (char *)edid; | ||
1253 | goto end; | ||
1254 | |||
1255 | clean_up: | ||
1256 | kfree(edid); | ||
1257 | edid = NULL; | ||
1258 | end: | ||
1259 | return edid; | ||
1260 | |||
1261 | } | ||
1262 | EXPORT_SYMBOL(drm_get_edid); | ||
1263 | |||
1264 | #define HDMI_IDENTIFIER 0x000C03 | 1551 | #define HDMI_IDENTIFIER 0x000C03 |
1265 | #define VENDOR_BLOCK 0x03 | 1552 | #define VENDOR_BLOCK 0x03 |
1266 | /** | 1553 | /** |
@@ -1273,7 +1560,7 @@ EXPORT_SYMBOL(drm_get_edid); | |||
1273 | bool drm_detect_hdmi_monitor(struct edid *edid) | 1560 | bool drm_detect_hdmi_monitor(struct edid *edid) |
1274 | { | 1561 | { |
1275 | char *edid_ext = NULL; | 1562 | char *edid_ext = NULL; |
1276 | int i, hdmi_id, edid_ext_num; | 1563 | int i, hdmi_id; |
1277 | int start_offset, end_offset; | 1564 | int start_offset, end_offset; |
1278 | bool is_hdmi = false; | 1565 | bool is_hdmi = false; |
1279 | 1566 | ||
@@ -1281,19 +1568,15 @@ bool drm_detect_hdmi_monitor(struct edid *edid) | |||
1281 | if (edid == NULL || edid->extensions == 0) | 1568 | if (edid == NULL || edid->extensions == 0) |
1282 | goto end; | 1569 | goto end; |
1283 | 1570 | ||
1284 | /* Chose real EDID extension number */ | ||
1285 | edid_ext_num = edid->extensions > DRM_MAX_EDID_EXT_NUM ? | ||
1286 | DRM_MAX_EDID_EXT_NUM : edid->extensions; | ||
1287 | |||
1288 | /* Find CEA extension */ | 1571 | /* Find CEA extension */ |
1289 | for (i = 0; i < edid_ext_num; i++) { | 1572 | for (i = 0; i < edid->extensions; i++) { |
1290 | edid_ext = (char *)edid + EDID_LENGTH * (i + 1); | 1573 | edid_ext = (char *)edid + EDID_LENGTH * (i + 1); |
1291 | /* This block is CEA extension */ | 1574 | /* This block is CEA extension */ |
1292 | if (edid_ext[0] == 0x02) | 1575 | if (edid_ext[0] == 0x02) |
1293 | break; | 1576 | break; |
1294 | } | 1577 | } |
1295 | 1578 | ||
1296 | if (i == edid_ext_num) | 1579 | if (i == edid->extensions) |
1297 | goto end; | 1580 | goto end; |
1298 | 1581 | ||
1299 | /* Data block offset in CEA extension block */ | 1582 | /* Data block offset in CEA extension block */ |
@@ -1348,10 +1631,24 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid) | |||
1348 | 1631 | ||
1349 | quirks = edid_get_quirks(edid); | 1632 | quirks = edid_get_quirks(edid); |
1350 | 1633 | ||
1351 | num_modes += add_established_modes(connector, edid); | 1634 | /* |
1352 | num_modes += add_standard_modes(connector, edid); | 1635 | * EDID spec says modes should be preferred in this order: |
1636 | * - preferred detailed mode | ||
1637 | * - other detailed modes from base block | ||
1638 | * - detailed modes from extension blocks | ||
1639 | * - CVT 3-byte code modes | ||
1640 | * - standard timing codes | ||
1641 | * - established timing codes | ||
1642 | * - modes inferred from GTF or CVT range information | ||
1643 | * | ||
1644 | * We don't quite implement this yet, but we're close. | ||
1645 | * | ||
1646 | * XXX order for additional mode types in extension blocks? | ||
1647 | */ | ||
1353 | num_modes += add_detailed_info(connector, edid, quirks); | 1648 | num_modes += add_detailed_info(connector, edid, quirks); |
1354 | num_modes += add_detailed_info_eedid(connector, edid, quirks); | 1649 | num_modes += add_detailed_info_eedid(connector, edid, quirks); |
1650 | num_modes += add_standard_modes(connector, edid); | ||
1651 | num_modes += add_established_modes(connector, edid); | ||
1355 | 1652 | ||
1356 | if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75)) | 1653 | if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75)) |
1357 | edid_fixup_preferred(connector, quirks); | 1654 | edid_fixup_preferred(connector, quirks); |