2 * linux/drivers/video/fbmon.c
4 * Copyright (C) 2002 James Simmons <jsimmons@users.sf.net>
8 * The EDID Parser is a conglomeration from the following sources:
10 * 1. SciTech SNAP Graphics Architecture
11 * Copyright (C) 1991-2002 SciTech Software, Inc. All rights reserved.
13 * 2. XFree86 4.3.0, interpret_edid.c
14 * Copyright 1998 by Egbert Eich <Egbert.Eich@Physik.TU-Darmstadt.DE>
16 * 3. John Fremlin <vii@users.sourceforge.net> and
17 * Ani Joshi <ajoshi@unixbox.com>
19 * Generalized Timing Formula is derived from:
21 * GTF Spreadsheet by Andy Morrish (1/5/97)
22 * available at http://www.vesa.org
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
30 #include <linux/module.h>
31 #include <linux/pci.h>
32 #include <linux/slab.h>
33 #include <video/edid.h>
34 #include <video/of_videomode.h>
35 #include <video/videomode.h>
42 #undef DEBUG /* define this for verbose EDID parsing output */
45 #define DPRINTK(fmt, args...) printk(fmt,## args)
47 #define DPRINTK(fmt, args...)
50 #define FBMON_FIX_HEADER 1
51 #define FBMON_FIX_INPUT 2
52 #define FBMON_FIX_TIMINGS 3
54 #ifdef CONFIG_FB_MODE_HELPERS
61 static const struct broken_edid brokendb
[] = {
64 .manufacturer
= "DEC",
66 .fix
= FBMON_FIX_HEADER
,
68 /* ViewSonic PF775a */
70 .manufacturer
= "VSC",
72 .fix
= FBMON_FIX_INPUT
,
76 .manufacturer
= "SHP",
78 .fix
= FBMON_FIX_TIMINGS
,
82 static const unsigned char edid_v1_header
[] = { 0x00, 0xff, 0xff, 0xff,
83 0xff, 0xff, 0xff, 0x00
86 static void copy_string(unsigned char *c
, unsigned char *s
)
90 for (i
= 0; (i
< 13 && *c
!= 0x0A); i
++)
93 while (i
-- && (*--s
== 0x20)) *s
= 0;
96 static int edid_is_serial_block(unsigned char *block
)
98 if ((block
[0] == 0x00) && (block
[1] == 0x00) &&
99 (block
[2] == 0x00) && (block
[3] == 0xff) &&
106 static int edid_is_ascii_block(unsigned char *block
)
108 if ((block
[0] == 0x00) && (block
[1] == 0x00) &&
109 (block
[2] == 0x00) && (block
[3] == 0xfe) &&
116 static int edid_is_limits_block(unsigned char *block
)
118 if ((block
[0] == 0x00) && (block
[1] == 0x00) &&
119 (block
[2] == 0x00) && (block
[3] == 0xfd) &&
126 static int edid_is_monitor_block(unsigned char *block
)
128 if ((block
[0] == 0x00) && (block
[1] == 0x00) &&
129 (block
[2] == 0x00) && (block
[3] == 0xfc) &&
136 static int edid_is_timing_block(unsigned char *block
)
138 if ((block
[0] != 0x00) || (block
[1] != 0x00) ||
139 (block
[2] != 0x00) || (block
[4] != 0x00))
145 static int check_edid(unsigned char *edid
)
147 unsigned char *block
= edid
+ ID_MANUFACTURER_NAME
, manufacturer
[4];
150 int i
, fix
= 0, ret
= 0;
152 manufacturer
[0] = ((block
[0] & 0x7c) >> 2) + '@';
153 manufacturer
[1] = ((block
[0] & 0x03) << 3) +
154 ((block
[1] & 0xe0) >> 5) + '@';
155 manufacturer
[2] = (block
[1] & 0x1f) + '@';
157 model
= block
[2] + (block
[3] << 8);
159 for (i
= 0; i
< ARRAY_SIZE(brokendb
); i
++) {
160 if (!strncmp(manufacturer
, brokendb
[i
].manufacturer
, 4) &&
161 brokendb
[i
].model
== model
) {
162 fix
= brokendb
[i
].fix
;
168 case FBMON_FIX_HEADER
:
169 for (i
= 0; i
< 8; i
++) {
170 if (edid
[i
] != edid_v1_header
[i
]) {
176 case FBMON_FIX_INPUT
:
177 b
= edid
+ EDID_STRUCT_DISPLAY
;
178 /* Only if display is GTF capable will
179 the input type be reset to analog */
180 if (b
[4] & 0x01 && b
[0] & 0x80)
183 case FBMON_FIX_TIMINGS
:
184 b
= edid
+ DETAILED_TIMING_DESCRIPTIONS_START
;
187 for (i
= 0; i
< 4; i
++) {
188 if (edid_is_limits_block(b
)) {
193 b
+= DETAILED_TIMING_DESCRIPTION_SIZE
;
200 printk("fbmon: The EDID Block of "
201 "Manufacturer: %s Model: 0x%x is known to "
202 "be broken,\n", manufacturer
, model
);
207 static void fix_edid(unsigned char *edid
, int fix
)
210 unsigned char *b
, csum
= 0;
213 case FBMON_FIX_HEADER
:
214 printk("fbmon: trying a header reconstruct\n");
215 memcpy(edid
, edid_v1_header
, 8);
217 case FBMON_FIX_INPUT
:
218 printk("fbmon: trying to fix input type\n");
219 b
= edid
+ EDID_STRUCT_DISPLAY
;
223 case FBMON_FIX_TIMINGS
:
224 printk("fbmon: trying to fix monitor timings\n");
225 b
= edid
+ DETAILED_TIMING_DESCRIPTIONS_START
;
226 for (i
= 0; i
< 4; i
++) {
227 if (!(edid_is_serial_block(b
) ||
228 edid_is_ascii_block(b
) ||
229 edid_is_monitor_block(b
) ||
230 edid_is_timing_block(b
))) {
236 b
[5] = 60; /* vfmin */
237 b
[6] = 60; /* vfmax */
238 b
[7] = 30; /* hfmin */
239 b
[8] = 75; /* hfmax */
240 b
[9] = 17; /* pixclock - 170 MHz*/
245 b
+= DETAILED_TIMING_DESCRIPTION_SIZE
;
248 for (i
= 0; i
< EDID_LENGTH
- 1; i
++)
251 edid
[127] = 256 - csum
;
256 static int edid_checksum(unsigned char *edid
)
258 unsigned char csum
= 0, all_null
= 0;
259 int i
, err
= 0, fix
= check_edid(edid
);
264 for (i
= 0; i
< EDID_LENGTH
; i
++) {
269 if (csum
== 0x00 && all_null
) {
270 /* checksum passed, everything's good */
277 static int edid_check_header(unsigned char *edid
)
279 int i
, err
= 1, fix
= check_edid(edid
);
284 for (i
= 0; i
< 8; i
++) {
285 if (edid
[i
] != edid_v1_header
[i
])
292 static void parse_vendor_block(unsigned char *block
, struct fb_monspecs
*specs
)
294 specs
->manufacturer
[0] = ((block
[0] & 0x7c) >> 2) + '@';
295 specs
->manufacturer
[1] = ((block
[0] & 0x03) << 3) +
296 ((block
[1] & 0xe0) >> 5) + '@';
297 specs
->manufacturer
[2] = (block
[1] & 0x1f) + '@';
298 specs
->manufacturer
[3] = 0;
299 specs
->model
= block
[2] + (block
[3] << 8);
300 specs
->serial
= block
[4] + (block
[5] << 8) +
301 (block
[6] << 16) + (block
[7] << 24);
302 specs
->year
= block
[9] + 1990;
303 specs
->week
= block
[8];
304 DPRINTK(" Manufacturer: %s\n", specs
->manufacturer
);
305 DPRINTK(" Model: %x\n", specs
->model
);
306 DPRINTK(" Serial#: %u\n", specs
->serial
);
307 DPRINTK(" Year: %u Week %u\n", specs
->year
, specs
->week
);
310 static void get_dpms_capabilities(unsigned char flags
,
311 struct fb_monspecs
*specs
)
314 if (flags
& DPMS_ACTIVE_OFF
)
315 specs
->dpms
|= FB_DPMS_ACTIVE_OFF
;
316 if (flags
& DPMS_SUSPEND
)
317 specs
->dpms
|= FB_DPMS_SUSPEND
;
318 if (flags
& DPMS_STANDBY
)
319 specs
->dpms
|= FB_DPMS_STANDBY
;
320 DPRINTK(" DPMS: Active %s, Suspend %s, Standby %s\n",
321 (flags
& DPMS_ACTIVE_OFF
) ? "yes" : "no",
322 (flags
& DPMS_SUSPEND
) ? "yes" : "no",
323 (flags
& DPMS_STANDBY
) ? "yes" : "no");
326 static void get_chroma(unsigned char *block
, struct fb_monspecs
*specs
)
330 DPRINTK(" Chroma\n");
331 /* Chromaticity data */
332 tmp
= ((block
[5] & (3 << 6)) >> 6) | (block
[0x7] << 2);
335 specs
->chroma
.redx
= tmp
/1024;
336 DPRINTK(" RedX: 0.%03d ", specs
->chroma
.redx
);
338 tmp
= ((block
[5] & (3 << 4)) >> 4) | (block
[0x8] << 2);
341 specs
->chroma
.redy
= tmp
/1024;
342 DPRINTK("RedY: 0.%03d\n", specs
->chroma
.redy
);
344 tmp
= ((block
[5] & (3 << 2)) >> 2) | (block
[0x9] << 2);
347 specs
->chroma
.greenx
= tmp
/1024;
348 DPRINTK(" GreenX: 0.%03d ", specs
->chroma
.greenx
);
350 tmp
= (block
[5] & 3) | (block
[0xa] << 2);
353 specs
->chroma
.greeny
= tmp
/1024;
354 DPRINTK("GreenY: 0.%03d\n", specs
->chroma
.greeny
);
356 tmp
= ((block
[6] & (3 << 6)) >> 6) | (block
[0xb] << 2);
359 specs
->chroma
.bluex
= tmp
/1024;
360 DPRINTK(" BlueX: 0.%03d ", specs
->chroma
.bluex
);
362 tmp
= ((block
[6] & (3 << 4)) >> 4) | (block
[0xc] << 2);
365 specs
->chroma
.bluey
= tmp
/1024;
366 DPRINTK("BlueY: 0.%03d\n", specs
->chroma
.bluey
);
368 tmp
= ((block
[6] & (3 << 2)) >> 2) | (block
[0xd] << 2);
371 specs
->chroma
.whitex
= tmp
/1024;
372 DPRINTK(" WhiteX: 0.%03d ", specs
->chroma
.whitex
);
374 tmp
= (block
[6] & 3) | (block
[0xe] << 2);
377 specs
->chroma
.whitey
= tmp
/1024;
378 DPRINTK("WhiteY: 0.%03d\n", specs
->chroma
.whitey
);
381 static void calc_mode_timings(int xres
, int yres
, int refresh
,
382 struct fb_videomode
*mode
)
384 struct fb_var_screeninfo
*var
;
386 var
= kzalloc(sizeof(struct fb_var_screeninfo
), GFP_KERNEL
);
391 fb_get_mode(FB_VSYNCTIMINGS
| FB_IGNOREMON
,
395 mode
->pixclock
= var
->pixclock
;
396 mode
->refresh
= refresh
;
397 mode
->left_margin
= var
->left_margin
;
398 mode
->right_margin
= var
->right_margin
;
399 mode
->upper_margin
= var
->upper_margin
;
400 mode
->lower_margin
= var
->lower_margin
;
401 mode
->hsync_len
= var
->hsync_len
;
402 mode
->vsync_len
= var
->vsync_len
;
409 static int get_est_timing(unsigned char *block
, struct fb_videomode
*mode
)
416 calc_mode_timings(720, 400, 70, &mode
[num
]);
417 mode
[num
++].flag
= FB_MODE_IS_CALCULATED
;
418 DPRINTK(" 720x400@70Hz\n");
421 calc_mode_timings(720, 400, 88, &mode
[num
]);
422 mode
[num
++].flag
= FB_MODE_IS_CALCULATED
;
423 DPRINTK(" 720x400@88Hz\n");
426 mode
[num
++] = vesa_modes
[3];
427 DPRINTK(" 640x480@60Hz\n");
430 calc_mode_timings(640, 480, 67, &mode
[num
]);
431 mode
[num
++].flag
= FB_MODE_IS_CALCULATED
;
432 DPRINTK(" 640x480@67Hz\n");
435 mode
[num
++] = vesa_modes
[4];
436 DPRINTK(" 640x480@72Hz\n");
439 mode
[num
++] = vesa_modes
[5];
440 DPRINTK(" 640x480@75Hz\n");
443 mode
[num
++] = vesa_modes
[7];
444 DPRINTK(" 800x600@56Hz\n");
447 mode
[num
++] = vesa_modes
[8];
448 DPRINTK(" 800x600@60Hz\n");
453 mode
[num
++] = vesa_modes
[9];
454 DPRINTK(" 800x600@72Hz\n");
457 mode
[num
++] = vesa_modes
[10];
458 DPRINTK(" 800x600@75Hz\n");
461 calc_mode_timings(832, 624, 75, &mode
[num
]);
462 mode
[num
++].flag
= FB_MODE_IS_CALCULATED
;
463 DPRINTK(" 832x624@75Hz\n");
466 mode
[num
++] = vesa_modes
[12];
467 DPRINTK(" 1024x768@87Hz Interlaced\n");
470 mode
[num
++] = vesa_modes
[13];
471 DPRINTK(" 1024x768@60Hz\n");
474 mode
[num
++] = vesa_modes
[14];
475 DPRINTK(" 1024x768@70Hz\n");
478 mode
[num
++] = vesa_modes
[15];
479 DPRINTK(" 1024x768@75Hz\n");
482 mode
[num
++] = vesa_modes
[21];
483 DPRINTK(" 1280x1024@75Hz\n");
487 mode
[num
++] = vesa_modes
[17];
488 DPRINTK(" 1152x870@75Hz\n");
490 DPRINTK(" Manufacturer's mask: %x\n",c
&0x7F);
494 static int get_std_timing(unsigned char *block
, struct fb_videomode
*mode
,
495 int ver
, int rev
, const struct fb_monspecs
*specs
)
499 for (i
= 0; i
< DMT_SIZE
; i
++) {
500 u32 std_2byte_code
= block
[0] << 8 | block
[1];
501 if (std_2byte_code
== dmt_modes
[i
].std_2byte_code
)
505 if (i
< DMT_SIZE
&& dmt_modes
[i
].mode
) {
507 *mode
= *dmt_modes
[i
].mode
;
508 mode
->flag
|= FB_MODE_IS_STANDARD
;
509 DPRINTK(" DMT id=%d\n", dmt_modes
[i
].dmt_id
);
512 int xres
, yres
= 0, refresh
, ratio
;
514 xres
= (block
[0] + 31) * 8;
518 ratio
= (block
[1] & 0xc0) >> 6;
521 /* in EDID 1.3 the meaning of 0 changed to 16:10 (prior 1:1) */
522 if (ver
< 1 || (ver
== 1 && rev
< 3))
525 yres
= (xres
* 10)/16;
534 yres
= (xres
* 9)/16;
537 refresh
= (block
[1] & 0x3f) + 60;
538 DPRINTK(" %dx%d@%dHz\n", xres
, yres
, refresh
);
540 calc_mode_timings(xres
, yres
, refresh
, mode
);
543 /* Check the mode we got is within valid spec of the monitor */
544 if (specs
&& specs
->dclkmax
545 && PICOS2KHZ(mode
->pixclock
) * 1000 > specs
->dclkmax
) {
546 DPRINTK(" mode exceed max DCLK\n");
553 static int get_dst_timing(unsigned char *block
, struct fb_videomode
*mode
,
554 int ver
, int rev
, const struct fb_monspecs
*specs
)
558 for (j
= 0; j
< 6; j
++, block
+= STD_TIMING_DESCRIPTION_SIZE
)
559 num
+= get_std_timing(block
, &mode
[num
], ver
, rev
, specs
);
564 static void get_detailed_timing(unsigned char *block
,
565 struct fb_videomode
*mode
)
567 mode
->xres
= H_ACTIVE
;
568 mode
->yres
= V_ACTIVE
;
569 mode
->pixclock
= PIXEL_CLOCK
;
570 mode
->pixclock
/= 1000;
571 mode
->pixclock
= KHZ2PICOS(mode
->pixclock
);
572 mode
->right_margin
= H_SYNC_OFFSET
;
573 mode
->left_margin
= (H_ACTIVE
+ H_BLANKING
) -
574 (H_ACTIVE
+ H_SYNC_OFFSET
+ H_SYNC_WIDTH
);
575 mode
->upper_margin
= V_BLANKING
- V_SYNC_OFFSET
-
577 mode
->lower_margin
= V_SYNC_OFFSET
;
578 mode
->hsync_len
= H_SYNC_WIDTH
;
579 mode
->vsync_len
= V_SYNC_WIDTH
;
581 mode
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
583 mode
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
584 mode
->refresh
= PIXEL_CLOCK
/((H_ACTIVE
+ H_BLANKING
) *
585 (V_ACTIVE
+ V_BLANKING
));
588 mode
->upper_margin
*= 2;
589 mode
->lower_margin
*= 2;
590 mode
->vsync_len
*= 2;
591 mode
->vmode
|= FB_VMODE_INTERLACED
;
593 mode
->flag
= FB_MODE_IS_DETAILED
;
595 DPRINTK(" %d MHz ", PIXEL_CLOCK
/1000000);
596 DPRINTK("%d %d %d %d ", H_ACTIVE
, H_ACTIVE
+ H_SYNC_OFFSET
,
597 H_ACTIVE
+ H_SYNC_OFFSET
+ H_SYNC_WIDTH
, H_ACTIVE
+ H_BLANKING
);
598 DPRINTK("%d %d %d %d ", V_ACTIVE
, V_ACTIVE
+ V_SYNC_OFFSET
,
599 V_ACTIVE
+ V_SYNC_OFFSET
+ V_SYNC_WIDTH
, V_ACTIVE
+ V_BLANKING
);
600 DPRINTK("%sHSync %sVSync\n\n", (HSYNC_POSITIVE
) ? "+" : "-",
601 (VSYNC_POSITIVE
) ? "+" : "-");
605 * fb_create_modedb - create video mode database
607 * @dbsize: database size
609 * RETURNS: struct fb_videomode, @dbsize contains length of database
612 * This function builds a mode database using the contents of the EDID
615 static struct fb_videomode
*fb_create_modedb(unsigned char *edid
, int *dbsize
,
616 const struct fb_monspecs
*specs
)
618 struct fb_videomode
*mode
, *m
;
619 unsigned char *block
;
620 int num
= 0, i
, first
= 1;
623 mode
= kzalloc(50 * sizeof(struct fb_videomode
), GFP_KERNEL
);
627 if (edid
== NULL
|| !edid_checksum(edid
) ||
628 !edid_check_header(edid
)) {
633 ver
= edid
[EDID_STRUCT_VERSION
];
634 rev
= edid
[EDID_STRUCT_REVISION
];
638 DPRINTK(" Detailed Timings\n");
639 block
= edid
+ DETAILED_TIMING_DESCRIPTIONS_START
;
640 for (i
= 0; i
< 4; i
++, block
+= DETAILED_TIMING_DESCRIPTION_SIZE
) {
641 if (!(block
[0] == 0x00 && block
[1] == 0x00)) {
642 get_detailed_timing(block
, &mode
[num
]);
644 mode
[num
].flag
|= FB_MODE_IS_FIRST
;
651 DPRINTK(" Supported VESA Modes\n");
652 block
= edid
+ ESTABLISHED_TIMING_1
;
653 num
+= get_est_timing(block
, &mode
[num
]);
655 DPRINTK(" Standard Timings\n");
656 block
= edid
+ STD_TIMING_DESCRIPTIONS_START
;
657 for (i
= 0; i
< STD_TIMING
; i
++, block
+= STD_TIMING_DESCRIPTION_SIZE
)
658 num
+= get_std_timing(block
, &mode
[num
], ver
, rev
, specs
);
660 block
= edid
+ DETAILED_TIMING_DESCRIPTIONS_START
;
661 for (i
= 0; i
< 4; i
++, block
+= DETAILED_TIMING_DESCRIPTION_SIZE
) {
662 if (block
[0] == 0x00 && block
[1] == 0x00 && block
[3] == 0xfa)
663 num
+= get_dst_timing(block
+ 5, &mode
[num
],
667 /* Yikes, EDID data is totally useless */
674 m
= kmalloc(num
* sizeof(struct fb_videomode
), GFP_KERNEL
);
677 memmove(m
, mode
, num
* sizeof(struct fb_videomode
));
683 * fb_destroy_modedb - destroys mode database
684 * @modedb: mode database to destroy
687 * Destroy mode database created by fb_create_modedb
689 void fb_destroy_modedb(struct fb_videomode
*modedb
)
694 static int fb_get_monitor_limits(unsigned char *edid
, struct fb_monspecs
*specs
)
697 unsigned char *block
;
699 block
= edid
+ DETAILED_TIMING_DESCRIPTIONS_START
;
701 DPRINTK(" Monitor Operating Limits: ");
703 for (i
= 0; i
< 4; i
++, block
+= DETAILED_TIMING_DESCRIPTION_SIZE
) {
704 if (edid_is_limits_block(block
)) {
705 specs
->hfmin
= H_MIN_RATE
* 1000;
706 specs
->hfmax
= H_MAX_RATE
* 1000;
707 specs
->vfmin
= V_MIN_RATE
;
708 specs
->vfmax
= V_MAX_RATE
;
709 specs
->dclkmax
= MAX_PIXEL_CLOCK
* 1000000;
710 specs
->gtf
= (GTF_SUPPORT
) ? 1 : 0;
712 DPRINTK("From EDID\n");
717 /* estimate monitor limits based on modes supported */
719 struct fb_videomode
*modes
, *mode
;
720 int num_modes
, hz
, hscan
, pixclock
;
723 modes
= fb_create_modedb(edid
, &num_modes
, specs
);
725 DPRINTK("None Available\n");
730 for (i
= 0; i
< num_modes
; i
++) {
732 pixclock
= PICOS2KHZ(modes
[i
].pixclock
) * 1000;
733 htotal
= mode
->xres
+ mode
->right_margin
+ mode
->hsync_len
735 vtotal
= mode
->yres
+ mode
->lower_margin
+ mode
->vsync_len
736 + mode
->upper_margin
;
738 if (mode
->vmode
& FB_VMODE_INTERLACED
)
741 if (mode
->vmode
& FB_VMODE_DOUBLE
)
744 hscan
= (pixclock
+ htotal
/ 2) / htotal
;
745 hscan
= (hscan
+ 500) / 1000 * 1000;
746 hz
= (hscan
+ vtotal
/ 2) / vtotal
;
748 if (specs
->dclkmax
== 0 || specs
->dclkmax
< pixclock
)
749 specs
->dclkmax
= pixclock
;
751 if (specs
->dclkmin
== 0 || specs
->dclkmin
> pixclock
)
752 specs
->dclkmin
= pixclock
;
754 if (specs
->hfmax
== 0 || specs
->hfmax
< hscan
)
755 specs
->hfmax
= hscan
;
757 if (specs
->hfmin
== 0 || specs
->hfmin
> hscan
)
758 specs
->hfmin
= hscan
;
760 if (specs
->vfmax
== 0 || specs
->vfmax
< hz
)
763 if (specs
->vfmin
== 0 || specs
->vfmin
> hz
)
766 DPRINTK("Extrapolated\n");
767 fb_destroy_modedb(modes
);
769 DPRINTK(" H: %d-%dKHz V: %d-%dHz DCLK: %dMHz\n",
770 specs
->hfmin
/1000, specs
->hfmax
/1000, specs
->vfmin
,
771 specs
->vfmax
, specs
->dclkmax
/1000000);
775 static void get_monspecs(unsigned char *edid
, struct fb_monspecs
*specs
)
777 unsigned char c
, *block
;
779 block
= edid
+ EDID_STRUCT_DISPLAY
;
781 fb_get_monitor_limits(edid
, specs
);
786 specs
->input
|= FB_DISP_DDI
;
787 DPRINTK(" Digital Display Input");
789 DPRINTK(" Analog Display Input: Input Voltage - ");
790 switch ((block
[0] & 0x60) >> 5) {
792 DPRINTK("0.700V/0.300V");
793 specs
->input
|= FB_DISP_ANA_700_300
;
796 DPRINTK("0.714V/0.286V");
797 specs
->input
|= FB_DISP_ANA_714_286
;
800 DPRINTK("1.000V/0.400V");
801 specs
->input
|= FB_DISP_ANA_1000_400
;
804 DPRINTK("0.700V/0.000V");
805 specs
->input
|= FB_DISP_ANA_700_000
;
809 DPRINTK("\n Sync: ");
812 DPRINTK(" Configurable signal level\n");
816 DPRINTK("Blank to Blank ");
817 specs
->signal
|= FB_SIGNAL_BLANK_BLANK
;
820 DPRINTK("Separate ");
821 specs
->signal
|= FB_SIGNAL_SEPARATE
;
824 DPRINTK("Composite ");
825 specs
->signal
|= FB_SIGNAL_COMPOSITE
;
828 DPRINTK("Sync on Green ");
829 specs
->signal
|= FB_SIGNAL_SYNC_ON_GREEN
;
832 DPRINTK("Serration on ");
833 specs
->signal
|= FB_SIGNAL_SERRATION_ON
;
836 specs
->max_x
= block
[1];
837 specs
->max_y
= block
[2];
838 DPRINTK(" Max H-size in cm: ");
840 DPRINTK("%d\n", specs
->max_x
);
842 DPRINTK("variable\n");
843 DPRINTK(" Max V-size in cm: ");
845 DPRINTK("%d\n", specs
->max_y
);
847 DPRINTK("variable\n");
850 specs
->gamma
= c
+100;
852 DPRINTK("%d.%d\n", specs
->gamma
/100, specs
->gamma
% 100);
854 get_dpms_capabilities(block
[4], specs
);
856 switch ((block
[4] & 0x18) >> 3) {
858 DPRINTK(" Monochrome/Grayscale\n");
859 specs
->input
|= FB_DISP_MONO
;
862 DPRINTK(" RGB Color Display\n");
863 specs
->input
|= FB_DISP_RGB
;
866 DPRINTK(" Non-RGB Multicolor Display\n");
867 specs
->input
|= FB_DISP_MULTI
;
870 DPRINTK(" Unknown\n");
871 specs
->input
|= FB_DISP_UNKNOWN
;
875 get_chroma(block
, specs
);
880 DPRINTK(" Default color format is primary\n");
881 specs
->misc
|= FB_MISC_PRIM_COLOR
;
884 DPRINTK(" First DETAILED Timing is preferred\n");
885 specs
->misc
|= FB_MISC_1ST_DETAIL
;
888 printk(" Display is GTF capable\n");
893 int fb_parse_edid(unsigned char *edid
, struct fb_var_screeninfo
*var
)
896 unsigned char *block
;
898 if (edid
== NULL
|| var
== NULL
)
901 if (!(edid_checksum(edid
)))
904 if (!(edid_check_header(edid
)))
907 block
= edid
+ DETAILED_TIMING_DESCRIPTIONS_START
;
909 for (i
= 0; i
< 4; i
++, block
+= DETAILED_TIMING_DESCRIPTION_SIZE
) {
910 if (edid_is_timing_block(block
)) {
911 var
->xres
= var
->xres_virtual
= H_ACTIVE
;
912 var
->yres
= var
->yres_virtual
= V_ACTIVE
;
913 var
->height
= var
->width
= 0;
914 var
->right_margin
= H_SYNC_OFFSET
;
915 var
->left_margin
= (H_ACTIVE
+ H_BLANKING
) -
916 (H_ACTIVE
+ H_SYNC_OFFSET
+ H_SYNC_WIDTH
);
917 var
->upper_margin
= V_BLANKING
- V_SYNC_OFFSET
-
919 var
->lower_margin
= V_SYNC_OFFSET
;
920 var
->hsync_len
= H_SYNC_WIDTH
;
921 var
->vsync_len
= V_SYNC_WIDTH
;
922 var
->pixclock
= PIXEL_CLOCK
;
923 var
->pixclock
/= 1000;
924 var
->pixclock
= KHZ2PICOS(var
->pixclock
);
927 var
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
929 var
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
936 void fb_edid_to_monspecs(unsigned char *edid
, struct fb_monspecs
*specs
)
938 unsigned char *block
;
944 if (!(edid_checksum(edid
)))
947 if (!(edid_check_header(edid
)))
950 memset(specs
, 0, sizeof(struct fb_monspecs
));
952 specs
->version
= edid
[EDID_STRUCT_VERSION
];
953 specs
->revision
= edid
[EDID_STRUCT_REVISION
];
955 DPRINTK("========================================\n");
956 DPRINTK("Display Information (EDID)\n");
957 DPRINTK("========================================\n");
958 DPRINTK(" EDID Version %d.%d\n", (int) specs
->version
,
959 (int) specs
->revision
);
961 parse_vendor_block(edid
+ ID_MANUFACTURER_NAME
, specs
);
963 block
= edid
+ DETAILED_TIMING_DESCRIPTIONS_START
;
964 for (i
= 0; i
< 4; i
++, block
+= DETAILED_TIMING_DESCRIPTION_SIZE
) {
965 if (edid_is_serial_block(block
)) {
966 copy_string(block
, specs
->serial_no
);
967 DPRINTK(" Serial Number: %s\n", specs
->serial_no
);
968 } else if (edid_is_ascii_block(block
)) {
969 copy_string(block
, specs
->ascii
);
970 DPRINTK(" ASCII Block: %s\n", specs
->ascii
);
971 } else if (edid_is_monitor_block(block
)) {
972 copy_string(block
, specs
->monitor
);
973 DPRINTK(" Monitor Name: %s\n", specs
->monitor
);
977 DPRINTK(" Display Characteristics:\n");
978 get_monspecs(edid
, specs
);
980 specs
->modedb
= fb_create_modedb(edid
, &specs
->modedb_len
, specs
);
983 * Workaround for buggy EDIDs that sets that the first
984 * detailed timing is preferred but has not detailed
987 for (i
= 0; i
< specs
->modedb_len
; i
++) {
988 if (specs
->modedb
[i
].flag
& FB_MODE_IS_DETAILED
) {
995 specs
->misc
&= ~FB_MISC_1ST_DETAIL
;
997 DPRINTK("========================================\n");
1001 * fb_edid_add_monspecs() - add monitor video modes from E-EDID data
1002 * @edid: 128 byte array with an E-EDID block
1003 * @spacs: monitor specs to be extended
1005 void fb_edid_add_monspecs(unsigned char *edid
, struct fb_monspecs
*specs
)
1007 unsigned char *block
;
1008 struct fb_videomode
*m
;
1010 u8 svd
[64], edt
[(128 - 4) / DETAILED_TIMING_DESCRIPTION_SIZE
];
1011 u8 pos
= 4, svd_n
= 0;
1016 if (!edid_checksum(edid
))
1019 if (edid
[0] != 0x2 ||
1020 edid
[2] < 4 || edid
[2] > 128 - DETAILED_TIMING_DESCRIPTION_SIZE
)
1023 DPRINTK(" Short Video Descriptors\n");
1025 while (pos
< edid
[2]) {
1026 u8 len
= edid
[pos
] & 0x1f, type
= (edid
[pos
] >> 5) & 7;
1027 pr_debug("Data block %u of %u bytes\n", type
, len
);
1029 for (i
= pos
; i
< pos
+ len
; i
++) {
1030 u8 idx
= edid
[pos
+ i
] & 0x7f;
1032 pr_debug("N%sative mode #%d\n",
1033 edid
[pos
+ i
] & 0x80 ? "" : "on-n", idx
);
1035 } else if (type
== 3 && len
>= 3) {
1036 /* Check Vendor Specific Data Block. For HDMI,
1037 it is always 00-0C-03 for HDMI Licensing, LLC. */
1038 if (edid
[pos
+ 1] == 3 && edid
[pos
+ 2] == 0xc &&
1040 specs
->misc
|= FB_MISC_HDMI
;
1045 block
= edid
+ edid
[2];
1047 DPRINTK(" Extended Detailed Timings\n");
1049 for (i
= 0; i
< (128 - edid
[2]) / DETAILED_TIMING_DESCRIPTION_SIZE
;
1050 i
++, block
+= DETAILED_TIMING_DESCRIPTION_SIZE
)
1052 edt
[num
++] = block
- edid
;
1054 /* Yikes, EDID data is totally useless */
1058 m
= kzalloc((specs
->modedb_len
+ num
+ svd_n
) *
1059 sizeof(struct fb_videomode
), GFP_KERNEL
);
1064 memcpy(m
, specs
->modedb
, specs
->modedb_len
* sizeof(struct fb_videomode
));
1066 for (i
= specs
->modedb_len
; i
< specs
->modedb_len
+ num
; i
++) {
1067 get_detailed_timing(edid
+ edt
[i
- specs
->modedb_len
], &m
[i
]);
1068 if (i
== specs
->modedb_len
)
1069 m
[i
].flag
|= FB_MODE_IS_FIRST
;
1070 pr_debug("Adding %ux%u@%u\n", m
[i
].xres
, m
[i
].yres
, m
[i
].refresh
);
1073 for (i
= specs
->modedb_len
+ num
; i
< specs
->modedb_len
+ num
+ svd_n
; i
++) {
1074 int idx
= svd
[i
- specs
->modedb_len
- num
];
1075 if (!idx
|| idx
> 63) {
1076 pr_warning("Reserved SVD code %d\n", idx
);
1077 } else if (idx
> ARRAY_SIZE(cea_modes
) || !cea_modes
[idx
].xres
) {
1078 pr_warning("Unimplemented SVD code %d\n", idx
);
1080 memcpy(&m
[i
], cea_modes
+ idx
, sizeof(m
[i
]));
1081 pr_debug("Adding SVD #%d: %ux%u@%u\n", idx
,
1082 m
[i
].xres
, m
[i
].yres
, m
[i
].refresh
);
1086 kfree(specs
->modedb
);
1088 specs
->modedb_len
= specs
->modedb_len
+ num
+ svd_n
;
1092 * VESA Generalized Timing Formula (GTF)
1096 #define V_FRONTPORCH 1
1098 #define H_SCALEFACTOR 20
1099 #define H_BLANKSCALE 128
1100 #define H_GRADIENT 600
1104 struct __fb_timings
{
1117 * fb_get_vblank - get vertical blank time
1118 * @hfreq: horizontal freq
1121 * vblank = right_margin + vsync_len + left_margin
1123 * given: right_margin = 1 (V_FRONTPORCH)
1128 * left_margin = --------------- - vsync_len
1131 static u32
fb_get_vblank(u32 hfreq
)
1135 vblank
= (hfreq
* FLYBACK
)/1000;
1136 vblank
= (vblank
+ 500)/1000;
1137 return (vblank
+ V_FRONTPORCH
);
1141 * fb_get_hblank_by_freq - get horizontal blank time given hfreq
1142 * @hfreq: horizontal freq
1143 * @xres: horizontal resolution in pixels
1148 * hblank = ------------------
1151 * duty cycle = percent of htotal assigned to inactive display
1152 * duty cycle = C - (M/Hfreq)
1154 * where: C = ((offset - scale factor) * blank_scale)
1155 * -------------------------------------- + scale factor
1157 * M = blank_scale * gradient
1160 static u32
fb_get_hblank_by_hfreq(u32 hfreq
, u32 xres
)
1162 u32 c_val
, m_val
, duty_cycle
, hblank
;
1164 c_val
= (((H_OFFSET
- H_SCALEFACTOR
) * H_BLANKSCALE
)/256 +
1165 H_SCALEFACTOR
) * 1000;
1166 m_val
= (H_BLANKSCALE
* H_GRADIENT
)/256;
1167 m_val
= (m_val
* 1000000)/hfreq
;
1168 duty_cycle
= c_val
- m_val
;
1169 hblank
= (xres
* duty_cycle
)/(100000 - duty_cycle
);
1174 * fb_get_hblank_by_dclk - get horizontal blank time given pixelclock
1175 * @dclk: pixelclock in Hz
1176 * @xres: horizontal resolution in pixels
1181 * hblank = ------------------
1184 * duty cycle = percent of htotal assigned to inactive display
1185 * duty cycle = C - (M * h_period)
1187 * where: h_period = SQRT(100 - C + (0.4 * xres * M)/dclk) + C - 100
1188 * -----------------------------------------------
1194 static u32
fb_get_hblank_by_dclk(u32 dclk
, u32 xres
)
1196 u32 duty_cycle
, h_period
, hblank
;
1199 h_period
= 100 - C_VAL
;
1200 h_period
*= h_period
;
1201 h_period
+= (M_VAL
* xres
* 2 * 1000)/(5 * dclk
);
1204 h_period
= int_sqrt(h_period
);
1205 h_period
-= (100 - C_VAL
) * 100;
1207 h_period
/= 2 * M_VAL
;
1209 duty_cycle
= C_VAL
* 1000 - (M_VAL
* h_period
)/100;
1210 hblank
= (xres
* duty_cycle
)/(100000 - duty_cycle
) + 8;
1216 * fb_get_hfreq - estimate hsync
1217 * @vfreq: vertical refresh rate
1218 * @yres: vertical resolution
1222 * (yres + front_port) * vfreq * 1000000
1223 * hfreq = -------------------------------------
1224 * (1000000 - (vfreq * FLYBACK)
1228 static u32
fb_get_hfreq(u32 vfreq
, u32 yres
)
1232 divisor
= (1000000 - (vfreq
* FLYBACK
))/1000;
1233 hfreq
= (yres
+ V_FRONTPORCH
) * vfreq
* 1000;
1234 return (hfreq
/divisor
);
1237 static void fb_timings_vfreq(struct __fb_timings
*timings
)
1239 timings
->hfreq
= fb_get_hfreq(timings
->vfreq
, timings
->vactive
);
1240 timings
->vblank
= fb_get_vblank(timings
->hfreq
);
1241 timings
->vtotal
= timings
->vactive
+ timings
->vblank
;
1242 timings
->hblank
= fb_get_hblank_by_hfreq(timings
->hfreq
,
1244 timings
->htotal
= timings
->hactive
+ timings
->hblank
;
1245 timings
->dclk
= timings
->htotal
* timings
->hfreq
;
1248 static void fb_timings_hfreq(struct __fb_timings
*timings
)
1250 timings
->vblank
= fb_get_vblank(timings
->hfreq
);
1251 timings
->vtotal
= timings
->vactive
+ timings
->vblank
;
1252 timings
->vfreq
= timings
->hfreq
/timings
->vtotal
;
1253 timings
->hblank
= fb_get_hblank_by_hfreq(timings
->hfreq
,
1255 timings
->htotal
= timings
->hactive
+ timings
->hblank
;
1256 timings
->dclk
= timings
->htotal
* timings
->hfreq
;
1259 static void fb_timings_dclk(struct __fb_timings
*timings
)
1261 timings
->hblank
= fb_get_hblank_by_dclk(timings
->dclk
,
1263 timings
->htotal
= timings
->hactive
+ timings
->hblank
;
1264 timings
->hfreq
= timings
->dclk
/timings
->htotal
;
1265 timings
->vblank
= fb_get_vblank(timings
->hfreq
);
1266 timings
->vtotal
= timings
->vactive
+ timings
->vblank
;
1267 timings
->vfreq
= timings
->hfreq
/timings
->vtotal
;
1271 * fb_get_mode - calculates video mode using VESA GTF
1272 * @flags: if: 0 - maximize vertical refresh rate
1273 * 1 - vrefresh-driven calculation;
1274 * 2 - hscan-driven calculation;
1275 * 3 - pixelclock-driven calculation;
1276 * @val: depending on @flags, ignored, vrefresh, hsync or pixelclock
1277 * @var: pointer to fb_var_screeninfo
1278 * @info: pointer to fb_info
1281 * Calculates video mode based on monitor specs using VESA GTF.
1282 * The GTF is best for VESA GTF compliant monitors but is
1283 * specifically formulated to work for older monitors as well.
1285 * If @flag==0, the function will attempt to maximize the
1286 * refresh rate. Otherwise, it will calculate timings based on
1287 * the flag and accompanying value.
1289 * If FB_IGNOREMON bit is set in @flags, monitor specs will be
1290 * ignored and @var will be filled with the calculated timings.
1292 * All calculations are based on the VESA GTF Spreadsheet
1293 * available at VESA's public ftp (http://www.vesa.org).
1296 * The timings generated by the GTF will be different from VESA
1297 * DMT. It might be a good idea to keep a table of standard
1298 * VESA modes as well. The GTF may also not work for some displays,
1299 * such as, and especially, analog TV.
1302 * A valid info->monspecs, otherwise 'safe numbers' will be used.
1304 int fb_get_mode(int flags
, u32 val
, struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1306 struct __fb_timings
*timings
;
1307 u32 interlace
= 1, dscan
= 1;
1308 u32 hfmin
, hfmax
, vfmin
, vfmax
, dclkmin
, dclkmax
, err
= 0;
1311 timings
= kzalloc(sizeof(struct __fb_timings
), GFP_KERNEL
);
1317 * If monspecs are invalid, use values that are enough
1320 if (!info
|| !info
->monspecs
.hfmax
|| !info
->monspecs
.vfmax
||
1321 !info
->monspecs
.dclkmax
||
1322 info
->monspecs
.hfmax
< info
->monspecs
.hfmin
||
1323 info
->monspecs
.vfmax
< info
->monspecs
.vfmin
||
1324 info
->monspecs
.dclkmax
< info
->monspecs
.dclkmin
) {
1325 hfmin
= 29000; hfmax
= 30000;
1326 vfmin
= 60; vfmax
= 60;
1327 dclkmin
= 0; dclkmax
= 25000000;
1329 hfmin
= info
->monspecs
.hfmin
;
1330 hfmax
= info
->monspecs
.hfmax
;
1331 vfmin
= info
->monspecs
.vfmin
;
1332 vfmax
= info
->monspecs
.vfmax
;
1333 dclkmin
= info
->monspecs
.dclkmin
;
1334 dclkmax
= info
->monspecs
.dclkmax
;
1337 timings
->hactive
= var
->xres
;
1338 timings
->vactive
= var
->yres
;
1339 if (var
->vmode
& FB_VMODE_INTERLACED
) {
1340 timings
->vactive
/= 2;
1343 if (var
->vmode
& FB_VMODE_DOUBLE
) {
1344 timings
->vactive
*= 2;
1348 switch (flags
& ~FB_IGNOREMON
) {
1349 case FB_MAXTIMINGS
: /* maximize refresh rate */
1350 timings
->hfreq
= hfmax
;
1351 fb_timings_hfreq(timings
);
1352 if (timings
->vfreq
> vfmax
) {
1353 timings
->vfreq
= vfmax
;
1354 fb_timings_vfreq(timings
);
1356 if (timings
->dclk
> dclkmax
) {
1357 timings
->dclk
= dclkmax
;
1358 fb_timings_dclk(timings
);
1361 case FB_VSYNCTIMINGS
: /* vrefresh driven */
1362 timings
->vfreq
= val
;
1363 fb_timings_vfreq(timings
);
1365 case FB_HSYNCTIMINGS
: /* hsync driven */
1366 timings
->hfreq
= val
;
1367 fb_timings_hfreq(timings
);
1369 case FB_DCLKTIMINGS
: /* pixelclock driven */
1370 timings
->dclk
= PICOS2KHZ(val
) * 1000;
1371 fb_timings_dclk(timings
);
1378 if (err
|| (!(flags
& FB_IGNOREMON
) &&
1379 (timings
->vfreq
< vfmin
|| timings
->vfreq
> vfmax
||
1380 timings
->hfreq
< hfmin
|| timings
->hfreq
> hfmax
||
1381 timings
->dclk
< dclkmin
|| timings
->dclk
> dclkmax
))) {
1384 var
->pixclock
= KHZ2PICOS(timings
->dclk
/1000);
1385 var
->hsync_len
= (timings
->htotal
* 8)/100;
1386 var
->right_margin
= (timings
->hblank
/2) - var
->hsync_len
;
1387 var
->left_margin
= timings
->hblank
- var
->right_margin
-
1389 var
->vsync_len
= (3 * interlace
)/dscan
;
1390 var
->lower_margin
= (1 * interlace
)/dscan
;
1391 var
->upper_margin
= (timings
->vblank
* interlace
)/dscan
-
1392 (var
->vsync_len
+ var
->lower_margin
);
1399 #ifdef CONFIG_VIDEOMODE_HELPERS
1400 int fb_videomode_from_videomode(const struct videomode
*vm
,
1401 struct fb_videomode
*fbmode
)
1403 unsigned int htotal
, vtotal
;
1405 fbmode
->xres
= vm
->hactive
;
1406 fbmode
->left_margin
= vm
->hback_porch
;
1407 fbmode
->right_margin
= vm
->hfront_porch
;
1408 fbmode
->hsync_len
= vm
->hsync_len
;
1410 fbmode
->yres
= vm
->vactive
;
1411 fbmode
->upper_margin
= vm
->vback_porch
;
1412 fbmode
->lower_margin
= vm
->vfront_porch
;
1413 fbmode
->vsync_len
= vm
->vsync_len
;
1415 /* prevent division by zero in KHZ2PICOS macro */
1416 fbmode
->pixclock
= vm
->pixelclock
?
1417 KHZ2PICOS(vm
->pixelclock
/ 1000) : 0;
1421 if (vm
->flags
& DISPLAY_FLAGS_HSYNC_HIGH
)
1422 fbmode
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
1423 if (vm
->flags
& DISPLAY_FLAGS_VSYNC_HIGH
)
1424 fbmode
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
1425 if (vm
->flags
& DISPLAY_FLAGS_INTERLACED
)
1426 fbmode
->vmode
|= FB_VMODE_INTERLACED
;
1427 if (vm
->flags
& DISPLAY_FLAGS_DOUBLESCAN
)
1428 fbmode
->vmode
|= FB_VMODE_DOUBLE
;
1431 htotal
= vm
->hactive
+ vm
->hfront_porch
+ vm
->hback_porch
+
1433 vtotal
= vm
->vactive
+ vm
->vfront_porch
+ vm
->vback_porch
+
1435 /* prevent division by zero */
1436 if (htotal
&& vtotal
) {
1437 fbmode
->refresh
= vm
->pixelclock
/ (htotal
* vtotal
);
1438 /* a mode must have htotal and vtotal != 0 or it is invalid */
1440 fbmode
->refresh
= 0;
1446 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode
);
1449 static inline void dump_fb_videomode(const struct fb_videomode
*m
)
1451 pr_debug("fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u %u\n",
1452 m
->xres
, m
->yres
, m
->refresh
, m
->pixclock
, m
->left_margin
,
1453 m
->right_margin
, m
->upper_margin
, m
->lower_margin
,
1454 m
->hsync_len
, m
->vsync_len
, m
->sync
, m
->vmode
, m
->flag
);
1458 * of_get_fb_videomode - get a fb_videomode from devicetree
1459 * @np: device_node with the timing specification
1460 * @fb: will be set to the return value
1461 * @index: index into the list of display timings in devicetree
1464 * This function is expensive and should only be used, if only one mode is to be
1465 * read from DT. To get multiple modes start with of_get_display_timings ond
1466 * work with that instead.
1468 int of_get_fb_videomode(struct device_node
*np
, struct fb_videomode
*fb
,
1471 struct videomode vm
;
1474 ret
= of_get_videomode(np
, &vm
, index
);
1478 fb_videomode_from_videomode(&vm
, fb
);
1480 pr_debug("%s: got %dx%d display mode from %s\n",
1481 of_node_full_name(np
), vm
.hactive
, vm
.vactive
, np
->name
);
1482 dump_fb_videomode(fb
);
1486 EXPORT_SYMBOL_GPL(of_get_fb_videomode
);
1487 #endif /* CONFIG_OF */
1488 #endif /* CONFIG_VIDEOMODE_HELPERS */
1491 int fb_parse_edid(unsigned char *edid
, struct fb_var_screeninfo
*var
)
1495 void fb_edid_to_monspecs(unsigned char *edid
, struct fb_monspecs
*specs
)
1499 void fb_edid_add_monspecs(unsigned char *edid
, struct fb_monspecs
*specs
)
1502 void fb_destroy_modedb(struct fb_videomode
*modedb
)
1505 int fb_get_mode(int flags
, u32 val
, struct fb_var_screeninfo
*var
,
1506 struct fb_info
*info
)
1510 #endif /* CONFIG_FB_MODE_HELPERS */
1513 * fb_validate_mode - validates var against monitor capabilities
1514 * @var: pointer to fb_var_screeninfo
1515 * @info: pointer to fb_info
1518 * Validates video mode against monitor capabilities specified in
1522 * A valid info->monspecs.
1524 int fb_validate_mode(const struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1526 u32 hfreq
, vfreq
, htotal
, vtotal
, pixclock
;
1527 u32 hfmin
, hfmax
, vfmin
, vfmax
, dclkmin
, dclkmax
;
1530 * If monspecs are invalid, use values that are enough
1533 if (!info
->monspecs
.hfmax
|| !info
->monspecs
.vfmax
||
1534 !info
->monspecs
.dclkmax
||
1535 info
->monspecs
.hfmax
< info
->monspecs
.hfmin
||
1536 info
->monspecs
.vfmax
< info
->monspecs
.vfmin
||
1537 info
->monspecs
.dclkmax
< info
->monspecs
.dclkmin
) {
1538 hfmin
= 29000; hfmax
= 30000;
1539 vfmin
= 60; vfmax
= 60;
1540 dclkmin
= 0; dclkmax
= 25000000;
1542 hfmin
= info
->monspecs
.hfmin
;
1543 hfmax
= info
->monspecs
.hfmax
;
1544 vfmin
= info
->monspecs
.vfmin
;
1545 vfmax
= info
->monspecs
.vfmax
;
1546 dclkmin
= info
->monspecs
.dclkmin
;
1547 dclkmax
= info
->monspecs
.dclkmax
;
1552 pixclock
= PICOS2KHZ(var
->pixclock
) * 1000;
1554 htotal
= var
->xres
+ var
->right_margin
+ var
->hsync_len
+
1556 vtotal
= var
->yres
+ var
->lower_margin
+ var
->vsync_len
+
1559 if (var
->vmode
& FB_VMODE_INTERLACED
)
1561 if (var
->vmode
& FB_VMODE_DOUBLE
)
1564 hfreq
= pixclock
/htotal
;
1565 hfreq
= (hfreq
+ 500) / 1000 * 1000;
1567 vfreq
= hfreq
/vtotal
;
1569 return (vfreq
< vfmin
|| vfreq
> vfmax
||
1570 hfreq
< hfmin
|| hfreq
> hfmax
||
1571 pixclock
< dclkmin
|| pixclock
> dclkmax
) ?
1575 #if defined(CONFIG_FIRMWARE_EDID) && defined(CONFIG_X86)
1578 * We need to ensure that the EDID block is only returned for
1579 * the primary graphics adapter.
1582 const unsigned char *fb_firmware_edid(struct device
*device
)
1584 struct pci_dev
*dev
= NULL
;
1585 struct resource
*res
= NULL
;
1586 unsigned char *edid
= NULL
;
1589 dev
= to_pci_dev(device
);
1592 res
= &dev
->resource
[PCI_ROM_RESOURCE
];
1594 if (res
&& res
->flags
& IORESOURCE_ROM_SHADOW
)
1595 edid
= edid_info
.dummy
;
1600 const unsigned char *fb_firmware_edid(struct device
*device
)
1605 EXPORT_SYMBOL(fb_firmware_edid
);
1607 EXPORT_SYMBOL(fb_parse_edid
);
1608 EXPORT_SYMBOL(fb_edid_to_monspecs
);
1609 EXPORT_SYMBOL(fb_edid_add_monspecs
);
1610 EXPORT_SYMBOL(fb_get_mode
);
1611 EXPORT_SYMBOL(fb_validate_mode
);
1612 EXPORT_SYMBOL(fb_destroy_modedb
);