Merge master.kernel.org:/pub/scm/linux/kernel/git/kyle/parisc-2.6
[linux-2.6] / drivers / video / fbmon.c
1 /*
2  * linux/drivers/video/fbmon.c
3  *
4  * Copyright (C) 2002 James Simmons <jsimmons@users.sf.net>
5  *
6  * Credits:
7  * 
8  * The EDID Parser is a conglomeration from the following sources:
9  *
10  *   1. SciTech SNAP Graphics Architecture
11  *      Copyright (C) 1991-2002 SciTech Software, Inc. All rights reserved.
12  *
13  *   2. XFree86 4.3.0, interpret_edid.c
14  *      Copyright 1998 by Egbert Eich <Egbert.Eich@Physik.TU-Darmstadt.DE>
15  * 
16  *   3. John Fremlin <vii@users.sourceforge.net> and 
17  *      Ani Joshi <ajoshi@unixbox.com>
18  *  
19  * Generalized Timing Formula is derived from:
20  *
21  *      GTF Spreadsheet by Andy Morrish (1/5/97) 
22  *      available at http://www.vesa.org
23  *
24  * This file is subject to the terms and conditions of the GNU General Public
25  * License.  See the file COPYING in the main directory of this archive
26  * for more details.
27  *
28  */
29 #include <linux/tty.h>
30 #include <linux/fb.h>
31 #include <linux/module.h>
32 #include <linux/pci.h>
33 #include <video/edid.h>
34 #ifdef CONFIG_PPC_OF
35 #include <asm/prom.h>
36 #include <asm/pci-bridge.h>
37 #endif
38 #include "edid.h"
39
40 /* 
41  * EDID parser
42  */
43
44 #undef DEBUG  /* define this for verbose EDID parsing output */
45
46 #ifdef DEBUG
47 #define DPRINTK(fmt, args...) printk(fmt,## args)
48 #else
49 #define DPRINTK(fmt, args...)
50 #endif
51
52 #define FBMON_FIX_HEADER 1
53 #define FBMON_FIX_INPUT  2
54
55 #ifdef CONFIG_FB_MODE_HELPERS
56 struct broken_edid {
57         u8  manufacturer[4];
58         u32 model;
59         u32 fix;
60 };
61
62 static struct broken_edid brokendb[] = {
63         /* DEC FR-PCXAV-YZ */
64         {
65                 .manufacturer = "DEC",
66                 .model        = 0x073a,
67                 .fix          = FBMON_FIX_HEADER,
68         },
69         /* ViewSonic PF775a */
70         {
71                 .manufacturer = "VSC",
72                 .model        = 0x5a44,
73                 .fix          = FBMON_FIX_INPUT,
74         },
75 };
76
77 static const unsigned char edid_v1_header[] = { 0x00, 0xff, 0xff, 0xff,
78         0xff, 0xff, 0xff, 0x00
79 };
80
81 static void copy_string(unsigned char *c, unsigned char *s)
82 {
83   int i;
84   c = c + 5;
85   for (i = 0; (i < 13 && *c != 0x0A); i++)
86     *(s++) = *(c++);
87   *s = 0;
88   while (i-- && (*--s == 0x20)) *s = 0;
89 }
90
91 static int check_edid(unsigned char *edid)
92 {
93         unsigned char *block = edid + ID_MANUFACTURER_NAME, manufacturer[4];
94         unsigned char *b;
95         u32 model;
96         int i, fix = 0, ret = 0;
97
98         manufacturer[0] = ((block[0] & 0x7c) >> 2) + '@';
99         manufacturer[1] = ((block[0] & 0x03) << 3) +
100                 ((block[1] & 0xe0) >> 5) + '@';
101         manufacturer[2] = (block[1] & 0x1f) + '@';
102         manufacturer[3] = 0;
103         model = block[2] + (block[3] << 8);
104
105         for (i = 0; i < ARRAY_SIZE(brokendb); i++) {
106                 if (!strncmp(manufacturer, brokendb[i].manufacturer, 4) &&
107                         brokendb[i].model == model) {
108                         printk("fbmon: The EDID Block of "
109                                "Manufacturer: %s Model: 0x%x is known to "
110                                "be broken,\n",  manufacturer, model);
111                         fix = brokendb[i].fix;
112                         break;
113                 }
114         }
115
116         switch (fix) {
117         case FBMON_FIX_HEADER:
118                 for (i = 0; i < 8; i++) {
119                         if (edid[i] != edid_v1_header[i])
120                                 ret = fix;
121                 }
122                 break;
123         case FBMON_FIX_INPUT:
124                 b = edid + EDID_STRUCT_DISPLAY;
125                 /* Only if display is GTF capable will
126                    the input type be reset to analog */
127                 if (b[4] & 0x01 && b[0] & 0x80)
128                         ret = fix;
129                 break;
130         }
131
132         return ret;
133 }
134
135 static void fix_edid(unsigned char *edid, int fix)
136 {
137         unsigned char *b;
138
139         switch (fix) {
140         case FBMON_FIX_HEADER:
141                 printk("fbmon: trying a header reconstruct\n");
142                 memcpy(edid, edid_v1_header, 8);
143                 break;
144         case FBMON_FIX_INPUT:
145                 printk("fbmon: trying to fix input type\n");
146                 b = edid + EDID_STRUCT_DISPLAY;
147                 b[0] &= ~0x80;
148                 edid[127] += 0x80;
149         }
150 }
151
152 static int edid_checksum(unsigned char *edid)
153 {
154         unsigned char i, csum = 0, all_null = 0;
155         int err = 0, fix = check_edid(edid);
156
157         if (fix)
158                 fix_edid(edid, fix);
159
160         for (i = 0; i < EDID_LENGTH; i++) {
161                 csum += edid[i];
162                 all_null |= edid[i];
163         }
164
165         if (csum == 0x00 && all_null) {
166                 /* checksum passed, everything's good */
167                 err = 1;
168         }
169
170         return err;
171 }
172
173 static int edid_check_header(unsigned char *edid)
174 {
175         int i, err = 1, fix = check_edid(edid);
176
177         if (fix)
178                 fix_edid(edid, fix);
179
180         for (i = 0; i < 8; i++) {
181                 if (edid[i] != edid_v1_header[i])
182                         err = 0;
183         }
184
185         return err;
186 }
187
188 static void parse_vendor_block(unsigned char *block, struct fb_monspecs *specs)
189 {
190         specs->manufacturer[0] = ((block[0] & 0x7c) >> 2) + '@';
191         specs->manufacturer[1] = ((block[0] & 0x03) << 3) +
192                 ((block[1] & 0xe0) >> 5) + '@';
193         specs->manufacturer[2] = (block[1] & 0x1f) + '@';
194         specs->manufacturer[3] = 0;
195         specs->model = block[2] + (block[3] << 8);
196         specs->serial = block[4] + (block[5] << 8) +
197                (block[6] << 16) + (block[7] << 24);
198         specs->year = block[9] + 1990;
199         specs->week = block[8];
200         DPRINTK("   Manufacturer: %s\n", specs->manufacturer);
201         DPRINTK("   Model: %x\n", specs->model);
202         DPRINTK("   Serial#: %u\n", specs->serial);
203         DPRINTK("   Year: %u Week %u\n", specs->year, specs->week);
204 }
205
206 static void get_dpms_capabilities(unsigned char flags,
207                                   struct fb_monspecs *specs)
208 {
209         specs->dpms = 0;
210         if (flags & DPMS_ACTIVE_OFF)
211                 specs->dpms |= FB_DPMS_ACTIVE_OFF;
212         if (flags & DPMS_SUSPEND)
213                 specs->dpms |= FB_DPMS_SUSPEND;
214         if (flags & DPMS_STANDBY)
215                 specs->dpms |= FB_DPMS_STANDBY;
216         DPRINTK("      DPMS: Active %s, Suspend %s, Standby %s\n",
217                (flags & DPMS_ACTIVE_OFF) ? "yes" : "no",
218                (flags & DPMS_SUSPEND)    ? "yes" : "no",
219                (flags & DPMS_STANDBY)    ? "yes" : "no");
220 }
221         
222 static void get_chroma(unsigned char *block, struct fb_monspecs *specs)
223 {
224         int tmp;
225
226         DPRINTK("      Chroma\n");
227         /* Chromaticity data */
228         tmp = ((block[5] & (3 << 6)) >> 6) | (block[0x7] << 2);
229         tmp *= 1000;
230         tmp += 512;
231         specs->chroma.redx = tmp/1024;
232         DPRINTK("         RedX:     0.%03d ", specs->chroma.redx);
233
234         tmp = ((block[5] & (3 << 4)) >> 4) | (block[0x8] << 2);
235         tmp *= 1000;
236         tmp += 512;
237         specs->chroma.redy = tmp/1024;
238         DPRINTK("RedY:     0.%03d\n", specs->chroma.redy);
239
240         tmp = ((block[5] & (3 << 2)) >> 2) | (block[0x9] << 2);
241         tmp *= 1000;
242         tmp += 512;
243         specs->chroma.greenx = tmp/1024;
244         DPRINTK("         GreenX:   0.%03d ", specs->chroma.greenx);
245
246         tmp = (block[5] & 3) | (block[0xa] << 2);
247         tmp *= 1000;
248         tmp += 512;
249         specs->chroma.greeny = tmp/1024;
250         DPRINTK("GreenY:   0.%03d\n", specs->chroma.greeny);
251
252         tmp = ((block[6] & (3 << 6)) >> 6) | (block[0xb] << 2);
253         tmp *= 1000;
254         tmp += 512;
255         specs->chroma.bluex = tmp/1024;
256         DPRINTK("         BlueX:    0.%03d ", specs->chroma.bluex);
257
258         tmp = ((block[6] & (3 << 4)) >> 4) | (block[0xc] << 2);
259         tmp *= 1000;
260         tmp += 512;
261         specs->chroma.bluey = tmp/1024;
262         DPRINTK("BlueY:    0.%03d\n", specs->chroma.bluey);
263         
264         tmp = ((block[6] & (3 << 2)) >> 2) | (block[0xd] << 2);
265         tmp *= 1000;
266         tmp += 512;
267         specs->chroma.whitex = tmp/1024;
268         DPRINTK("         WhiteX:   0.%03d ", specs->chroma.whitex);
269
270         tmp = (block[6] & 3) | (block[0xe] << 2);
271         tmp *= 1000;
272         tmp += 512;
273         specs->chroma.whitey = tmp/1024;
274         DPRINTK("WhiteY:   0.%03d\n", specs->chroma.whitey);
275 }
276
277 static int edid_is_serial_block(unsigned char *block)
278 {
279         if ((block[0] == 0x00) && (block[1] == 0x00) && 
280             (block[2] == 0x00) && (block[3] == 0xff) &&
281             (block[4] == 0x00))
282                 return 1;
283         else
284                 return 0;
285 }
286
287 static int edid_is_ascii_block(unsigned char *block)
288 {
289         if ((block[0] == 0x00) && (block[1] == 0x00) && 
290             (block[2] == 0x00) && (block[3] == 0xfe) &&
291             (block[4] == 0x00))
292                 return 1;
293         else
294                 return 0;
295 }
296
297 static int edid_is_limits_block(unsigned char *block)
298 {
299         if ((block[0] == 0x00) && (block[1] == 0x00) && 
300             (block[2] == 0x00) && (block[3] == 0xfd) &&
301             (block[4] == 0x00))
302                 return 1;
303         else
304                 return 0;
305 }
306
307 static int edid_is_monitor_block(unsigned char *block)
308 {
309         if ((block[0] == 0x00) && (block[1] == 0x00) && 
310             (block[2] == 0x00) && (block[3] == 0xfc) &&
311             (block[4] == 0x00))
312                 return 1;
313         else
314                 return 0;
315 }
316
317 static void calc_mode_timings(int xres, int yres, int refresh,
318                               struct fb_videomode *mode)
319 {
320         struct fb_var_screeninfo *var;
321         
322         var = kzalloc(sizeof(struct fb_var_screeninfo), GFP_KERNEL);
323
324         if (var) {
325                 var->xres = xres;
326                 var->yres = yres;
327                 fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON,
328                             refresh, var, NULL);
329                 mode->xres = xres;
330                 mode->yres = yres;
331                 mode->pixclock = var->pixclock;
332                 mode->refresh = refresh;
333                 mode->left_margin = var->left_margin;
334                 mode->right_margin = var->right_margin;
335                 mode->upper_margin = var->upper_margin;
336                 mode->lower_margin = var->lower_margin;
337                 mode->hsync_len = var->hsync_len;
338                 mode->vsync_len = var->vsync_len;
339                 mode->vmode = 0;
340                 mode->sync = 0;
341                 kfree(var);
342         }
343 }
344
345 static int get_est_timing(unsigned char *block, struct fb_videomode *mode)
346 {
347         int num = 0;
348         unsigned char c;
349
350         c = block[0];
351         if (c&0x80) {
352                 calc_mode_timings(720, 400, 70, &mode[num]);
353                 mode[num++].flag = FB_MODE_IS_CALCULATED;
354                 DPRINTK("      720x400@70Hz\n");
355         }
356         if (c&0x40) {
357                 calc_mode_timings(720, 400, 88, &mode[num]);
358                 mode[num++].flag = FB_MODE_IS_CALCULATED;
359                 DPRINTK("      720x400@88Hz\n");
360         }
361         if (c&0x20) {
362                 mode[num++] = vesa_modes[3];
363                 DPRINTK("      640x480@60Hz\n");
364         }
365         if (c&0x10) {
366                 calc_mode_timings(640, 480, 67, &mode[num]);
367                 mode[num++].flag = FB_MODE_IS_CALCULATED;
368                 DPRINTK("      640x480@67Hz\n");
369         }
370         if (c&0x08) {
371                 mode[num++] = vesa_modes[4];
372                 DPRINTK("      640x480@72Hz\n");
373         }
374         if (c&0x04) {
375                 mode[num++] = vesa_modes[5];
376                 DPRINTK("      640x480@75Hz\n");
377         }
378         if (c&0x02) {
379                 mode[num++] = vesa_modes[7];
380                 DPRINTK("      800x600@56Hz\n");
381         }
382         if (c&0x01) {
383                 mode[num++] = vesa_modes[8];
384                 DPRINTK("      800x600@60Hz\n");
385         }
386
387         c = block[1];
388         if (c&0x80) {
389                 mode[num++] = vesa_modes[9];
390                 DPRINTK("      800x600@72Hz\n");
391         }
392         if (c&0x40) {
393                 mode[num++] = vesa_modes[10];
394                 DPRINTK("      800x600@75Hz\n");
395         }
396         if (c&0x20) {
397                 calc_mode_timings(832, 624, 75, &mode[num]);
398                 mode[num++].flag = FB_MODE_IS_CALCULATED;
399                 DPRINTK("      832x624@75Hz\n");
400         }
401         if (c&0x10) {
402                 mode[num++] = vesa_modes[12];
403                 DPRINTK("      1024x768@87Hz Interlaced\n");
404         }
405         if (c&0x08) {
406                 mode[num++] = vesa_modes[13];
407                 DPRINTK("      1024x768@60Hz\n");
408         }
409         if (c&0x04) {
410                 mode[num++] = vesa_modes[14];
411                 DPRINTK("      1024x768@70Hz\n");
412         }
413         if (c&0x02) {
414                 mode[num++] = vesa_modes[15];
415                 DPRINTK("      1024x768@75Hz\n");
416         }
417         if (c&0x01) {
418                 mode[num++] = vesa_modes[21];
419                 DPRINTK("      1280x1024@75Hz\n");
420         }
421         c = block[2];
422         if (c&0x80) {
423                 mode[num++] = vesa_modes[17];
424                 DPRINTK("      1152x870@75Hz\n");
425         }
426         DPRINTK("      Manufacturer's mask: %x\n",c&0x7F);
427         return num;
428 }
429
430 static int get_std_timing(unsigned char *block, struct fb_videomode *mode)
431 {
432         int xres, yres = 0, refresh, ratio, i;
433         
434         xres = (block[0] + 31) * 8;
435         if (xres <= 256)
436                 return 0;
437
438         ratio = (block[1] & 0xc0) >> 6;
439         switch (ratio) {
440         case 0:
441                 yres = xres;
442                 break;
443         case 1:
444                 yres = (xres * 3)/4;
445                 break;
446         case 2:
447                 yres = (xres * 4)/5;
448                 break;
449         case 3:
450                 yres = (xres * 9)/16;
451                 break;
452         }
453         refresh = (block[1] & 0x3f) + 60;
454
455         DPRINTK("      %dx%d@%dHz\n", xres, yres, refresh);
456         for (i = 0; i < VESA_MODEDB_SIZE; i++) {
457                 if (vesa_modes[i].xres == xres && 
458                     vesa_modes[i].yres == yres &&
459                     vesa_modes[i].refresh == refresh) {
460                         *mode = vesa_modes[i];
461                         mode->flag |= FB_MODE_IS_STANDARD;
462                         return 1;
463                 }
464         }
465         calc_mode_timings(xres, yres, refresh, mode);
466         return 1;
467 }
468
469 static int get_dst_timing(unsigned char *block,
470                           struct fb_videomode *mode)
471 {
472         int j, num = 0;
473
474         for (j = 0; j < 6; j++, block+= STD_TIMING_DESCRIPTION_SIZE) 
475                 num += get_std_timing(block, &mode[num]);
476
477         return num;
478 }
479
480 static void get_detailed_timing(unsigned char *block, 
481                                 struct fb_videomode *mode)
482 {
483         mode->xres = H_ACTIVE;
484         mode->yres = V_ACTIVE;
485         mode->pixclock = PIXEL_CLOCK;
486         mode->pixclock /= 1000;
487         mode->pixclock = KHZ2PICOS(mode->pixclock);
488         mode->right_margin = H_SYNC_OFFSET;
489         mode->left_margin = (H_ACTIVE + H_BLANKING) -
490                 (H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH);
491         mode->upper_margin = V_BLANKING - V_SYNC_OFFSET - 
492                 V_SYNC_WIDTH;
493         mode->lower_margin = V_SYNC_OFFSET;
494         mode->hsync_len = H_SYNC_WIDTH;
495         mode->vsync_len = V_SYNC_WIDTH;
496         if (HSYNC_POSITIVE)
497                 mode->sync |= FB_SYNC_HOR_HIGH_ACT;
498         if (VSYNC_POSITIVE)
499                 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
500         mode->refresh = PIXEL_CLOCK/((H_ACTIVE + H_BLANKING) *
501                                      (V_ACTIVE + V_BLANKING));
502         mode->vmode = 0;
503         mode->flag = FB_MODE_IS_DETAILED;
504
505         DPRINTK("      %d MHz ",  PIXEL_CLOCK/1000000);
506         DPRINTK("%d %d %d %d ", H_ACTIVE, H_ACTIVE + H_SYNC_OFFSET,
507                H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH, H_ACTIVE + H_BLANKING);
508         DPRINTK("%d %d %d %d ", V_ACTIVE, V_ACTIVE + V_SYNC_OFFSET,
509                V_ACTIVE + V_SYNC_OFFSET + V_SYNC_WIDTH, V_ACTIVE + V_BLANKING);
510         DPRINTK("%sHSync %sVSync\n\n", (HSYNC_POSITIVE) ? "+" : "-",
511                (VSYNC_POSITIVE) ? "+" : "-");
512 }
513
514 /**
515  * fb_create_modedb - create video mode database
516  * @edid: EDID data
517  * @dbsize: database size
518  *
519  * RETURNS: struct fb_videomode, @dbsize contains length of database
520  *
521  * DESCRIPTION:
522  * This function builds a mode database using the contents of the EDID
523  * data
524  */
525 static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
526 {
527         struct fb_videomode *mode, *m;
528         unsigned char *block;
529         int num = 0, i;
530
531         mode = kzalloc(50 * sizeof(struct fb_videomode), GFP_KERNEL);
532         if (mode == NULL)
533                 return NULL;
534
535         if (edid == NULL || !edid_checksum(edid) || 
536             !edid_check_header(edid)) {
537                 kfree(mode);
538                 return NULL;
539         }
540
541         *dbsize = 0;
542
543         DPRINTK("   Detailed Timings\n");
544         block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
545         for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) {
546                 int first = 1;
547
548                 if (!(block[0] == 0x00 && block[1] == 0x00)) {
549                         get_detailed_timing(block, &mode[num]);
550                         if (first) {
551                                 mode[num].flag |= FB_MODE_IS_FIRST;
552                                 first = 0;
553                         }
554                         num++;
555                 }
556         }
557
558         DPRINTK("   Supported VESA Modes\n");
559         block = edid + ESTABLISHED_TIMING_1;
560         num += get_est_timing(block, &mode[num]);
561
562         DPRINTK("   Standard Timings\n");
563         block = edid + STD_TIMING_DESCRIPTIONS_START;
564         for (i = 0; i < STD_TIMING; i++, block += STD_TIMING_DESCRIPTION_SIZE)
565                 num += get_std_timing(block, &mode[num]);
566
567         block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
568         for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) {
569                 if (block[0] == 0x00 && block[1] == 0x00 && block[3] == 0xfa)
570                         num += get_dst_timing(block + 5, &mode[num]);
571         }
572         
573         /* Yikes, EDID data is totally useless */
574         if (!num) {
575                 kfree(mode);
576                 return NULL;
577         }
578
579         *dbsize = num;
580         m = kmalloc(num * sizeof(struct fb_videomode), GFP_KERNEL);
581         if (!m)
582                 return mode;
583         memmove(m, mode, num * sizeof(struct fb_videomode));
584         kfree(mode);
585         return m;
586 }
587
588 /**
589  * fb_destroy_modedb - destroys mode database
590  * @modedb: mode database to destroy
591  *
592  * DESCRIPTION:
593  * Destroy mode database created by fb_create_modedb
594  */
595 void fb_destroy_modedb(struct fb_videomode *modedb)
596 {
597         kfree(modedb);
598 }
599
600 static int fb_get_monitor_limits(unsigned char *edid, struct fb_monspecs *specs)
601 {
602         int i, retval = 1;
603         unsigned char *block;
604
605         block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
606
607         DPRINTK("      Monitor Operating Limits: ");
608
609         for (i = 0; i < 4; i++, block += DETAILED_TIMING_DESCRIPTION_SIZE) {
610                 if (edid_is_limits_block(block)) {
611                         specs->hfmin = H_MIN_RATE * 1000;
612                         specs->hfmax = H_MAX_RATE * 1000;
613                         specs->vfmin = V_MIN_RATE;
614                         specs->vfmax = V_MAX_RATE;
615                         specs->dclkmax = MAX_PIXEL_CLOCK * 1000000;
616                         specs->gtf = (GTF_SUPPORT) ? 1 : 0;
617                         retval = 0;
618                         DPRINTK("From EDID\n");
619                         break;
620                 }
621         }
622
623         /* estimate monitor limits based on modes supported */
624         if (retval) {
625                 struct fb_videomode *modes, *mode;
626                 int num_modes, i, hz, hscan, pixclock;
627                 int vtotal, htotal;
628
629                 modes = fb_create_modedb(edid, &num_modes);
630                 if (!modes) {
631                         DPRINTK("None Available\n");
632                         return 1;
633                 }
634
635                 retval = 0;
636                 for (i = 0; i < num_modes; i++) {
637                         mode = &modes[i];
638                         pixclock = PICOS2KHZ(modes[i].pixclock) * 1000;
639                         htotal = mode->xres + mode->right_margin + mode->hsync_len
640                                 + mode->left_margin;
641                         vtotal = mode->yres + mode->lower_margin + mode->vsync_len
642                                 + mode->upper_margin;
643
644                         if (mode->vmode & FB_VMODE_INTERLACED)
645                                 vtotal /= 2;
646
647                         if (mode->vmode & FB_VMODE_DOUBLE)
648                                 vtotal *= 2;
649
650                         hscan = (pixclock + htotal / 2) / htotal;
651                         hscan = (hscan + 500) / 1000 * 1000;
652                         hz = (hscan + vtotal / 2) / vtotal;
653                         
654                         if (specs->dclkmax == 0 || specs->dclkmax < pixclock)
655                                 specs->dclkmax = pixclock;
656
657                         if (specs->dclkmin == 0 || specs->dclkmin > pixclock)
658                                 specs->dclkmin = pixclock;
659
660                         if (specs->hfmax == 0 || specs->hfmax < hscan)
661                                 specs->hfmax = hscan;
662
663                         if (specs->hfmin == 0 || specs->hfmin > hscan)
664                                 specs->hfmin = hscan;
665
666                         if (specs->vfmax == 0 || specs->vfmax < hz)
667                                 specs->vfmax = hz;
668
669                         if (specs->vfmin == 0 || specs->vfmin > hz)
670                                 specs->vfmin = hz;
671                 }
672                 DPRINTK("Extrapolated\n");
673                 fb_destroy_modedb(modes);
674         }
675         DPRINTK("           H: %d-%dKHz V: %d-%dHz DCLK: %dMHz\n",
676                 specs->hfmin/1000, specs->hfmax/1000, specs->vfmin,
677                 specs->vfmax, specs->dclkmax/1000000);
678         return retval;
679 }
680
681 static void get_monspecs(unsigned char *edid, struct fb_monspecs *specs)
682 {
683         unsigned char c, *block;
684
685         block = edid + EDID_STRUCT_DISPLAY;
686
687         fb_get_monitor_limits(edid, specs);
688
689         c = block[0] & 0x80;
690         specs->input = 0;
691         if (c) {
692                 specs->input |= FB_DISP_DDI;
693                 DPRINTK("      Digital Display Input");
694         } else {
695                 DPRINTK("      Analog Display Input: Input Voltage - ");
696                 switch ((block[0] & 0x60) >> 5) {
697                 case 0:
698                         DPRINTK("0.700V/0.300V");
699                         specs->input |= FB_DISP_ANA_700_300;
700                         break;
701                 case 1:
702                         DPRINTK("0.714V/0.286V");
703                         specs->input |= FB_DISP_ANA_714_286;
704                         break;
705                 case 2:
706                         DPRINTK("1.000V/0.400V");
707                         specs->input |= FB_DISP_ANA_1000_400;
708                         break;
709                 case 3:
710                         DPRINTK("0.700V/0.000V");
711                         specs->input |= FB_DISP_ANA_700_000;
712                         break;
713                 }
714         }
715         DPRINTK("\n      Sync: ");
716         c = block[0] & 0x10;
717         if (c)
718                 DPRINTK("      Configurable signal level\n");
719         c = block[0] & 0x0f;
720         specs->signal = 0;
721         if (c & 0x10) {
722                 DPRINTK("Blank to Blank ");
723                 specs->signal |= FB_SIGNAL_BLANK_BLANK;
724         }
725         if (c & 0x08) {
726                 DPRINTK("Separate ");
727                 specs->signal |= FB_SIGNAL_SEPARATE;
728         }
729         if (c & 0x04) {
730                 DPRINTK("Composite ");
731                 specs->signal |= FB_SIGNAL_COMPOSITE;
732         }
733         if (c & 0x02) {
734                 DPRINTK("Sync on Green ");
735                 specs->signal |= FB_SIGNAL_SYNC_ON_GREEN;
736         }
737         if (c & 0x01) {
738                 DPRINTK("Serration on ");
739                 specs->signal |= FB_SIGNAL_SERRATION_ON;
740         }
741         DPRINTK("\n");
742         specs->max_x = block[1];
743         specs->max_y = block[2];
744         DPRINTK("      Max H-size in cm: ");
745         if (specs->max_x)
746                 DPRINTK("%d\n", specs->max_x);
747         else
748                 DPRINTK("variable\n");
749         DPRINTK("      Max V-size in cm: ");
750         if (specs->max_y)
751                 DPRINTK("%d\n", specs->max_y);
752         else
753                 DPRINTK("variable\n");
754
755         c = block[3];
756         specs->gamma = c+100;
757         DPRINTK("      Gamma: ");
758         DPRINTK("%d.%d\n", specs->gamma/100, specs->gamma % 100);
759
760         get_dpms_capabilities(block[4], specs);
761
762         switch ((block[4] & 0x18) >> 3) {
763         case 0:
764                 DPRINTK("      Monochrome/Grayscale\n");
765                 specs->input |= FB_DISP_MONO;
766                 break;
767         case 1:
768                 DPRINTK("      RGB Color Display\n");
769                 specs->input |= FB_DISP_RGB;
770                 break;
771         case 2:
772                 DPRINTK("      Non-RGB Multicolor Display\n");
773                 specs->input |= FB_DISP_MULTI;
774                 break;
775         default:
776                 DPRINTK("      Unknown\n");
777                 specs->input |= FB_DISP_UNKNOWN;
778                 break;
779         }
780
781         get_chroma(block, specs);
782
783         specs->misc = 0;
784         c = block[4] & 0x7;
785         if (c & 0x04) {
786                 DPRINTK("      Default color format is primary\n");
787                 specs->misc |= FB_MISC_PRIM_COLOR;
788         }
789         if (c & 0x02) {
790                 DPRINTK("      First DETAILED Timing is preferred\n");
791                 specs->misc |= FB_MISC_1ST_DETAIL;
792         }
793         if (c & 0x01) {
794                 printk("      Display is GTF capable\n");
795                 specs->gtf = 1;
796         }
797 }
798
799 static int edid_is_timing_block(unsigned char *block)
800 {
801         if ((block[0] != 0x00) || (block[1] != 0x00) ||
802             (block[2] != 0x00) || (block[4] != 0x00))
803                 return 1;
804         else
805                 return 0;
806 }
807
808 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
809 {
810         int i;
811         unsigned char *block;
812
813         if (edid == NULL || var == NULL)
814                 return 1;
815
816         if (!(edid_checksum(edid)))
817                 return 1;
818
819         if (!(edid_check_header(edid)))
820                 return 1;
821
822         block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
823
824         for (i = 0; i < 4; i++, block += DETAILED_TIMING_DESCRIPTION_SIZE) {
825                 if (edid_is_timing_block(block)) {
826                         var->xres = var->xres_virtual = H_ACTIVE;
827                         var->yres = var->yres_virtual = V_ACTIVE;
828                         var->height = var->width = -1;
829                         var->right_margin = H_SYNC_OFFSET;
830                         var->left_margin = (H_ACTIVE + H_BLANKING) -
831                                 (H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH);
832                         var->upper_margin = V_BLANKING - V_SYNC_OFFSET -
833                                 V_SYNC_WIDTH;
834                         var->lower_margin = V_SYNC_OFFSET;
835                         var->hsync_len = H_SYNC_WIDTH;
836                         var->vsync_len = V_SYNC_WIDTH;
837                         var->pixclock = PIXEL_CLOCK;
838                         var->pixclock /= 1000;
839                         var->pixclock = KHZ2PICOS(var->pixclock);
840
841                         if (HSYNC_POSITIVE)
842                                 var->sync |= FB_SYNC_HOR_HIGH_ACT;
843                         if (VSYNC_POSITIVE)
844                                 var->sync |= FB_SYNC_VERT_HIGH_ACT;
845                         return 0;
846                 }
847         }
848         return 1;
849 }
850
851 void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
852 {
853         unsigned char *block;
854         int i, found = 0;
855
856         if (edid == NULL)
857                 return;
858
859         if (!(edid_checksum(edid)))
860                 return;
861
862         if (!(edid_check_header(edid)))
863                 return;
864
865         memset(specs, 0, sizeof(struct fb_monspecs));
866
867         specs->version = edid[EDID_STRUCT_VERSION];
868         specs->revision = edid[EDID_STRUCT_REVISION];
869
870         DPRINTK("========================================\n");
871         DPRINTK("Display Information (EDID)\n");
872         DPRINTK("========================================\n");
873         DPRINTK("   EDID Version %d.%d\n", (int) specs->version,
874                (int) specs->revision);
875
876         parse_vendor_block(edid + ID_MANUFACTURER_NAME, specs);
877
878         block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
879         for (i = 0; i < 4; i++, block += DETAILED_TIMING_DESCRIPTION_SIZE) {
880                 if (edid_is_serial_block(block)) {
881                         copy_string(block, specs->serial_no);
882                         DPRINTK("   Serial Number: %s\n", specs->serial_no);
883                 } else if (edid_is_ascii_block(block)) {
884                         copy_string(block, specs->ascii);
885                         DPRINTK("   ASCII Block: %s\n", specs->ascii);
886                 } else if (edid_is_monitor_block(block)) {
887                         copy_string(block, specs->monitor);
888                         DPRINTK("   Monitor Name: %s\n", specs->monitor);
889                 }
890         }
891
892         DPRINTK("   Display Characteristics:\n");
893         get_monspecs(edid, specs);
894
895         specs->modedb = fb_create_modedb(edid, &specs->modedb_len);
896
897         /*
898          * Workaround for buggy EDIDs that sets that the first
899          * detailed timing is preferred but has not detailed
900          * timing specified
901          */
902         for (i = 0; i < specs->modedb_len; i++) {
903                 if (specs->modedb[i].flag & FB_MODE_IS_DETAILED) {
904                         found = 1;
905                         break;
906                 }
907         }
908
909         if (!found)
910                 specs->misc &= ~FB_MISC_1ST_DETAIL;
911
912         DPRINTK("========================================\n");
913 }
914
915 /* 
916  * VESA Generalized Timing Formula (GTF) 
917  */
918
919 #define FLYBACK                     550
920 #define V_FRONTPORCH                1
921 #define H_OFFSET                    40
922 #define H_SCALEFACTOR               20
923 #define H_BLANKSCALE                128
924 #define H_GRADIENT                  600
925 #define C_VAL                       30
926 #define M_VAL                       300
927
928 struct __fb_timings {
929         u32 dclk;
930         u32 hfreq;
931         u32 vfreq;
932         u32 hactive;
933         u32 vactive;
934         u32 hblank;
935         u32 vblank;
936         u32 htotal;
937         u32 vtotal;
938 };
939
940 /**
941  * fb_get_vblank - get vertical blank time
942  * @hfreq: horizontal freq
943  *
944  * DESCRIPTION:
945  * vblank = right_margin + vsync_len + left_margin 
946  *
947  *    given: right_margin = 1 (V_FRONTPORCH)
948  *           vsync_len    = 3
949  *           flyback      = 550
950  *
951  *                          flyback * hfreq
952  *           left_margin  = --------------- - vsync_len
953  *                           1000000
954  */
955 static u32 fb_get_vblank(u32 hfreq)
956 {
957         u32 vblank;
958
959         vblank = (hfreq * FLYBACK)/1000; 
960         vblank = (vblank + 500)/1000;
961         return (vblank + V_FRONTPORCH);
962 }
963
964 /** 
965  * fb_get_hblank_by_freq - get horizontal blank time given hfreq
966  * @hfreq: horizontal freq
967  * @xres: horizontal resolution in pixels
968  *
969  * DESCRIPTION:
970  *
971  *           xres * duty_cycle
972  * hblank = ------------------
973  *           100 - duty_cycle
974  *
975  * duty cycle = percent of htotal assigned to inactive display
976  * duty cycle = C - (M/Hfreq)
977  *
978  * where: C = ((offset - scale factor) * blank_scale)
979  *            -------------------------------------- + scale factor
980  *                        256 
981  *        M = blank_scale * gradient
982  *
983  */
984 static u32 fb_get_hblank_by_hfreq(u32 hfreq, u32 xres)
985 {
986         u32 c_val, m_val, duty_cycle, hblank;
987
988         c_val = (((H_OFFSET - H_SCALEFACTOR) * H_BLANKSCALE)/256 + 
989                  H_SCALEFACTOR) * 1000;
990         m_val = (H_BLANKSCALE * H_GRADIENT)/256;
991         m_val = (m_val * 1000000)/hfreq;
992         duty_cycle = c_val - m_val;
993         hblank = (xres * duty_cycle)/(100000 - duty_cycle);
994         return (hblank);
995 }
996
997 /** 
998  * fb_get_hblank_by_dclk - get horizontal blank time given pixelclock
999  * @dclk: pixelclock in Hz
1000  * @xres: horizontal resolution in pixels
1001  *
1002  * DESCRIPTION:
1003  *
1004  *           xres * duty_cycle
1005  * hblank = ------------------
1006  *           100 - duty_cycle
1007  *
1008  * duty cycle = percent of htotal assigned to inactive display
1009  * duty cycle = C - (M * h_period)
1010  * 
1011  * where: h_period = SQRT(100 - C + (0.4 * xres * M)/dclk) + C - 100
1012  *                   -----------------------------------------------
1013  *                                    2 * M
1014  *        M = 300;
1015  *        C = 30;
1016
1017  */
1018 static u32 fb_get_hblank_by_dclk(u32 dclk, u32 xres)
1019 {
1020         u32 duty_cycle, h_period, hblank;
1021
1022         dclk /= 1000;
1023         h_period = 100 - C_VAL;
1024         h_period *= h_period;
1025         h_period += (M_VAL * xres * 2 * 1000)/(5 * dclk);
1026         h_period *=10000; 
1027
1028         h_period = int_sqrt(h_period);
1029         h_period -= (100 - C_VAL) * 100;
1030         h_period *= 1000; 
1031         h_period /= 2 * M_VAL;
1032
1033         duty_cycle = C_VAL * 1000 - (M_VAL * h_period)/100;
1034         hblank = (xres * duty_cycle)/(100000 - duty_cycle) + 8;
1035         hblank &= ~15;
1036         return (hblank);
1037 }
1038         
1039 /**
1040  * fb_get_hfreq - estimate hsync
1041  * @vfreq: vertical refresh rate
1042  * @yres: vertical resolution
1043  *
1044  * DESCRIPTION:
1045  *
1046  *          (yres + front_port) * vfreq * 1000000
1047  * hfreq = -------------------------------------
1048  *          (1000000 - (vfreq * FLYBACK)
1049  * 
1050  */
1051
1052 static u32 fb_get_hfreq(u32 vfreq, u32 yres)
1053 {
1054         u32 divisor, hfreq;
1055         
1056         divisor = (1000000 - (vfreq * FLYBACK))/1000;
1057         hfreq = (yres + V_FRONTPORCH) * vfreq  * 1000;
1058         return (hfreq/divisor);
1059 }
1060
1061 static void fb_timings_vfreq(struct __fb_timings *timings)
1062 {
1063         timings->hfreq = fb_get_hfreq(timings->vfreq, timings->vactive);
1064         timings->vblank = fb_get_vblank(timings->hfreq);
1065         timings->vtotal = timings->vactive + timings->vblank;
1066         timings->hblank = fb_get_hblank_by_hfreq(timings->hfreq, 
1067                                                  timings->hactive);
1068         timings->htotal = timings->hactive + timings->hblank;
1069         timings->dclk = timings->htotal * timings->hfreq;
1070 }
1071
1072 static void fb_timings_hfreq(struct __fb_timings *timings)
1073 {
1074         timings->vblank = fb_get_vblank(timings->hfreq);
1075         timings->vtotal = timings->vactive + timings->vblank;
1076         timings->vfreq = timings->hfreq/timings->vtotal;
1077         timings->hblank = fb_get_hblank_by_hfreq(timings->hfreq, 
1078                                                  timings->hactive);
1079         timings->htotal = timings->hactive + timings->hblank;
1080         timings->dclk = timings->htotal * timings->hfreq;
1081 }
1082
1083 static void fb_timings_dclk(struct __fb_timings *timings)
1084 {
1085         timings->hblank = fb_get_hblank_by_dclk(timings->dclk, 
1086                                                 timings->hactive);
1087         timings->htotal = timings->hactive + timings->hblank;
1088         timings->hfreq = timings->dclk/timings->htotal;
1089         timings->vblank = fb_get_vblank(timings->hfreq);
1090         timings->vtotal = timings->vactive + timings->vblank;
1091         timings->vfreq = timings->hfreq/timings->vtotal;
1092 }
1093
1094 /*
1095  * fb_get_mode - calculates video mode using VESA GTF
1096  * @flags: if: 0 - maximize vertical refresh rate
1097  *             1 - vrefresh-driven calculation;
1098  *             2 - hscan-driven calculation;
1099  *             3 - pixelclock-driven calculation;
1100  * @val: depending on @flags, ignored, vrefresh, hsync or pixelclock
1101  * @var: pointer to fb_var_screeninfo
1102  * @info: pointer to fb_info
1103  *
1104  * DESCRIPTION:
1105  * Calculates video mode based on monitor specs using VESA GTF. 
1106  * The GTF is best for VESA GTF compliant monitors but is 
1107  * specifically formulated to work for older monitors as well.
1108  *
1109  * If @flag==0, the function will attempt to maximize the 
1110  * refresh rate.  Otherwise, it will calculate timings based on
1111  * the flag and accompanying value.  
1112  *
1113  * If FB_IGNOREMON bit is set in @flags, monitor specs will be 
1114  * ignored and @var will be filled with the calculated timings.
1115  *
1116  * All calculations are based on the VESA GTF Spreadsheet
1117  * available at VESA's public ftp (http://www.vesa.org).
1118  * 
1119  * NOTES:
1120  * The timings generated by the GTF will be different from VESA
1121  * DMT.  It might be a good idea to keep a table of standard
1122  * VESA modes as well.  The GTF may also not work for some displays,
1123  * such as, and especially, analog TV.
1124  *   
1125  * REQUIRES:
1126  * A valid info->monspecs, otherwise 'safe numbers' will be used.
1127  */ 
1128 int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_info *info)
1129 {
1130         struct __fb_timings *timings;
1131         u32 interlace = 1, dscan = 1;
1132         u32 hfmin, hfmax, vfmin, vfmax, dclkmin, dclkmax, err = 0;
1133
1134
1135         timings = kzalloc(sizeof(struct __fb_timings), GFP_KERNEL);
1136
1137         if (!timings)
1138                 return -ENOMEM;
1139
1140         /* 
1141          * If monspecs are invalid, use values that are enough
1142          * for 640x480@60
1143          */
1144         if (!info || !info->monspecs.hfmax || !info->monspecs.vfmax ||
1145             !info->monspecs.dclkmax ||
1146             info->monspecs.hfmax < info->monspecs.hfmin ||
1147             info->monspecs.vfmax < info->monspecs.vfmin ||
1148             info->monspecs.dclkmax < info->monspecs.dclkmin) {
1149                 hfmin = 29000; hfmax = 30000;
1150                 vfmin = 60; vfmax = 60;
1151                 dclkmin = 0; dclkmax = 25000000;
1152         } else {
1153                 hfmin = info->monspecs.hfmin;
1154                 hfmax = info->monspecs.hfmax;
1155                 vfmin = info->monspecs.vfmin;
1156                 vfmax = info->monspecs.vfmax;
1157                 dclkmin = info->monspecs.dclkmin;
1158                 dclkmax = info->monspecs.dclkmax;
1159         }
1160
1161         timings->hactive = var->xres;
1162         timings->vactive = var->yres;
1163         if (var->vmode & FB_VMODE_INTERLACED) { 
1164                 timings->vactive /= 2;
1165                 interlace = 2;
1166         }
1167         if (var->vmode & FB_VMODE_DOUBLE) {
1168                 timings->vactive *= 2;
1169                 dscan = 2;
1170         }
1171
1172         switch (flags & ~FB_IGNOREMON) {
1173         case FB_MAXTIMINGS: /* maximize refresh rate */
1174                 timings->hfreq = hfmax;
1175                 fb_timings_hfreq(timings);
1176                 if (timings->vfreq > vfmax) {
1177                         timings->vfreq = vfmax;
1178                         fb_timings_vfreq(timings);
1179                 }
1180                 if (timings->dclk > dclkmax) {
1181                         timings->dclk = dclkmax;
1182                         fb_timings_dclk(timings);
1183                 }
1184                 break;
1185         case FB_VSYNCTIMINGS: /* vrefresh driven */
1186                 timings->vfreq = val;
1187                 fb_timings_vfreq(timings);
1188                 break;
1189         case FB_HSYNCTIMINGS: /* hsync driven */
1190                 timings->hfreq = val;
1191                 fb_timings_hfreq(timings);
1192                 break;
1193         case FB_DCLKTIMINGS: /* pixelclock driven */
1194                 timings->dclk = PICOS2KHZ(val) * 1000;
1195                 fb_timings_dclk(timings);
1196                 break;
1197         default:
1198                 err = -EINVAL;
1199                 
1200         } 
1201         
1202         if (err || (!(flags & FB_IGNOREMON) &&
1203             (timings->vfreq < vfmin || timings->vfreq > vfmax ||
1204              timings->hfreq < hfmin || timings->hfreq > hfmax ||
1205              timings->dclk < dclkmin || timings->dclk > dclkmax))) {
1206                 err = -EINVAL;
1207         } else {
1208                 var->pixclock = KHZ2PICOS(timings->dclk/1000);
1209                 var->hsync_len = (timings->htotal * 8)/100;
1210                 var->right_margin = (timings->hblank/2) - var->hsync_len;
1211                 var->left_margin = timings->hblank - var->right_margin -
1212                         var->hsync_len;
1213                 var->vsync_len = (3 * interlace)/dscan;
1214                 var->lower_margin = (1 * interlace)/dscan;
1215                 var->upper_margin = (timings->vblank * interlace)/dscan -
1216                         (var->vsync_len + var->lower_margin);
1217         }
1218         
1219         kfree(timings);
1220         return err;
1221 }
1222 #else
1223 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
1224 {
1225         return 1;
1226 }
1227 void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
1228 {
1229         specs = NULL;
1230 }
1231 void fb_destroy_modedb(struct fb_videomode *modedb)
1232 {
1233 }
1234 int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var,
1235                 struct fb_info *info)
1236 {
1237         return -EINVAL;
1238 }
1239 #endif /* CONFIG_FB_MODE_HELPERS */
1240         
1241 /*
1242  * fb_validate_mode - validates var against monitor capabilities
1243  * @var: pointer to fb_var_screeninfo
1244  * @info: pointer to fb_info
1245  *
1246  * DESCRIPTION:
1247  * Validates video mode against monitor capabilities specified in
1248  * info->monspecs.
1249  *
1250  * REQUIRES:
1251  * A valid info->monspecs.
1252  */
1253 int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
1254 {
1255         u32 hfreq, vfreq, htotal, vtotal, pixclock;
1256         u32 hfmin, hfmax, vfmin, vfmax, dclkmin, dclkmax;
1257
1258         /* 
1259          * If monspecs are invalid, use values that are enough
1260          * for 640x480@60
1261          */
1262         if (!info->monspecs.hfmax || !info->monspecs.vfmax ||
1263             !info->monspecs.dclkmax ||
1264             info->monspecs.hfmax < info->monspecs.hfmin ||
1265             info->monspecs.vfmax < info->monspecs.vfmin ||
1266             info->monspecs.dclkmax < info->monspecs.dclkmin) {
1267                 hfmin = 29000; hfmax = 30000;
1268                 vfmin = 60; vfmax = 60;
1269                 dclkmin = 0; dclkmax = 25000000;
1270         } else {
1271                 hfmin = info->monspecs.hfmin;
1272                 hfmax = info->monspecs.hfmax;
1273                 vfmin = info->monspecs.vfmin;
1274                 vfmax = info->monspecs.vfmax;
1275                 dclkmin = info->monspecs.dclkmin;
1276                 dclkmax = info->monspecs.dclkmax;
1277         }
1278
1279         if (!var->pixclock)
1280                 return -EINVAL;
1281         pixclock = PICOS2KHZ(var->pixclock) * 1000;
1282            
1283         htotal = var->xres + var->right_margin + var->hsync_len + 
1284                 var->left_margin;
1285         vtotal = var->yres + var->lower_margin + var->vsync_len + 
1286                 var->upper_margin;
1287
1288         if (var->vmode & FB_VMODE_INTERLACED)
1289                 vtotal /= 2;
1290         if (var->vmode & FB_VMODE_DOUBLE)
1291                 vtotal *= 2;
1292
1293         hfreq = pixclock/htotal;
1294         hfreq = (hfreq + 500) / 1000 * 1000;
1295
1296         vfreq = hfreq/vtotal;
1297
1298         return (vfreq < vfmin || vfreq > vfmax || 
1299                 hfreq < hfmin || hfreq > hfmax ||
1300                 pixclock < dclkmin || pixclock > dclkmax) ?
1301                 -EINVAL : 0;
1302 }
1303
1304 #if defined(CONFIG_FIRMWARE_EDID) && defined(CONFIG_X86)
1305
1306 /*
1307  * We need to ensure that the EDID block is only returned for
1308  * the primary graphics adapter.
1309  */
1310
1311 const unsigned char *fb_firmware_edid(struct device *device)
1312 {
1313         struct pci_dev *dev = NULL;
1314         struct resource *res = NULL;
1315         unsigned char *edid = NULL;
1316
1317         if (device)
1318                 dev = to_pci_dev(device);
1319
1320         if (dev)
1321                 res = &dev->resource[PCI_ROM_RESOURCE];
1322
1323         if (res && res->flags & IORESOURCE_ROM_SHADOW)
1324                 edid = edid_info.dummy;
1325
1326         return edid;
1327 }
1328 #else
1329 const unsigned char *fb_firmware_edid(struct device *device)
1330 {
1331         return NULL;
1332 }
1333 #endif
1334 EXPORT_SYMBOL(fb_firmware_edid);
1335
1336 EXPORT_SYMBOL(fb_parse_edid);
1337 EXPORT_SYMBOL(fb_edid_to_monspecs);
1338 EXPORT_SYMBOL(fb_get_mode);
1339 EXPORT_SYMBOL(fb_validate_mode);
1340 EXPORT_SYMBOL(fb_destroy_modedb);