x86, mce: implement panic synchronization
[safe/jmp/linux-2.6] / drivers / video / macfb.c
index e6cbd9d..d66887e 100644 (file)
 
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/mm.h>
-#include <linux/tty.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/nubus.h>
@@ -38,7 +36,6 @@
 #include <asm/irq.h>
 #include <asm/macintosh.h>
 #include <asm/io.h>
-#include <asm/machw.h>
 
 /* Common DAC base address for the LC, RBV, Valkyrie, and IIvx */
 #define DAC_BASE 0x50f24000
@@ -80,34 +77,34 @@ static int csc_setpalette (unsigned int regno, unsigned int red,
                           unsigned int green, unsigned int blue,
                           struct fb_info *fb_info);
 
-static volatile struct {
+static struct {
        unsigned char addr;
        /* Note: word-aligned */
        char pad[3];
        unsigned char lut;
-} *valkyrie_cmap_regs;
+} __iomem *valkyrie_cmap_regs;
 
-static volatile struct {
+static struct {
        unsigned char addr;
        unsigned char lut;
-} *v8_brazil_cmap_regs;
+} __iomem *v8_brazil_cmap_regs;
 
-static volatile struct {
+static struct {
        unsigned char addr;
        char pad1[3]; /* word aligned */
        unsigned char lut;
        char pad2[3]; /* word aligned */
        unsigned char cntl; /* a guess as to purpose */
-} *rbv_cmap_regs;
+} __iomem *rbv_cmap_regs;
 
-static volatile struct {
+static struct {
        unsigned long reset;
        unsigned long pad1[3];
        unsigned char pad2[3];
        unsigned char lut;
-} *dafb_cmap_regs;
+} __iomem *dafb_cmap_regs;
 
