summaryrefslogtreecommitdiff
path: root/sys/dev/videomode/edid.c
blob: 711e8ae9a2d36cdd65ac507412af8f7d8c81f9de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
/* $OpenBSD: edid.c,v 1.6 2024/11/02 15:00:26 miod Exp $ */
/* $NetBSD: edid.c,v 1.5 2007/03/07 19:56:40 macallan Exp $ */

/*-
 * Copyright (c) 2006 Itronix Inc.
 * All rights reserved.
 *
 * Written by Garrett D'Amore for Itronix Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of Itronix Inc. may not be used to endorse
 *    or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */ 

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <dev/videomode/videomode.h>
#include <dev/videomode/ediddevs.h>
#include <dev/videomode/edidreg.h>
#include <dev/videomode/edidvar.h>
#include <dev/videomode/vesagtf.h>

const char *edid_findvendor(const char *);
const char *edid_findproduct(const char *, uint16_t);
void edid_strchomp(char *);
const struct videomode *edid_mode_lookup_list(const char *);
int edid_std_timing(uint8_t *, struct videomode *);
int edid_det_timing(uint8_t *, struct videomode *);
void edid_block(struct edid_info *, uint8_t *);

/* #define EDID_DEBUG */
#define	EDIDVERBOSE	1
#define	DIVIDE(x,y)	(((x) + ((y) / 2)) / (y))

static const char *_edid_modes[] =  {
	"1280x1024x75",
	"1024x768x75",
	"1024x768x70",
	"1024x768x60",
	"1024x768x87i",
	"832x768x74",	/* rounding error, 74.55 Hz aka "832x624x75" */
	"800x600x75",
	"800x600x72",
	"800x600x60",
	"800x600x56",
	"640x480x75",
	"640x480x72",
	"640x480x67",
	"640x480x60",
	"720x400x85",	/* should this really be "720x400x88" ? */
	"720x400x70",	/* hmm... videomode.c doesn't have this one */
};

#ifdef	EDIDVERBOSE
struct edid_vendor {
	const char	*vendor;
	const char	*name;
};

struct edid_product {
	const char	*vendor;
	uint16_t	product;
	const char	*name;
};

#include <dev/videomode/ediddevs_data.h>
#endif	/* EDIDVERBOSE */

const char *
edid_findvendor(const char *vendor)
{
#ifdef	EDIDVERBOSE
	int	n;

	for (n = 0; n < edid_nvendors; n++)
		if (memcmp(edid_vendors[n].vendor, vendor, 3) == 0)
			return (edid_vendors[n].name);
#endif
	return NULL;
}

const char *
edid_findproduct(const char *vendor, uint16_t product)
{
#ifdef	EDIDVERBOSE
	int	n;

	for (n = 0; n < edid_nproducts; n++)
		if ((edid_products[n].product == product) &&
		    (memcmp(edid_products[n].vendor, vendor, 3) == 0))
			return (edid_products[n].name);
#endif	/* EDIDVERBOSE */
	return NULL;

}

void
edid_strchomp(char *ptr)
{
	for (;;) {
		switch (*ptr) {
		case 0:
			return;
		case '\r':
		case '\n':
			*ptr = 0;
			return;
		}
		ptr++;
	}
}

int
edid_is_valid(uint8_t *d)
{
	int sum = 0, i;
	uint8_t sig[8] = EDID_SIGNATURE;
	
	if (memcmp(d, sig, 8) != 0)
		return EINVAL;
	
	for (i = 0; i < 128; i++)
		sum += d[i];
	if ((sum & 0xff) != 0)
		return EINVAL;
		
	return 0;
}

