X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fvideo%2Foffb.c;h=a57455ee0c152160c7ea526e020060881266ed1e;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=e1715ef972b82d281b44b99a8d39634c2f2a11ef;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/drivers/video/offb.c b/drivers/video/offb.c index e1715ef97..a57455ee0 100644 --- a/drivers/video/offb.c +++ b/drivers/video/offb.c @@ -26,9 +26,15 @@ #include #include #include +#include #include #include -#ifdef CONFIG_BOOTX_TEXT + +#ifdef CONFIG_PPC64 +#include +#endif + +#ifdef CONFIG_PPC32 #include #endif @@ -46,20 +52,14 @@ enum { }; struct offb_par { - volatile unsigned char *cmap_adr; - volatile unsigned char *cmap_data; + volatile void __iomem *cmap_adr; + volatile void __iomem *cmap_data; int cmap_type; int blanked; }; struct offb_par default_par; -#ifdef __powerpc__ -#define mach_eieio() eieio() -#else -#define mach_eieio() do {} while (0) -#endif - /* * Interface used by the world */ @@ -70,7 +70,7 @@ 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); -#ifdef CONFIG_BOOTX_TEXT +#ifdef CONFIG_PPC32 extern boot_infos_t *boot_infos; #endif @@ -86,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, }; /* @@ -109,44 +108,36 @@ static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, switch (par->cmap_type) { case cmap_m64: - *par->cmap_adr = regno; - mach_eieio(); - *par->cmap_data = red; - mach_eieio(); - *par->cmap_data = green; - mach_eieio(); - *par->cmap_data = blue; - mach_eieio(); + writeb(regno, par->cmap_adr); + writeb(red, par->cmap_data); + writeb(green, par->cmap_data); + writeb(blue, par->cmap_data); break; case cmap_M3A: /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */ - out_le32((unsigned *) (par->cmap_adr + 0x58), - in_le32((unsigned *) (par->cmap_adr + - 0x58)) & ~0x20); + out_le32(par->cmap_adr + 0x58, + in_le32(par->cmap_adr + 0x58) & ~0x20); case cmap_r128: /* Set palette index & data */ out_8(par->cmap_adr + 0xb0, regno); - out_le32((unsigned *) (par->cmap_adr + 0xb4), + out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue)); break; case cmap_M3B: /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */ - out_le32((unsigned *) (par->cmap_adr + 0x58), - in_le32((unsigned *) (par->cmap_adr + - 0x58)) | 0x20); + out_le32(par->cmap_adr + 0x58, + in_le32(par->cmap_adr + 0x58) | 0x20); /* Set palette index & data */ out_8(par->cmap_adr + 0xb0, regno); - out_le32((unsigned *) (par->cmap_adr + 0xb4), - (red << 16 | green << 8 | blue)); + out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue)); break; case cmap_radeon: /* Set palette index & data (could be smarter) */ out_8(par->cmap_adr + 0xb0, regno); - out_le32((unsigned *) (par->cmap_adr + 0xb4), - (red << 16 | green << 8 | blue)); + out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue)); break; case cmap_gxt2000: - out_le32((unsigned *) par->cmap_adr + regno, + out_le32((unsigned __iomem *) par->cmap_adr + regno, (red << 16 | green << 8 | blue)); break; } @@ -190,52 +181,38 @@ static int offb_blank(int blank, struct fb_info *info) for (i = 0; i < 256; i++) { switch (par->cmap_type) { case cmap_m64: - *par->cmap_adr = i; - mach_eieio(); - for (j = 0; j < 3; j++) { - *par->cmap_data = 0; - mach_eieio(); - } + writeb(i, par->cmap_adr); + for (j = 0; j < 3; j++) + writeb(0, par->cmap_data); break; case cmap_M3A: /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */ - out_le32((unsigned *) (par->cmap_adr + - 0x58), - in_le32((unsigned *) (par-> - cmap_adr + - 0x58)) & - ~0x20); + out_le32(par->cmap_adr + 0x58, + in_le32(par->cmap_adr + 0x58) & ~0x20); case cmap_r128: /* Set palette index & data */ out_8(par->cmap_adr + 0xb0, i); - out_le32((unsigned *) (par->cmap_adr + - 0xb4), 0); + out_le32(par->cmap_adr + 0xb4, 0); break; case cmap_M3B: /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */ - out_le32((unsigned *) (par->cmap_adr + - 0x58), - in_le32((unsigned *) (par-> - cmap_adr + - 0x58)) | - 0x20); + out_le32(par->cmap_adr + 0x58, + in_le32(par->cmap_adr + 0x58) | 0x20); /* Set palette index & data */ out_8(par->cmap_adr + 0xb0, i); - out_le32((unsigned *) (par->cmap_adr + - 0xb4), 0); + out_le32(par->cmap_adr + 0xb4, 0); break; case cmap_radeon: out_8(par->cmap_adr + 0xb0, i); - out_le32((unsigned *) (par->cmap_adr + - 0xb4), 0); + out_le32(par->cmap_adr + 0xb4, 0); break; case cmap_gxt2000: - out_le32((unsigned *) par->cmap_adr + i, + out_le32((unsigned __iomem *) par->cmap_adr + i, 0); break; } } else - fb_set_cmap(&info->cmap, 1, info); + fb_set_cmap(&info->cmap, info); return 0; } @@ -245,70 +222,67 @@ static int offb_blank(int blank, struct fb_info *info) int __init offb_init(void) { - struct device_node *dp; - unsigned int dpy; + struct device_node *dp = NULL, *boot_disp = NULL; + #if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32) - struct device_node *displays = find_type_devices("display"); struct device_node *macos_display = NULL; +#endif + if (fb_get_options("offb", NULL)) + return -ENODEV; +#if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32) /* If we're booted from BootX... */ - if (prom_num_displays == 0 && boot_infos != 0) { + 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 */ - for (dp = displays; dp != NULL; dp = dp->next) { + 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; } } @@ -325,10 +299,19 @@ int __init offb_init(void) } #endif /* defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32) */ - for (dpy = 0; dpy < prom_num_displays; dpy++) { - if ((dp = find_path_device(prom_display_paths[dpy]))) + 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; } @@ -338,7 +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, 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)) @@ -356,30 +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; + 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, @@ -436,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); @@ -467,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 @@ -527,7 +545,7 @@ static void __init offb_init_fb(const char *name, const char *full_name, info->screen_base = ioremap(address, fix->smem_len); info->par = par; info->pseudo_palette = (void *) (info + 1); - info->flags = FBINFO_FLAG_DEFAULT; + info->flags = FBINFO_DEFAULT; fb_alloc_cmap(&info->cmap, 256, 0); @@ -541,4 +559,5 @@ static void __init offb_init_fb(const char *name, const char *full_name, info->node, full_name); } +module_init(offb_init); MODULE_LICENSE("GPL");