]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/video/fbmon.c
Merge master.kernel.org:/home/rmk/linux-2.6-mmc
[linux-2.6-omap-h63xx.git] / drivers / video / fbmon.c
index 6cd1976548d4d157ae7d530de585684f6947d3d0..fc7965b66775983a97d62d10ab7805c475e0eb73 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/tty.h>
 #include <linux/fb.h>
 #include <linux/module.h>
+#include <video/edid.h>
 #ifdef CONFIG_PPC_OF
 #include <linux/pci.h>
 #include <asm/prom.h>
@@ -313,11 +314,13 @@ static int edid_is_monitor_block(unsigned char *block)
                return 0;
 }
 
-static void calc_mode_timings(int xres, int yres, int refresh, struct fb_videomode *mode)
+static void calc_mode_timings(int xres, int yres, int refresh,
+                             struct fb_videomode *mode)
 {
        struct fb_var_screeninfo var;
        struct fb_info info;
        
+       memset(&var, 0, sizeof(struct fb_var_screeninfo));
        var.xres = xres;
        var.yres = yres;
        fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON, 
@@ -535,25 +538,12 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
 
        *dbsize = 0;
 
-       DPRINTK("   Supported VESA Modes\n");
-       block = edid + ESTABLISHED_TIMING_1;
-       num += get_est_timing(block, &mode[num]);
-
-       DPRINTK("   Standard Timings\n");
-       block = edid + STD_TIMING_DESCRIPTIONS_START;
-       for (i = 0; i < STD_TIMING; i++, block += STD_TIMING_DESCRIPTION_SIZE) 
-               num += get_std_timing(block, &mode[num]);
-
        DPRINTK("   Detailed Timings\n");
        block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
        for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) {
                int first = 1;
 
-               if (block[0] == 0x00 && block[1] == 0x00) {
-                       if (block[3] == 0xfa) {
-                               num += get_dst_timing(block + 5, &mode[num]);
-                       }
-               } else  {
+               if (!(block[0] == 0x00 && block[1] == 0x00)) {
                        get_detailed_timing(block, &mode[num]);
                        if (first) {
                                mode[num].flag |= FB_MODE_IS_FIRST;
@@ -562,6 +552,21 @@ static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
                        num++;
                }
        }
+
+       DPRINTK("   Supported VESA Modes\n");
+       block = edid + ESTABLISHED_TIMING_1;
+       num += get_est_timing(block, &mode[num]);
+
+       DPRINTK("   Standard Timings\n");
+       block = edid + STD_TIMING_DESCRIPTIONS_START;
+       for (i = 0; i < STD_TIMING; i++, block += STD_TIMING_DESCRIPTION_SIZE)
+               num += get_std_timing(block, &mode[num]);
+
+       block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
+       for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) {
+               if (block[0] == 0x00 && block[1] == 0x00 && block[3] == 0xfa)
+                       num += get_dst_timing(block + 5, &mode[num]);
+       }
        
        /* Yikes, EDID data is totally useless */
        if (!num) {
@@ -824,7 +829,7 @@ int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
 {
        unsigned char *block;
-       int i;
+       int i, found = 0;
 
        if (edid == NULL)
                return;
@@ -866,6 +871,22 @@ void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
        get_monspecs(edid, specs);
 
        specs->modedb = fb_create_modedb(edid, &specs->modedb_len);
+
+       /*
+        * Workaround for buggy EDIDs that sets that the first
+        * detailed timing is preferred but has not detailed
+        * timing specified
+        */
+       for (i = 0; i < specs->modedb_len; i++) {
+               if (specs->modedb[i].flag & FB_MODE_IS_DETAILED) {
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (!found)
+               specs->misc &= ~FB_MISC_1ST_DETAIL;
+
        DPRINTK("========================================\n");
 }
 
@@ -1241,6 +1262,8 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
                vtotal *= 2;
 
        hfreq = pixclock/htotal;
+       hfreq = (hfreq + 500) / 1000 * 1000;
+
        vfreq = hfreq/vtotal;
 
        return (vfreq < vfmin || vfreq > vfmax || 
@@ -1249,9 +1272,41 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
                -EINVAL : 0;
 }
 
+#if defined(__i386__)
+#include <linux/pci.h>
+
+/*
+ * We need to ensure that the EDID block is only returned for
+ * the primary graphics adapter.
+ */
+
+const unsigned char *fb_firmware_edid(struct device *device)
+{
+       struct pci_dev *dev = NULL;
+       struct resource *res = NULL;
+       unsigned char *edid = NULL;
+
+       if (device)
+               dev = to_pci_dev(device);
+
+       if (dev)
+               res = &dev->resource[PCI_ROM_RESOURCE];
+
+       if (res && res->flags & IORESOURCE_ROM_SHADOW)
+               edid = edid_info.dummy;
+
+       return edid;
+}
+#else
+const unsigned char *fb_firmware_edid(struct device *device)
+{
+       return NULL;
+}
+#endif /* _i386_ */
+
 EXPORT_SYMBOL(fb_parse_edid);
 EXPORT_SYMBOL(fb_edid_to_monspecs);
-
+EXPORT_SYMBOL(fb_firmware_edid);
 EXPORT_SYMBOL(fb_get_mode);
 EXPORT_SYMBOL(fb_validate_mode);
 EXPORT_SYMBOL(fb_destroy_modedb);