#ifdef EDID_DEBUG
void
edid_print(struct edid_info *edid)
{
	int	i;

	if (edid == NULL)
		return;
	printf("Vendor: [%s] %s\n", edid->edid_vendor, edid->edid_vendorname);
	printf("Product: [%04X] %s\n", edid->edid_product,
	    edid->edid_productname);
	printf("Serial number: %s\n", edid->edid_serial);
	printf("Manufactured %d Week %d\n",
	    edid->edid_year, edid->edid_week);
	printf("EDID Version %d.%d\n", edid->edid_version,
	    edid->edid_revision);
	printf("EDID Comment: %s\n", edid->edid_comment);

	printf("Video Input: %x\n", edid->edid_video_input);
	if (edid->edid_video_input & EDID_VIDEO_INPUT_DIGITAL) {
		printf("\tDigital");
		if (edid->edid_video_input & EDID_VIDEO_INPUT_DFP1_COMPAT)
			printf(" (DFP 1.x compatible)");
		printf("\n");
	} else {
		printf("\tAnalog\n");
		switch (EDID_VIDEO_INPUT_LEVEL(edid->edid_video_input)) {
		case 0:
			printf("\t-0.7, 0.3V\n");
			break;
		case 1:
			printf("\t-0.714, 0.286V\n");
			break;
		case 2:
			printf("\t-1.0, 0.4V\n");
			break;
		case 3:
			printf("\t-0.7, 0.0V\n");
			break;
		}
		if (edid->edid_video_input & EDID_VIDEO_INPUT_BLANK_TO_BLACK)
			printf("\tBlank-to-black setup\n");
		if (edid->edid_video_input & EDID_VIDEO_INPUT_SEPARATE_SYNCS)
			printf("\tSeparate syncs\n");
		if (edid->edid_video_input & EDID_VIDEO_INPUT_COMPOSITE_SYNC)
			printf("\tComposite sync\n");
		if (edid->edid_video_input & EDID_VIDEO_INPUT_SYNC_ON_GRN)
			printf("\tSync on green\n");
		if (edid->edid_video_input & EDID_VIDEO_INPUT_SERRATION)
			printf("\tSerration vsync\n");
	}

	printf("Gamma: %d.%02d\n",
	    edid->edid_gamma / 100, edid->edid_gamma % 100);

	printf("Max Size: %d cm x %d cm\n",
	    edid->edid_max_hsize, edid->edid_max_vsize);

	printf("Features: %x\n", edid->edid_features);
	if (edid->edid_features & EDID_FEATURES_STANDBY)
		printf("\tDPMS standby\n");
	if (edid->edid_features & EDID_FEATURES_SUSPEND)
		printf("\tDPMS suspend\n");
	if (edid->edid_features & EDID_FEATURES_ACTIVE_OFF)
		printf("\tDPMS active-off\n");
	switch (EDID_FEATURES_DISP_TYPE(edid->edid_features)) {
	case EDID_FEATURES_DISP_TYPE_MONO:
		printf("\tMonochrome\n");
		break;
	case EDID_FEATURES_DISP_TYPE_RGB:
		printf("\tRGB\n");
		break;
	case EDID_FEATURES_DISP_TYPE_NON_RGB:
		printf("\tMulticolor\n");
		break;
	case EDID_FEATURES_DISP_TYPE_UNDEFINED:
		printf("\tUndefined monitor type\n");
		break;
	}
	if (edid->edid_features & EDID_FEATURES_STD_COLOR)
		printf("\tStandard color space\n");
	if (edid->edid_features & EDID_FEATURES_PREFERRED_TIMING)
		printf("\tPreferred timing\n");
	if (edid->edid_features & EDID_FEATURES_DEFAULT_GTF)
		printf("\tDefault GTF supported\n");

	printf("Chroma Info:\n");
	printf("\tRed X: 0.%03d\n", edid->edid_chroma.ec_redx);
	printf("\tRed Y: 0.%03d\n", edid->edid_chroma.ec_redy);
	printf("\tGrn X: 0.%03d\n", edid->edid_chroma.ec_greenx);
	printf("\tGrn Y: 0.%03d\n", edid->edid_chroma.ec_greeny);
	printf("\tBlu X: 0.%03d\n", edid->edid_chroma.ec_bluex);
	printf("\tBlu Y: 0.%03d\n", edid->edid_chroma.ec_bluey);
	printf("\tWht X: 0.%03d\n", edid->edid_chroma.ec_whitex);
	printf("\tWht Y: 0.%03d\n", edid->edid_chroma.ec_whitey);

	if (edid->edid_have_range) {
		printf("Range:\n");
		printf("\tHorizontal: %d - %d kHz\n",
		    edid->edid_range.er_min_hfreq,
		    edid->edid_range.er_max_hfreq);
		printf("\tVertical: %d - %d Hz\n",
		    edid->edid_range.er_min_vfreq,
		    edid->edid_range.er_max_vfreq);
		printf("\tMax Dot Clock: %d MHz\n",
		    edid->edid_range.er_max_clock);
		if (edid->edid_range.er_have_gtf2) {
			printf("\tGTF2 hfreq: %d\n",
			    edid->edid_range.er_gtf2_hfreq);
			printf("\tGTF2 C: %d\n", edid->edid_range.er_gtf2_c);
			printf("\tGTF2 M: %d\n", edid->edid_range.er_gtf2_m);
			printf("\tGTF2 J: %d\n", edid->edid_range.er_gtf2_j);
			printf("\tGTF2 K: %d\n", edid->edid_range.er_gtf2_k);
		}
	}
	printf("Video modes:\n");
	for (i = 0; i < edid->edid_nmodes; i++) {
		printf("\t%dx%d @ %dHz\n",
		    edid->edid_modes[i].hdisplay,
		    edid->edid_modes[i].vdisplay,
		    DIVIDE(DIVIDE(edid->edid_modes[i].dot_clock * 1000,
			       edid->edid_modes[i].htotal),
			edid->edid_modes[i].vtotal));
	}
	if (edid->edid_preferred_mode)
		printf("Preferred mode: %dx%d @ %dHz\n",
		    edid->edid_preferred_mode->hdisplay,
		    edid->edid_preferred_mode->vdisplay,
		    DIVIDE(DIVIDE(edid->edid_preferred_mode->dot_clock * 1000,
			       edid->edid_preferred_mode->htotal),
			edid->edid_preferred_mode->vtotal));
}
#endif