-static volatile struct {
+static struct {
        unsigned char addr;     /* OFFSET: 0x00 */
        unsigned char pad1[15];
        unsigned char lut;      /* OFFSET: 0x10 */
@@ -116,16 +113,16 @@ static volatile struct {
        unsigned char pad3[7];
        unsigned long vbl_addr; /* OFFSET: 0x28 */
        unsigned int  status2;  /* OFFSET: 0x2C */
-} *civic_cmap_regs;
+} __iomem *civic_cmap_regs;
 
-static volatile struct {
+static struct {
        char    pad1[0x40];
         unsigned char  clut_waddr;     /* 0x40 */
         char    pad2;
         unsigned char  clut_data;      /* 0x42 */
         char   pad3[0x3];
         unsigned char  clut_raddr;     /* 0x46 */
-} *csc_cmap_regs;
+} __iomem *csc_cmap_regs;
 
 /* We will leave these the way they are for the time being */
 struct mdc_cmap_regs {
@@ -166,13 +163,12 @@ static struct fb_var_screeninfo macfb_defined = {
 };
 
 static struct fb_fix_screeninfo macfb_fix = {
-       .id     = "Macintosh ",
        .type   = FB_TYPE_PACKED_PIXELS,
        .accel  = FB_ACCEL_NONE,
 };
 
 static struct fb_info fb_info;
-static u32 pseudo_palette[17];
+static u32 pseudo_palette[16];
 static int inverse   = 0;
 static int vidtest   = 0;
 
@@ -510,10 +506,10 @@ static int csc_setpalette (unsigned int regno, unsigned int red,
                           struct fb_info *info)
 {
        mdelay(1);
-       csc_cmap_regs->clut_waddr = regno;
-       csc_cmap_regs->clut_data = red;
-       csc_cmap_regs->clut_data = green;
-       csc_cmap_regs->clut_data = blue;
+       nubus_writeb(regno, &csc_cmap_regs->clut_waddr);
+       nubus_writeb(red,   &csc_cmap_regs->clut_data);
+       nubus_writeb(green, &csc_cmap_regs->clut_data);
+       nubus_writeb(blue,  &csc_cmap_regs->clut_data);
        return 0;
 }
 
@@ -531,56 +527,63 @@ static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
        if (regno >= fb_info->cmap.len)
                return 1;
 
-       switch (fb_info->var.bits_per_pixel) {
-       case 1:
-               /* We shouldn't get here */
-               break;
-       case 2:
-       case 4:
-       case 8:
-               if (macfb_setpalette)
-                       macfb_setpalette(regno, red, green, blue, fb_info);
-               else
-                       return 1;
-               break;
-       case 16:
-               if (fb_info->var.red.offset == 10) {
-                       /* 1:5:5:5 */
-                       ((u32*) (fb_info->pseudo_palette))[regno] =
+       if (fb_info->var.bits_per_pixel <= 8) {
+               switch (fb_info->var.bits_per_pixel) {
+               case 1:
+                       /* We shouldn't get here */
+                       break;
+               case 2:
+               case 4:
+               case 8:
+                       if (macfb_setpalette)
+                               macfb_setpalette(regno, red, green, blue,
+                                                fb_info);
+                       else
+                               return 1;
+                       break;
+               }
+       } else if (regno < 16) {
+               switch (fb_info->var.bits_per_pixel) {
+               case 16:
+                       if (fb_info->var.red.offset == 10) {
+                               /* 1:5:5:5 */
+                               ((u32*) (fb_info->pseudo_palette))[regno] =
                                        ((red   & 0xf800) >>  1) |
                                        ((green & 0xf800) >>  6) |
                                        ((blue  & 0xf800) >> 11) |
                                        ((transp != 0) << 15);
-               } else {
-                       /* 0:5:6:5 */
-                       ((u32*) (fb_info->pseudo_palette))[regno] =
+                       } else {
+                               /* 0:5:6:5 */
+                               ((u32*) (fb_info->pseudo_palette))[regno] =
                                        ((red   & 0xf800)      ) |
                                        ((green & 0xfc00) >>  5) |
                                        ((blue  & 0xf800) >> 11);
+                       }
+                       break;
+                       /* I'm pretty sure that one or the other of these
+                          doesn't exist on 68k Macs */
+               case 24:
+                       red   >>= 8;
+                       green >>= 8;
+                       blue  >>= 8;
+                       ((u32 *)(fb_info->pseudo_palette))[regno] =
+                               (red   << fb_info->var.red.offset)   |
+                               (green << fb_info->var.green.offset) |
+                               (blue  << fb_info->var.blue.offset);
+                       break;
+               case 32:
+                       red   >>= 8;
+                       green >>= 8;
+                       blue  >>= 8;
+                       ((u32 *)(fb_info->pseudo_palette))[regno] =
+                               (red   << fb_info->var.red.offset)   |
+                               (green << fb_info->var.green.offset) |
+                               (blue  << fb_info->var.blue.offset);
+                       break;
                }
-               break;  
-               /* I'm pretty sure that one or the other of these
-                  doesn't exist on 68k Macs */
-       case 24:
-               red   >>= 8;
-               green >>= 8;
-               blue  >>= 8;
-               ((u32 *)(fb_info->pseudo_palette))[regno] =
-                       (red   << fb_info->var.red.offset)   |
-                       (green << fb_info->var.green.offset) |
-                       (blue  << fb_info->var.blue.offset);
-               break;
-       case 32:
-               red   >>= 8;
-               green >>= 8;
-               blue  >>= 8;
-               ((u32 *)(fb_info->pseudo_palette))[regno] =
-                       (red   << fb_info->var.red.offset)   |
-                       (green << fb_info->var.green.offset) |
-                       (blue  << fb_info->var.blue.offset);
-               break;
-    }
-    return 0;
+       }
+
+       return 0;
 }
 
 static struct fb_ops macfb_ops = {
@@ -591,7 +594,7 @@ static struct fb_ops macfb_ops = {
        .fb_imageblit   = cfb_imageblit,
 };
 
-void __init macfb_setup(char *options)
+static void __init macfb_setup(char *options)
 {
        char *this_opt;
        
@@ -609,6 +612,22 @@ void __init macfb_setup(char *options)
        }
 }
 
+static void __init iounmap_macfb(void)
+{
+       if (valkyrie_cmap_regs)
+               iounmap(valkyrie_cmap_regs);
+       if (dafb_cmap_regs)
+               iounmap(dafb_cmap_regs);
+       if (v8_brazil_cmap_regs)
+               iounmap(v8_brazil_cmap_regs);
+       if (rbv_cmap_regs)
+               iounmap(rbv_cmap_regs);
+       if (civic_cmap_regs)
+               iounmap(civic_cmap_regs);
+       if (csc_cmap_regs)
+               iounmap(csc_cmap_regs);
+}
+
 static int __init macfb_init(void)
 {
        int video_cmap_len, video_is_nubus = 0;
@@ -739,22 +758,22 @@ static int __init macfb_init(void)
 
                switch(ndev->dr_hw) {
                case NUBUS_DRHW_APPLE_MDC:
-                       strcat( macfb_fix.id, "Display Card" );
+                       strcpy(macfb_fix.id, "Mac Disp. Card");
                        macfb_setpalette = mdc_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
                        break;
                case NUBUS_DRHW_APPLE_TFB:
-                       strcat( macfb_fix.id, "Toby" );
+                       strcpy(macfb_fix.id, "Toby");
                        macfb_setpalette = toby_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
                        break;
                case NUBUS_DRHW_APPLE_JET:
-                       strcat( macfb_fix.id, "Jet");
+                       strcpy(macfb_fix.id, "Jet");
                        macfb_setpalette = jet_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
                        break;                  
                default:
-                       strcat( macfb_fix.id, "Generic NuBus" );
+                       strcpy(macfb_fix.id, "Generic NuBus");
                        break;
                }
        }
@@ -765,21 +784,11 @@ static int __init macfb_init(void)
        if (!video_is_nubus)
                switch( mac_bi_data.id )
                {
-                       /* These don't have onboard video.  Eventually, we may
-                          be able to write separate framebuffer drivers for
-                          them (tobyfb.c, hiresfb.c, etc, etc) */
-               case MAC_MODEL_II:
-               case MAC_MODEL_IIX:
-               case MAC_MODEL_IICX:
-               case MAC_MODEL_IIFX:
-                       strcat( macfb_fix.id, "Generic NuBus" );
-                       break;
-
                        /* Valkyrie Quadras */
                case MAC_MODEL_Q630:
                        /* I'm not sure about this one */
                case MAC_MODEL_P588:
-                       strcat( macfb_fix.id, "Valkyrie built-in" );
+                       strcpy(macfb_fix.id, "Valkyrie");
                        macfb_setpalette = valkyrie_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
                        valkyrie_cmap_regs = ioremap(DAC_BASE, 0x1000);
@@ -802,7 +811,7 @@ static int __init macfb_init(void)
                case MAC_MODEL_Q700:
                case MAC_MODEL_Q900:
                case MAC_MODEL_Q950:
-                       strcat( macfb_fix.id, "DAFB built-in" );
+                       strcpy(macfb_fix.id, "DAFB");
                        macfb_setpalette = dafb_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
                        dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);
@@ -810,7 +819,7 @@ static int __init macfb_init(void)
 
                        /* LC II uses the V8 framebuffer */
                case MAC_MODEL_LCII:
-                       strcat( macfb_fix.id, "V8 built-in" );
+                       strcpy(macfb_fix.id, "V8");
                        macfb_setpalette = v8_brazil_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
                        v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
@@ -822,7 +831,7 @@ static int __init macfb_init(void)
                case MAC_MODEL_IIVI:
                case MAC_MODEL_IIVX:
                case MAC_MODEL_P600:
-                       strcat( macfb_fix.id, "Brazil built-in" );
+                       strcpy(macfb_fix.id, "Brazil");
                        macfb_setpalette = v8_brazil_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
                        v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
@@ -839,7 +848,7 @@ static int __init macfb_init(void)
                case MAC_MODEL_P460:
                        macfb_setpalette = v8_brazil_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
-                       strcat( macfb_fix.id, "Sonora built-in" );
+                       strcpy(macfb_fix.id, "Sonora");
                        v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
                        break;
 
@@ -850,7 +859,7 @@ static int __init macfb_init(void)
                case MAC_MODEL_IISI:
                        macfb_setpalette = rbv_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
-                       strcat( macfb_fix.id, "RBV built-in" );
+                       strcpy(macfb_fix.id, "RBV");
                        rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);
                        break;
 
@@ -859,7 +868,7 @@ static int __init macfb_init(void)
                case MAC_MODEL_C660:
                        macfb_setpalette = civic_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
-                       strcat( macfb_fix.id, "Civic built-in" );
+                       strcpy(macfb_fix.id, "Civic");
                        civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
                        break;
 
@@ -880,7 +889,7 @@ static int __init macfb_init(void)
                                v8_brazil_cmap_regs =
                                        ioremap(DAC_BASE, 0x1000);
                        }
