Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / video / offb.c
index 42a6591..a57455e 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/fb.h>
 #include <linux/init.h>
 #include <linux/ioport.h>
+#include <linux/pci.h>
 #include <asm/io.h>
 #include <asm/prom.h>
 
@@ -85,7 +86,6 @@ static struct fb_ops offb_ops = {
        .fb_fillrect    = cfb_fillrect,
        .fb_copyarea    = cfb_copyarea,
        .fb_imageblit   = cfb_imageblit,
-       .fb_cursor      = soft_cursor,
 };
 
     /*
@@ -223,6 +223,7 @@ static int offb_blank(int blank, struct fb_info *info)
 int __init offb_init(void)
 {
        struct device_node *dp = NULL, *boot_disp = NULL;
+
 #if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
        struct device_node *macos_display = NULL;
 #endif
@@ -234,60 +235,54 @@ int __init offb_init(void)
        if (boot_infos != 0) {
                unsigned long addr =
                    (unsigned long) boot_infos->dispDeviceBase;
+               u32 *addrp;
+               u64 daddr, dsize;
+               unsigned int flags;
+
                /* find the device node corresponding to the macos display */
                while ((dp = of_find_node_by_type(dp, "display"))) {
                        int i;
-                       /*
-                        * Grrr...  It looks like the MacOS ATI driver
-                        * munges the assigned-addresses property (but
-                        * the AAPL,address value is OK).
-                        */
-                       if (strncmp(dp->name, "ATY,", 4) == 0
-                           && dp->n_addrs == 1) {
-                               unsigned int *ap =
-                                   (unsigned int *) get_property(dp,
-                                                                 "AAPL,address",
-                                                                 NULL);
-                               if (ap != NULL) {
-                                       dp->addrs[0].address = *ap;
-                                       dp->addrs[0].size = 0x01000000;
-                               }
-                       }
 
                        /*
-                        * The LTPro on the Lombard powerbook has no addresses
-                        * on the display nodes, they are on their parent.
+                        * Look for an AAPL,address property first.
                         */
-                       if (dp->n_addrs == 0
-                           && device_is_compatible(dp, "ATY,264LTPro")) {
-                               int na;
-                               unsigned int *ap = (unsigned int *)
-                                   get_property(dp, "AAPL,address", &na);
-                               if (ap != 0)
-                                       for (na /= sizeof(unsigned int);
-                                            na > 0; --na, ++ap)
-                                               if (*ap <= addr
-                                                   && addr <
-                                                   *ap + 0x1000000)
-                                                       goto foundit;
+                       unsigned int na;
+                       unsigned int *ap =
+                               (unsigned int *)get_property(dp, "AAPL,address",
+                                                            &na);
+                       if (ap != 0) {
+                               for (na /= sizeof(unsigned int); na > 0;
+                                    --na, ++ap)
+                                       if (*ap <= addr &&
+                                           addr < *ap + 0x1000000) {
+                                               macos_display = dp;
+                                               goto foundit;
+                                       }
                        }
 
                        /*
                         * See if the display address is in one of the address
                         * ranges for this display.
                         */
-                       for (i = 0; i < dp->n_addrs; ++i) {
-                               if (dp->addrs[i].address <= addr
-                                   && addr <
-                                   dp->addrs[i].address +
-                                   dp->addrs[i].size)
+                       i = 0;
+                       for (;;) {
+                               addrp = of_get_address(dp, i++, &dsize, &flags);
+                               if (addrp == NULL)
                                        break;
+                               if (!(flags & IORESOURCE_MEM))
+                                       continue;
+                               daddr = of_translate_address(dp, addrp);
+                               if (daddr == OF_BAD_ADDR)
+                                       continue;
+                               if (daddr <= addr && addr < (daddr + dsize)) {
+                                       macos_display = dp;
+                                       goto foundit;
+                               }
                        }
-                       if (i < dp->n_addrs) {
-                             foundit:
+               foundit:
+                       if (macos_display) {
                                printk(KERN_INFO "MacOS display is %s\n",
                                       dp->full_name);
-                               macos_display = dp;
                                break;
                        }
                }
@@ -326,8 +321,11 @@ static void __init offb_init_nodriver(struct device_node *dp)
        int *pp, i;
        unsigned int len;
        int width = 640, height = 480, depth = 8, pitch;
-       unsigned *up;
-       unsigned long address;
+       unsigned  flags, rsize, *up, addr_prop = 0;
+       unsigned long max_size = 0;
+       u64 rstart, address = OF_BAD_ADDR;
+       u32 *addrp;
+       u64 asize;
 
        if ((pp = (int *) get_property(dp, "depth", &len)) != NULL
            && len == sizeof(int))
@@ -345,34 +343,58 @@ static void __init offb_init_nodriver(struct device_node *dp)
                        pitch = 0x1000;
        } else
                pitch = width;
-       if ((up = (unsigned *) get_property(dp, "address", &len)) != NULL
-           && len == sizeof(unsigned))
-               address = (u_long) * up;
-       else {
-               for (i = 0; i < dp->n_addrs; ++i)
-                       if (dp->addrs[i].size >=
-                           pitch * height * depth / 8)
-                               break;
-               if (i >= dp->n_addrs) {
-                       printk(KERN_ERR
-                              "no framebuffer address found for %s\n",
-                              dp->full_name);
-                       return;
-               }
-
-               address = (u_long) dp->addrs[i].address;
-
-#ifdef CONFIG_PPC64
-               address += dp->phb->pci_mem_offset;
-#endif
 
+       rsize = (unsigned long)pitch * (unsigned long)height *
+               (unsigned long)(depth / 8);
+
+       /* Ok, now we try to figure out the address of the framebuffer.
+        *
+        * Unfortunately, Open Firmware doesn't provide a standard way to do
+        * so. All we can do is a dodgy heuristic that happens to work in
+        * practice. On most machines, the "address" property contains what
+        * we need, though not on Matrox cards found in IBM machines. What I've
+        * found that appears to give good results is to go through the PCI
+        * ranges and pick one that is both big enough and if possible encloses
+        * the "address" property. If none match, we pick the biggest
+        */
+       up = (unsigned int *) get_property(dp, "address", &len);
+       if (up && len == sizeof(unsigned int))
+               addr_prop = *up;
+
+       for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags))
+                    != NULL; i++) {
+               int match_addrp = 0;
+
+               if (!(flags & IORESOURCE_MEM))
+                       continue;
+               if (asize < rsize)
+                       continue;
+               rstart = of_translate_address(dp, addrp);
+               if (rstart == OF_BAD_ADDR)
+                       continue;
+               if (addr_prop && (rstart <= addr_prop) &&
+                   ((rstart + rsize) > addr_prop))
+                       match_addrp = 1;
+               if (match_addrp) {
+                       address = addr_prop;
+                       break;
+               }
+               if (rsize > max_size) {
+                       max_size = rsize;
+                       address = OF_BAD_ADDR;
+               }
+               if (address == OF_BAD_ADDR)
+                       address = rstart;
+       }
+       if (address == OF_BAD_ADDR && addr_prop)
+               address = (u_long)addr_prop;
+       if (address != OF_BAD_ADDR) {
                /* kludge for valkyrie */
                if (strcmp(dp->name, "valkyrie") == 0)
                        address += 0x1000;
+               offb_init_fb(dp->name, dp->full_name, width, height, depth,
+                            pitch, address, dp);
        }
-       offb_init_fb(dp->name, dp->full_name, width, height, depth,
-                    pitch, address, dp);
-
 }
 
 static void __init offb_init_fb(const char *name, const char *full_name,
@@ -429,7 +451,9 @@ static void __init offb_init_fb(const char *name, const char *full_name,
 
        par->cmap_type = cmap_unknown;
        if (depth == 8) {
-               /* XXX kludge for ati */
+
+               /* Palette hacks disabled for now */
+#if 0
                if (dp && !strncmp(name, "ATY,Rage128", 11)) {
                        unsigned long regbase = dp->addrs[2].address;
                        par->cmap_adr = ioremap(regbase, 0x1FFF);
@@ -460,6 +484,7 @@ static void __init offb_init_fb(const char *name, const char *full_name,
                        par->cmap_adr = ioremap(regbase + 0x6000, 0x1000);
                        par->cmap_type = cmap_gxt2000;
                }
+#endif
                fix->visual = par->cmap_adr ? FB_VISUAL_PSEUDOCOLOR
                    : FB_VISUAL_STATIC_PSEUDOCOLOR;
        } else