const struct videomode *
edid_mode_lookup_list(const char *name)
{
	int	i;

	for (i = 0; i < videomode_count; i++)
		if (strcmp(name, videomode_list[i].name) == 0)
			return &videomode_list[i];
	return NULL;
}

int
edid_std_timing(uint8_t *data, struct videomode *vmp)
{
	unsigned			x, y, f;
	const struct videomode		*lookup;
	char				name[80];

	if ((data[0] == 1 && data[1] == 1) ||
	    (data[0] == 0 && data[1] == 0) ||
	    (data[0] == 0x20 && data[1] == 0x20))
		return 0;

	x = EDID_STD_TIMING_HRES(data);
	switch (EDID_STD_TIMING_RATIO(data)) {
	case EDID_STD_TIMING_RATIO_16_10:
		y = x * 10 / 16;
		break;
	case EDID_STD_TIMING_RATIO_4_3:
		y = x * 3 / 4;
		break;
	case EDID_STD_TIMING_RATIO_5_4:
		y = x * 4 / 5;
		break;
	case EDID_STD_TIMING_RATIO_16_9:
	default:
		y = x * 9 / 16;
		break;
	}
	f = EDID_STD_TIMING_VFREQ(data);

	/* first try to lookup the mode as a DMT timing */
	snprintf(name, sizeof (name), "%dx%dx%d", x, y, f);
	if ((lookup = edid_mode_lookup_list(name)) != NULL) {
		*vmp = *lookup;
	}

	/* failing that, calculate it using gtf */
	else {
		/*
		 * Hmm. I'm not using alternate GTF timings, which
		 * could, in theory, be present.
		 */
		vesagtf_mode(x, y, f, vmp);
	}
	return 1;
}

int
edid_det_timing(uint8_t *data, struct videomode *vmp)
{
	unsigned	hactive, hblank, hsyncwid, hsyncoff;
	unsigned	vactive, vblank, vsyncwid, vsyncoff;
	uint8_t		flags;

	flags = EDID_DET_TIMING_FLAGS(data);

	/* we don't support stereo modes (for now) */
	if (flags & (EDID_DET_TIMING_FLAG_STEREO |
		EDID_DET_TIMING_FLAG_STEREO1))
		return 0;

	vmp->dot_clock = EDID_DET_TIMING_DOT_CLOCK(data) / 1000;

	hactive = EDID_DET_TIMING_HACTIVE(data);
	hblank = EDID_DET_TIMING_HBLANK(data);
	hsyncwid = EDID_DET_TIMING_HSYNC_WIDTH(data);
	hsyncoff = EDID_DET_TIMING_HSYNC_OFFSET(data);

	vactive = EDID_DET_TIMING_VACTIVE(data);
	vblank = EDID_DET_TIMING_VBLANK(data);
	vsyncwid = EDID_DET_TIMING_VSYNC_WIDTH(data);
	vsyncoff = EDID_DET_TIMING_VSYNC_OFFSET(data);
	
	/* XXX: I'm not doing anything with the borders, should I? */

	vmp->hdisplay = hactive;
	vmp->htotal = hactive + hblank;
	vmp->hsync_start = hactive + hsyncoff;
	vmp->hsync_end = vmp->hsync_start + hsyncwid;

	vmp->vdisplay = vactive;
	vmp->vtotal = vactive + vblank;
	vmp->vsync_start = vactive + vsyncoff;
	vmp->vsync_end = vmp->vsync_start + vsyncwid;

	vmp->flags = 0;

	if (flags & EDID_DET_TIMING_FLAG_INTERLACE)
		vmp->flags |= VID_INTERLACE;
	if (flags & EDID_DET_TIMING_FLAG_HSYNC_POSITIVE)
		vmp->flags |= VID_PHSYNC;
	else
		vmp->flags |= VID_NHSYNC;

	if (flags & EDID_DET_TIMING_FLAG_VSYNC_POSITIVE)
		vmp->flags |= VID_PVSYNC;
	else
		vmp->flags |= VID_NVSYNC;

	return 1;
}