-                       strcat( macfb_fix.id, "LC built-in" );
+                       strcpy(macfb_fix.id, "LC");
                        break;
                        /* We think this may be like the LC II */
                case MAC_MODEL_CCL:
@@ -890,18 +899,18 @@ static int __init macfb_init(void)
                                v8_brazil_cmap_regs =
                                        ioremap(DAC_BASE, 0x1000);
                        }
-                       strcat( macfb_fix.id, "Color Classic built-in" );
+                       strcpy(macfb_fix.id, "Color Classic");
                        break;
 
                        /* And we *do* mean "weirdos" */
                case MAC_MODEL_TV:
-                       strcat( macfb_fix.id, "Mac TV built-in" );
+                       strcpy(macfb_fix.id, "Mac TV");
                        break;
 
                        /* These don't have colour, so no need to worry */
                case MAC_MODEL_SE30:
                case MAC_MODEL_CLII:
-                       strcat( macfb_fix.id, "Monochrome built-in" );
+                       strcpy(macfb_fix.id, "Monochrome");
                        break;
 
                        /* Powerbooks are particularly difficult.  Many of
@@ -914,7 +923,7 @@ static int __init macfb_init(void)
                case MAC_MODEL_PB140:
                case MAC_MODEL_PB145:
                case MAC_MODEL_PB170:
-                       strcat( macfb_fix.id, "DDC built-in" );
+                       strcpy(macfb_fix.id, "DDC");
                        break;
 
                        /* Internal is GSC, External (if present) is ViSC */
