mbxfb: fix incorrect argument type
[safe/jmp/linux-2.6] / drivers / video / offb.c
index ce5f303..452433d 100644 (file)
@@ -62,8 +62,6 @@ struct offb_par default_par;
      *  Interface used by the world
      */
 
-int offb_init(void);
-
 static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
                          u_int transp, struct fb_info *info);
 static int offb_blank(int blank, struct fb_info *info);
@@ -72,11 +70,6 @@ static int offb_blank(int blank, struct fb_info *info);
 extern boot_infos_t *boot_infos;
 #endif
 
-static void offb_init_nodriver(struct device_node *);
-static void offb_init_fb(const char *name, const char *full_name,
-                        int width, int height, int depth, int pitch,
-                        unsigned long address, struct device_node *dp);
-
 static struct fb_ops offb_ops = {
        .owner          = THIS_MODULE,
        .fb_setcolreg   = offb_setcolreg,
@@ -164,7 +157,7 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
                out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
                break;
        case cmap_gxt2000:
-               out_le32((unsigned __iomem *) par->cmap_adr + regno,
+               out_le32(((unsigned __iomem *) par->cmap_adr) + regno,
                         (red << 16 | green << 8 | blue));
                break;
        }
@@ -220,7 +213,7 @@ static int offb_blank(int blank, struct fb_info *info)
                                out_le32(par->cmap_adr + 0xb4, 0);
                                break;
                        case cmap_gxt2000:
-                               out_le32((unsigned __iomem *) par->cmap_adr + i,
+                               out_le32(((unsigned __iomem *) par->cmap_adr) + i,
                                         0);
                                break;
                        }
@@ -229,123 +222,27 @@ static int offb_blank(int blank, struct fb_info *info)
        return 0;
 }
 
-    /*
-     *  Initialisation
-     */
 