void
edid_block(struct edid_info *edid, uint8_t *data)
{
	int			i;
	struct videomode	mode;

	if (EDID_BLOCK_IS_DET_TIMING(data)) {
		if (edid_det_timing(data, &mode)) {
			edid->edid_modes[edid->edid_nmodes] = mode;
			if (edid->edid_preferred_mode == NULL) {
				edid->edid_preferred_mode =
				    &edid->edid_modes[edid->edid_nmodes];
			}
			edid->edid_nmodes++;	
		}
		return;
	}

	switch (EDID_BLOCK_TYPE(data)) {
	case EDID_DESC_BLOCK_TYPE_SERIAL:
		memcpy(edid->edid_serial,
		    data + EDID_DESC_ASCII_DATA_OFFSET,
		    EDID_DESC_ASCII_DATA_LEN);
		edid->edid_serial[sizeof (edid->edid_serial) - 1] = 0;
		break;

	case EDID_DESC_BLOCK_TYPE_ASCII:
		memcpy(edid->edid_comment,
		    data + EDID_DESC_ASCII_DATA_OFFSET,
		    EDID_DESC_ASCII_DATA_LEN);
		edid->edid_comment[sizeof (edid->edid_comment) - 1] = 0;
		break;

	case EDID_DESC_BLOCK_TYPE_RANGE:
		edid->edid_have_range = 1;
		edid->edid_range.er_min_vfreq =	
		    EDID_DESC_RANGE_MIN_VFREQ(data);
		edid->edid_range.er_max_vfreq =	
		    EDID_DESC_RANGE_MAX_VFREQ(data);
		edid->edid_range.er_min_hfreq =	
		    EDID_DESC_RANGE_MIN_HFREQ(data);
		edid->edid_range.er_max_hfreq =	
		    EDID_DESC_RANGE_MAX_HFREQ(data);
		edid->edid_range.er_max_clock =
		    EDID_DESC_RANGE_MAX_CLOCK(data);
		if (EDID_DESC_RANGE_HAVE_GTF2(data)) {
			edid->edid_range.er_have_gtf2 = 1;
			edid->edid_range.er_gtf2_hfreq =
			    EDID_DESC_RANGE_GTF2_HFREQ(data);
			edid->edid_range.er_gtf2_c =
			    EDID_DESC_RANGE_GTF2_C(data);
			edid->edid_range.er_gtf2_m =
			    EDID_DESC_RANGE_GTF2_M(data);
			edid->edid_range.er_gtf2_j =
			    EDID_DESC_RANGE_GTF2_J(data);
			edid->edid_range.er_gtf2_k =
			    EDID_DESC_RANGE_GTF2_K(data);
		}
		break;

	case EDID_DESC_BLOCK_TYPE_NAME:
		/* copy the product name into place */
		memcpy(edid->edid_productname,
		    data + EDID_DESC_ASCII_DATA_OFFSET,
		    EDID_DESC_ASCII_DATA_LEN);
		break;

	case EDID_DESC_BLOCK_TYPE_STD_TIMING:
		data += EDID_DESC_STD_TIMING_START;
		for (i = 0; i < EDID_DESC_STD_TIMING_COUNT; i++) {
			if (edid_std_timing(data, &mode)) {
				edid->edid_modes[edid->edid_nmodes] = mode;
				edid->edid_nmodes++;
			}
			data += 2;
		}
		break;

	case EDID_DESC_BLOCK_TYPE_COLOR_POINT:
		/* XXX: not implemented yet */
		break;
	}
}

/*
 * Gets EDID version in BCD, e.g. EDID v1.3  returned as 0x0103
 */