@@ -924,13 +933,13 @@ static int __init macfb_init(void)
                case MAC_MODEL_PB180:
                case MAC_MODEL_PB210:
                case MAC_MODEL_PB230:
-                       strcat( macfb_fix.id, "GSC built-in" );
+                       strcpy(macfb_fix.id, "GSC");
                        break;
 
                        /* Internal is TIM, External is ViSC */
                case MAC_MODEL_PB165C:
                case MAC_MODEL_PB180C:
-                       strcat( macfb_fix.id, "TIM built-in" );
+                       strcpy(macfb_fix.id, "TIM");
                        break;
 
                        /* Internal is CSC, External is Keystone+Ariel. */
@@ -942,12 +951,12 @@ static int __init macfb_init(void)
                case MAC_MODEL_PB280C:
                        macfb_setpalette = csc_setpalette;
                        macfb_defined.activate = FB_ACTIVATE_NOW;
-                       strcat( macfb_fix.id, "CSC built-in" );
+                       strcpy(macfb_fix.id, "CSC");
                        csc_cmap_regs = ioremap(CSC_BASE, 0x1000);
                        break;
                
                default:
-                       strcat( macfb_fix.id, "Unknown/Unsupported built-in" );
+                       strcpy(macfb_fix.id, "Unknown");
                        break;
                }
 
@@ -957,12 +966,23 @@ static int __init macfb_init(void)
        fb_info.pseudo_palette  = pseudo_palette;
        fb_info.flags           = FBINFO_DEFAULT;
 
-       fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
+       err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
+       if (err)
+               goto fail_unmap;
        
        err = register_framebuffer(&fb_info);
-       if (!err)
-               printk("fb%d: %s frame buffer device\n",
-                      fb_info.node, fb_info.fix.id);
+       if (err)
+               goto fail_dealloc;
+
+       printk("fb%d: %s frame buffer device\n",
+              fb_info.node, fb_info.fix.id);
+       return 0;
+
+fail_dealloc:
+       fb_dealloc_cmap(&fb_info.cmap);
+fail_unmap:
+       iounmap(fb_info.screen_base);
+       iounmap_macfb();
        return err;
 }