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