int
edid_parse(uint8_t *data, struct edid_info *edid)
{
	uint16_t		manfid, estmodes;
	const struct videomode	*vmp;
	int			i;
	const char		*name;
	int max_dotclock = 0;
	int mhz;

	if (edid_is_valid(data) != 0)
		return -1;

	/* get product identification */
	manfid = EDID_VENDOR_ID(data);
	edid->edid_vendor[0] = EDID_MANFID_0(manfid);
	edid->edid_vendor[1] = EDID_MANFID_1(manfid);
	edid->edid_vendor[2] = EDID_MANFID_2(manfid);
	edid->edid_vendor[3] = 0;	/* null terminate for convenience */

	edid->edid_product = data[EDID_OFFSET_PRODUCT_ID] + 
	    (data[EDID_OFFSET_PRODUCT_ID + 1] << 8);

	name = edid_findvendor(edid->edid_vendor);
	if (name != NULL) {
		snprintf(edid->edid_vendorname,
		    sizeof (edid->edid_vendorname), "%s", name);
	}
	edid->edid_vendorname[sizeof (edid->edid_vendorname) - 1] = 0;

	name = edid_findproduct(edid->edid_vendor, edid->edid_product);
	if (name != NULL) {
		snprintf(edid->edid_productname,
		    sizeof (edid->edid_productname), "%s", name);
	}
	edid->edid_productname[sizeof (edid->edid_productname) - 1] = 0;

	snprintf(edid->edid_serial, sizeof (edid->edid_serial), "%08x",
	    EDID_SERIAL_NUMBER(data));

	edid->edid_week = EDID_WEEK(data);
	edid->edid_year = EDID_YEAR(data);

	/* get edid revision */
	edid->edid_version = EDID_VERSION(data);
	edid->edid_revision = EDID_REVISION(data);

	edid->edid_video_input = EDID_VIDEO_INPUT(data);
	edid->edid_max_hsize = EDID_MAX_HSIZE(data);
	edid->edid_max_vsize = EDID_MAX_VSIZE(data);

	edid->edid_gamma = EDID_GAMMA(data);
	edid->edid_features = EDID_FEATURES(data);

	edid->edid_chroma.ec_redx = EDID_CHROMA_REDX(data);
	edid->edid_chroma.ec_redy = EDID_CHROMA_REDX(data);
	edid->edid_chroma.ec_greenx = EDID_CHROMA_GREENX(data);
	edid->edid_chroma.ec_greeny = EDID_CHROMA_GREENY(data);
	edid->edid_chroma.ec_bluex = EDID_CHROMA_BLUEX(data);
	edid->edid_chroma.ec_bluey = EDID_CHROMA_BLUEY(data);
	edid->edid_chroma.ec_whitex = EDID_CHROMA_WHITEX(data);
	edid->edid_chroma.ec_whitey = EDID_CHROMA_WHITEY(data);

	/* lookup established modes */
	edid->edid_nmodes = 0;
	edid->edid_preferred_mode = NULL;
	estmodes = EDID_EST_TIMING(data);
	for (i = 0; i < 16; i++) {
		if (estmodes & (1 << i)) {
			vmp = edid_mode_lookup_list(_edid_modes[i]);
			if (vmp != NULL) {
				edid->edid_modes[edid->edid_nmodes] = *vmp;
				edid->edid_nmodes++;
			}
#ifdef DIAGNOSTIC
			  else
				printf("no data for est. mode %s\n",
				    _edid_modes[i]);
#endif
		}
	}

	/* do standard timing section */
	for (i = 0; i < EDID_STD_TIMING_COUNT; i++) {
		struct videomode	mode;
		if (edid_std_timing(data + EDID_OFFSET_STD_TIMING + i * 2,
			&mode)) {
			edid->edid_modes[edid->edid_nmodes] = mode;
			edid->edid_nmodes++;
		}
	}
	/* do detailed timings and descriptors */
	for (i = 0; i < EDID_BLOCK_COUNT; i++) {
		edid_block(edid, data + EDID_OFFSET_DESC_BLOCK +
		    i * EDID_BLOCK_SIZE);
	}

	edid_strchomp(edid->edid_vendorname);
	edid_strchomp(edid->edid_productname);
	edid_strchomp(edid->edid_serial);
	edid_strchomp(edid->edid_comment);

	/*
	 * XXX
	 * some monitors lie about their maximum supported dot clock
	 * by claiming to support modes which need a higher dot clock
	 * than the stated maximum.
	 * For sanity's sake we bump it to the highest dot clock we find
	 * in the list of supported modes
	 */
	for (i = 0; i < edid->edid_nmodes; i++)
		if (edid->edid_modes[i].dot_clock > max_dotclock)
			max_dotclock = edid->edid_modes[i].dot_clock;

	printf("max_dotclock according to supported modes: %d\n",
	    max_dotclock);

	mhz = (max_dotclock + 999) / 1000;

	if (edid->edid_have_range) {

		if (mhz > edid->edid_range.er_max_clock)
			edid->edid_range.er_max_clock = mhz;
	} else
		edid->edid_range.er_max_clock = mhz;

	return 0;
}