-int __init offb_init(void)
+static void __iomem *offb_map_reg(struct device_node *np, int index,
+                                 unsigned long offset, unsigned long size)
 {
-       struct device_node *dp = NULL, *boot_disp = NULL;
-
-       if (fb_get_options("offb", NULL))
-               return -ENODEV;
-
-       for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
-               if (get_property(dp, "linux,opened", NULL) &&
-                   get_property(dp, "linux,boot-display", NULL)) {
-                       boot_disp = dp;
-                       offb_init_nodriver(dp);
-               }
-       }
-       for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
-               if (get_property(dp, "linux,opened", NULL) &&
-                   dp != boot_disp)
-                       offb_init_nodriver(dp);
-       }
-
-       return 0;
-}
-
-
-static void __init offb_init_nodriver(struct device_node *dp)
-{
-       unsigned int len;
-       int i, width = 640, height = 480, depth = 8, pitch = 640;
-       unsigned int flags, rsize, addr_prop = 0;
-       unsigned long max_size = 0;
-       u64 rstart, address = OF_BAD_ADDR;
-       u32 *pp, *addrp, *up;
-       u64 asize;
-
-       pp = (u32 *)get_property(dp, "linux,bootx-depth", &len);
-       if (pp == NULL)
-               pp = (u32 *)get_property(dp, "depth", &len);
-       if (pp && len == sizeof(u32))
-               depth = *pp;
-
-       pp = (u32 *)get_property(dp, "linux,bootx-width", &len);
-       if (pp == NULL)
-               pp = (u32 *)get_property(dp, "width", &len);
-       if (pp && len == sizeof(u32))
-               width = *pp;
-
-       pp = (u32 *)get_property(dp, "linux,bootx-height", &len);
-       if (pp == NULL)
-               pp = (u32 *)get_property(dp, "height", &len);
-       if (pp && len == sizeof(u32))
-               height = *pp;
-
-       pp = (u32 *)get_property(dp, "linux,bootx-linebytes", &len);
-       if (pp == NULL)
-               pp = (u32 *)get_property(dp, "linebytes", &len);
-       if (pp && len == sizeof(u32))
-               pitch = *pp;
-       else
-               pitch = width * ((depth + 7) / 8);
-
-       rsize = (unsigned long)pitch * (unsigned long)height;
-
-       /* 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 = (u32 *)get_property(dp, "linux,bootx-addr", &len);
-       if (up == NULL)
-               up = (u32 *)get_property(dp, "address", &len);
-       if (up && len == sizeof(u32))
-               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 + asize) >= (addr_prop + rsize)))
-                       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 = (u64)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);
-       }
+       const u32 *addrp;
+       u64 asize, taddr;
+       unsigned int flags;
+
+       addrp = of_get_pci_address(np, index, &asize, &flags);
+       if (addrp == NULL)
+               addrp = of_get_address(np, index, &asize, &flags);
+       if (addrp == NULL)
+               return NULL;
+       if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
+               return NULL;
+       if ((offset + size) > asize)
+               return NULL;
+       taddr = of_translate_address(np, addrp);
+       if (taddr == OF_BAD_ADDR)
+               return NULL;
+       return ioremap(taddr + offset, size);
 }
 
 static void __init offb_init_fb(const char *name, const char *full_name,
@@ -374,7 +271,7 @@ static void __init offb_init_fb(const char *name, const char *full_name,
                return;
        }
 
-       size = sizeof(struct fb_info) + sizeof(u32) * 17;
+       size = sizeof(struct fb_info) + sizeof(u32) * 16;
 
        info = kmalloc(size, GFP_ATOMIC);
        
@@ -402,45 +299,39 @@ static void __init offb_init_fb(const char *name, const char *full_name,
 
        par->cmap_type = cmap_unknown;
        if (depth == 8) {
-
-               /* 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);
-                       par->cmap_type = cmap_r128;
+                       par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
+                       if (par->cmap_adr)
+                               par->cmap_type = cmap_r128;
                } else if (dp && (!strncmp(name, "ATY,RageM3pA", 12)
                                  || !strncmp(name, "ATY,RageM3p12A", 14))) {
-                       unsigned long regbase =
-                           dp->parent->addrs[2].address;
-                       par->cmap_adr = ioremap(regbase, 0x1FFF);
-                       par->cmap_type = cmap_M3A;
+                       par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
+                       if (par->cmap_adr)
+                               par->cmap_type = cmap_M3A;
                } else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) {
-                       unsigned long regbase =
-                           dp->parent->addrs[2].address;
-                       par->cmap_adr = ioremap(regbase, 0x1FFF);
-                       par->cmap_type = cmap_M3B;
+                       par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
+                       if (par->cmap_adr)
+                               par->cmap_type = cmap_M3B;
                } else if (dp && !strncmp(name, "ATY,Rage6", 9)) {
-                       unsigned long regbase = dp->addrs[1].address;
-                       par->cmap_adr = ioremap(regbase, 0x1FFF);
-                       par->cmap_type = cmap_radeon;
+                       par->cmap_adr = offb_map_reg(dp, 1, 0, 0x1fff);
+                       if (par->cmap_adr)
+                               par->cmap_type = cmap_radeon;
                } else if (!strncmp(name, "ATY,", 4)) {
                        unsigned long base = address & 0xff000000UL;
                        par->cmap_adr =
                            ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
                        par->cmap_data = par->cmap_adr + 1;
                        par->cmap_type = cmap_m64;
-               } else if (device_is_compatible(dp, "pci1014,b7")) {
-                       unsigned long regbase = dp->addrs[0].address;
-                       par->cmap_adr = ioremap(regbase + 0x6000, 0x1000);
-                       par->cmap_type = cmap_gxt2000;
+               } else if (dp && (of_device_is_compatible(dp, "pci1014,b7") ||
+                                 of_device_is_compatible(dp, "pci1014,21c"))) {
+                       par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000);
+                       if (par->cmap_adr)
+                               par->cmap_type = cmap_gxt2000;
                }
-#endif
-               fix->visual = par->cmap_adr ? FB_VISUAL_PSEUDOCOLOR
-                   : FB_VISUAL_STATIC_PSEUDOCOLOR;
+               fix->visual = (par->cmap_type != cmap_unknown) ?
+                       FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
        } else
-               fix->visual =   /* par->cmap_adr ? FB_VISUAL_DIRECTCOLOR
-                                  : */ FB_VISUAL_TRUECOLOR;
+               fix->visual = FB_VISUAL_TRUECOLOR;
 
        var->xoffset = var->yoffset = 0;
        switch (depth) {
@@ -511,6 +402,9 @@ static void __init offb_init_fb(const char *name, const char *full_name,
        fb_alloc_cmap(&info->cmap, 256, 0);
 
        if (register_framebuffer(info) < 0) {
+               iounmap(par->cmap_adr);
+               par->cmap_adr = NULL;
+               iounmap(info->screen_base);
                kfree(info);
                release_mem_region(res_start, res_size);
                return;
@@ -520,5 +414,139 @@ static void __init offb_init_fb(const char *name, const char *full_name,
               info->node, full_name);
 }
 
+
+static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
+{
+       unsigned int len;
+       int i, width = 640, height = 480, depth = 8, pitch = 640;
+       unsigned int flags, rsize, addr_prop = 0;
+       unsigned long max_size = 0;
+       u64 rstart, address = OF_BAD_ADDR;
+       const u32 *pp, *addrp, *up;
+       u64 asize;
+
+       pp = of_get_property(dp, "linux,bootx-depth", &len);
+       if (pp == NULL)
+               pp = of_get_property(dp, "depth", &len);
+       if (pp && len == sizeof(u32))
+               depth = *pp;
+
+       pp = of_get_property(dp, "linux,bootx-width", &len);
+       if (pp == NULL)
+               pp = of_get_property(dp, "width", &len);
+       if (pp && len == sizeof(u32))
+               width = *pp;
+
+       pp = of_get_property(dp, "linux,bootx-height", &len);
+       if (pp == NULL)
+               pp = of_get_property(dp, "height", &len);
+       if (pp && len == sizeof(u32))
+               height = *pp;
+
+       pp = of_get_property(dp, "linux,bootx-linebytes", &len);
+       if (pp == NULL)
+               pp = of_get_property(dp, "linebytes", &len);
+       if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
+               pitch = *pp;
+       else
+               pitch = width * ((depth + 7) / 8);
+
+       rsize = (unsigned long)pitch * (unsigned long)height;
+
+       /* 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 = of_get_property(dp, "linux,bootx-addr", &len);
+       if (up == NULL)
+               up = of_get_property(dp, "address", &len);
+       if (up && len == sizeof(u32))
+               addr_prop = *up;
+
+       /* Hack for when BootX is passing us */
+       if (no_real_node)
+               goto skip_addr;
+
+       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 + asize) >= (addr_prop + rsize)))
+                       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;
+       }
+ skip_addr:
+       if (address == OF_BAD_ADDR && addr_prop)
+               address = (u64)addr_prop;
+       if (address != OF_BAD_ADDR) {
+               /* kludge for valkyrie */
+               if (strcmp(dp->name, "valkyrie") == 0)
+                       address += 0x1000;
+               offb_init_fb(no_real_node ? "bootx" : dp->name,
+                            no_real_node ? "display" : dp->full_name,
+                            width, height, depth, pitch, address,
+                            no_real_node ? NULL : dp);
+       }
+}
+
+static int __init offb_init(void)
+{
+       struct device_node *dp = NULL, *boot_disp = NULL;
+
+       if (fb_get_options("offb", NULL))
+               return -ENODEV;
+
+       /* Check if we have a MacOS display without a node spec */
+       if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) {
+               /* The old code tried to work out which node was the MacOS
+                * display based on the address. I'm dropping that since the
+                * lack of a node spec only happens with old BootX versions
+                * (users can update) and with this code, they'll still get
+                * a display (just not the palette hacks).
+                */
+               offb_init_nodriver(of_chosen, 1);
+       }
+
+       for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
+               if (of_get_property(dp, "linux,opened", NULL) &&
+                   of_get_property(dp, "linux,boot-display", NULL)) {
+                       boot_disp = dp;
+                       offb_init_nodriver(dp, 0);
+               }
+       }
+       for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
+               if (of_get_property(dp, "linux,opened", NULL) &&
+                   dp != boot_disp)
+                       offb_init_nodriver(dp, 0);
+       }
+
+       return 0;
+}
+
+
 module_init(offb_init);
 MODULE_LICENSE("GPL");