Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * macfb.c: Generic framebuffer for Macs whose colourmaps/modes we
0004  * don't know how to set.
0005  *
0006  * (c) 1999 David Huggins-Daines <dhd@debian.org>
0007  *
0008  * Primarily based on vesafb.c, by Gerd Knorr
0009  * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
0010  *
0011  * Also uses information and code from:
0012  *
0013  * The original macfb.c from Linux/mac68k 2.0, by Alan Cox, Juergen
0014  * Mellinger, Mikael Forselius, Michael Schmitz, and others.
0015  *
0016  * valkyriefb.c, by Martin Costabel, Kevin Schoedel, Barry Nathan, Dan
0017  * Jacobowitz, Paul Mackerras, Fabio Riccardi, and Geert Uytterhoeven.
0018  *
0019  * The VideoToolbox "Bugs" web page at
0020  * http://rajsky.psych.nyu.edu/Tips/VideoBugs.html
0021  */
0022 
0023 #include <linux/module.h>
0024 #include <linux/kernel.h>
0025 #include <linux/errno.h>
0026 #include <linux/string.h>
0027 #include <linux/mm.h>
0028 #include <linux/delay.h>
0029 #include <linux/nubus.h>
0030 #include <linux/init.h>
0031 #include <linux/fb.h>
0032 
0033 #include <asm/setup.h>
0034 #include <asm/macintosh.h>
0035 #include <asm/io.h>
0036 
0037 /* Common DAC base address for the LC, RBV, Valkyrie, and IIvx */
0038 #define DAC_BASE 0x50f24000
0039 
0040 /* Some addresses for the DAFB */
0041 #define DAFB_BASE 0xf9800200
0042 
0043 /* Address for the built-in Civic framebuffer in Quadra AVs */
0044 #define CIVIC_BASE 0x50f30800
0045 
0046 /* GSC (Gray Scale Controller) base address */
0047 #define GSC_BASE 0x50F20000
0048 
0049 /* CSC (Color Screen Controller) base address */
0050 #define CSC_BASE 0x50F20000
0051 
0052 static int (*macfb_setpalette)(unsigned int regno, unsigned int red,
0053                    unsigned int green, unsigned int blue,
0054                    struct fb_info *info);
0055 
0056 static struct {
0057     unsigned char addr;
0058     unsigned char lut;
0059 } __iomem *v8_brazil_cmap_regs;
0060 
0061 static struct {
0062     unsigned char addr;
0063     char pad1[3]; /* word aligned */
0064     unsigned char lut;
0065     char pad2[3]; /* word aligned */
0066     unsigned char cntl; /* a guess as to purpose */
0067 } __iomem *rbv_cmap_regs;
0068 
0069 static struct {
0070     unsigned long reset;
0071     unsigned long pad1[3];
0072     unsigned char pad2[3];
0073     unsigned char lut;
0074 } __iomem *dafb_cmap_regs;
0075 
0076 static struct {
0077     unsigned char addr; /* OFFSET: 0x00 */
0078     unsigned char pad1[15];
0079     unsigned char lut;  /* OFFSET: 0x10 */
0080     unsigned char pad2[15];
0081     unsigned char status;   /* OFFSET: 0x20 */
0082     unsigned char pad3[7];
0083     unsigned long vbl_addr; /* OFFSET: 0x28 */
0084     unsigned int  status2;  /* OFFSET: 0x2C */
0085 } __iomem *civic_cmap_regs;
0086 
0087 static struct {
0088     char pad1[0x40];
0089     unsigned char clut_waddr;   /* 0x40 */
0090     char pad2;
0091     unsigned char clut_data;    /* 0x42 */
0092     char pad3[0x3];
0093     unsigned char clut_raddr;   /* 0x46 */
0094 } __iomem *csc_cmap_regs;
0095 
0096 /* The registers in these structs are in NuBus slot space */
0097 struct mdc_cmap_regs {
0098     char pad1[0x200200];
0099     unsigned char addr;
0100     char pad2[6];
0101     unsigned char lut;
0102 };
0103 
0104 struct toby_cmap_regs {
0105     char pad1[0x90018];
0106     unsigned char lut; /* TFBClutWDataReg, offset 0x90018 */
0107     char pad2[3];
0108     unsigned char addr; /* TFBClutAddrReg, offset 0x9001C */
0109 };
0110 
0111 struct jet_cmap_regs {
0112     char pad1[0xe0e000];
0113     unsigned char addr;
0114     unsigned char lut;
0115 };
0116 
0117 #define PIXEL_TO_MM(a)  (((a)*10)/28)   /* width in mm at 72 dpi */
0118 
0119 static struct fb_var_screeninfo macfb_defined = {
0120     .activate   = FB_ACTIVATE_NOW,
0121     .right_margin   = 32,
0122     .upper_margin   = 16,
0123     .lower_margin   = 4,
0124     .vsync_len  = 4,
0125     .vmode      = FB_VMODE_NONINTERLACED,
0126 };
0127 
0128 static struct fb_fix_screeninfo macfb_fix = {
0129     .type   = FB_TYPE_PACKED_PIXELS,
0130     .accel  = FB_ACCEL_NONE,
0131 };
0132 
0133 static void *slot_addr;
0134 static struct fb_info fb_info;
0135 static u32 pseudo_palette[16];
0136 static int vidtest;
0137 
0138 /*
0139  * Unlike the Valkyrie, the DAFB cannot set individual colormap
0140  * registers.  Therefore, we do what the MacOS driver does (no
0141  * kidding!) and simply set them one by one until we hit the one we
0142  * want.
0143  */
0144 static int dafb_setpalette(unsigned int regno, unsigned int red,
0145                unsigned int green, unsigned int blue,
0146                struct fb_info *info)
0147 {
0148     static int lastreg = -2;
0149     unsigned long flags;
0150 
0151     local_irq_save(flags);
0152 
0153     /*
0154      * fbdev will set an entire colourmap, but X won't.  Hopefully
0155      * this should accommodate both of them
0156      */
0157     if (regno != lastreg + 1) {
0158         int i;
0159 
0160         /* Stab in the dark trying to reset the CLUT pointer */
0161         nubus_writel(0, &dafb_cmap_regs->reset);
0162         nop();
0163 
0164         /* Loop until we get to the register we want */
0165         for (i = 0; i < regno; i++) {
0166             nubus_writeb(info->cmap.red[i] >> 8,
0167                      &dafb_cmap_regs->lut);
0168             nop();
0169             nubus_writeb(info->cmap.green[i] >> 8,
0170                      &dafb_cmap_regs->lut);
0171             nop();
0172             nubus_writeb(info->cmap.blue[i] >> 8,
0173                      &dafb_cmap_regs->lut);
0174             nop();
0175         }
0176     }
0177 
0178     nubus_writeb(red, &dafb_cmap_regs->lut);
0179     nop();
0180     nubus_writeb(green, &dafb_cmap_regs->lut);
0181     nop();
0182     nubus_writeb(blue, &dafb_cmap_regs->lut);
0183 
0184     local_irq_restore(flags);
0185     lastreg = regno;
0186     return 0;
0187 }
0188 
0189 /* V8 and Brazil seem to use the same DAC.  Sonora does as well. */
0190 static int v8_brazil_setpalette(unsigned int regno, unsigned int red,
0191                 unsigned int green, unsigned int blue,
0192                 struct fb_info *info)
0193 {
0194     unsigned int bpp = info->var.bits_per_pixel;
0195     unsigned long flags;
0196 
0197     local_irq_save(flags);
0198 
0199     /* On these chips, the CLUT register numbers are spread out
0200      * across the register space.  Thus:
0201      * In 8bpp, all regnos are valid.
0202      * In 4bpp, the regnos are 0x0f, 0x1f, 0x2f, etc, etc
0203      * In 2bpp, the regnos are 0x3f, 0x7f, 0xbf, 0xff
0204      */
0205     regno = (regno << (8 - bpp)) | (0xFF >> bpp);
0206     nubus_writeb(regno, &v8_brazil_cmap_regs->addr);
0207     nop();
0208 
0209     /* send one color channel at a time */
0210     nubus_writeb(red, &v8_brazil_cmap_regs->lut);
0211     nop();
0212     nubus_writeb(green, &v8_brazil_cmap_regs->lut);
0213     nop();
0214     nubus_writeb(blue, &v8_brazil_cmap_regs->lut);
0215 
0216     local_irq_restore(flags);
0217     return 0;
0218 }
0219 
0220 /* RAM-Based Video */
0221 static int rbv_setpalette(unsigned int regno, unsigned int red,
0222               unsigned int green, unsigned int blue,
0223               struct fb_info *info)
0224 {
0225     unsigned long flags;
0226 
0227     local_irq_save(flags);
0228 
0229     /* From the VideoToolbox driver.  Seems to be saying that
0230      * regno #254 and #255 are the important ones for 1-bit color,
0231      * regno #252-255 are the important ones for 2-bit color, etc.
0232      */
0233     regno += 256 - (1 << info->var.bits_per_pixel);
0234 
0235     /* reset clut? (VideoToolbox sez "not necessary") */
0236     nubus_writeb(0xFF, &rbv_cmap_regs->cntl);
0237     nop();
0238 
0239     /* tell clut which address to use. */
0240     nubus_writeb(regno, &rbv_cmap_regs->addr);
0241     nop();
0242 
0243     /* send one color channel at a time. */
0244     nubus_writeb(red, &rbv_cmap_regs->lut);
0245     nop();
0246     nubus_writeb(green, &rbv_cmap_regs->lut);
0247     nop();
0248     nubus_writeb(blue, &rbv_cmap_regs->lut);
0249 
0250     local_irq_restore(flags);
0251     return 0;
0252 }
0253 
0254 /* Macintosh Display Card (8*24) */
0255 static int mdc_setpalette(unsigned int regno, unsigned int red,
0256               unsigned int green, unsigned int blue,
0257               struct fb_info *info)
0258 {
0259     struct mdc_cmap_regs *cmap_regs = slot_addr;
0260     unsigned long flags;
0261 
0262     local_irq_save(flags);
0263 
0264     /* the nop's are there to order writes. */
0265     nubus_writeb(regno, &cmap_regs->addr);
0266     nop();
0267     nubus_writeb(red, &cmap_regs->lut);
0268     nop();
0269     nubus_writeb(green, &cmap_regs->lut);
0270     nop();
0271     nubus_writeb(blue, &cmap_regs->lut);
0272 
0273     local_irq_restore(flags);
0274     return 0;
0275 }
0276 
0277 /* Toby frame buffer */
0278 static int toby_setpalette(unsigned int regno, unsigned int red,
0279                unsigned int green, unsigned int blue,
0280                struct fb_info *info)
0281 {
0282     struct toby_cmap_regs *cmap_regs = slot_addr;
0283     unsigned int bpp = info->var.bits_per_pixel;
0284     unsigned long flags;
0285 
0286     red = ~red;
0287     green = ~green;
0288     blue = ~blue;
0289     regno = (regno << (8 - bpp)) | (0xFF >> bpp);
0290 
0291     local_irq_save(flags);
0292 
0293     nubus_writeb(regno, &cmap_regs->addr);
0294     nop();
0295     nubus_writeb(red, &cmap_regs->lut);
0296     nop();
0297     nubus_writeb(green, &cmap_regs->lut);
0298     nop();
0299     nubus_writeb(blue, &cmap_regs->lut);
0300 
0301     local_irq_restore(flags);
0302     return 0;
0303 }
0304 
0305 /* Jet frame buffer */
0306 static int jet_setpalette(unsigned int regno, unsigned int red,
0307               unsigned int green, unsigned int blue,
0308               struct fb_info *info)
0309 {
0310     struct jet_cmap_regs *cmap_regs = slot_addr;
0311     unsigned long flags;
0312 
0313     local_irq_save(flags);
0314 
0315     nubus_writeb(regno, &cmap_regs->addr);
0316     nop();
0317     nubus_writeb(red, &cmap_regs->lut);
0318     nop();
0319     nubus_writeb(green, &cmap_regs->lut);
0320     nop();
0321     nubus_writeb(blue, &cmap_regs->lut);
0322 
0323     local_irq_restore(flags);
0324     return 0;
0325 }
0326 
0327 /*
0328  * Civic framebuffer -- Quadra AV built-in video.  A chip
0329  * called Sebastian holds the actual color palettes, and
0330  * apparently, there are two different banks of 512K RAM
0331  * which can act as separate framebuffers for doing video
0332  * input and viewing the screen at the same time!  The 840AV
0333  * Can add another 1MB RAM to give the two framebuffers
0334  * 1MB RAM apiece.
0335  */
0336 static int civic_setpalette(unsigned int regno, unsigned int red,
0337                 unsigned int green, unsigned int blue,
0338                 struct fb_info *info)
0339 {
0340     unsigned long flags;
0341     int clut_status;
0342     
0343     local_irq_save(flags);
0344 
0345     /* Set the register address */
0346     nubus_writeb(regno, &civic_cmap_regs->addr);
0347     nop();
0348 
0349     /*
0350      * Grab a status word and do some checking;
0351      * Then finally write the clut!
0352      */
0353     clut_status =  nubus_readb(&civic_cmap_regs->status2);
0354 
0355     if ((clut_status & 0x0008) == 0)
0356     {
0357 #if 0
0358         if ((clut_status & 0x000D) != 0)
0359         {
0360             nubus_writeb(0x00, &civic_cmap_regs->lut);
0361             nop();
0362             nubus_writeb(0x00, &civic_cmap_regs->lut);
0363             nop();
0364         }
0365 #endif
0366 
0367         nubus_writeb(red, &civic_cmap_regs->lut);
0368         nop();
0369         nubus_writeb(green, &civic_cmap_regs->lut);
0370         nop();
0371         nubus_writeb(blue, &civic_cmap_regs->lut);
0372         nop();
0373         nubus_writeb(0x00, &civic_cmap_regs->lut);
0374     }
0375     else
0376     {
0377         unsigned char junk;
0378 
0379         junk = nubus_readb(&civic_cmap_regs->lut);
0380         nop();
0381         junk = nubus_readb(&civic_cmap_regs->lut);
0382         nop();
0383         junk = nubus_readb(&civic_cmap_regs->lut);
0384         nop();
0385         junk = nubus_readb(&civic_cmap_regs->lut);
0386         nop();
0387 
0388         if ((clut_status & 0x000D) != 0)
0389         {
0390             nubus_writeb(0x00, &civic_cmap_regs->lut);
0391             nop();
0392             nubus_writeb(0x00, &civic_cmap_regs->lut);
0393             nop();
0394         }
0395 
0396         nubus_writeb(red, &civic_cmap_regs->lut);
0397         nop();
0398         nubus_writeb(green, &civic_cmap_regs->lut);
0399         nop();
0400         nubus_writeb(blue, &civic_cmap_regs->lut);
0401         nop();
0402         nubus_writeb(junk, &civic_cmap_regs->lut);
0403     }
0404 
0405     local_irq_restore(flags);
0406     return 0;
0407 }
0408 
0409 /*
0410  * The CSC is the framebuffer on the PowerBook 190 series
0411  * (and the 5300 too, but that's a PowerMac). This function
0412  * brought to you in part by the ECSC driver for MkLinux.
0413  */
0414 static int csc_setpalette(unsigned int regno, unsigned int red,
0415               unsigned int green, unsigned int blue,
0416               struct fb_info *info)
0417 {
0418     unsigned long flags;
0419 
0420     local_irq_save(flags);
0421 
0422     udelay(1); /* mklinux on PB 5300 waits for 260 ns */
0423     nubus_writeb(regno, &csc_cmap_regs->clut_waddr);
0424     nubus_writeb(red, &csc_cmap_regs->clut_data);
0425     nubus_writeb(green, &csc_cmap_regs->clut_data);
0426     nubus_writeb(blue, &csc_cmap_regs->clut_data);
0427 
0428     local_irq_restore(flags);
0429     return 0;
0430 }
0431 
0432 static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
0433                unsigned blue, unsigned transp,
0434                struct fb_info *fb_info)
0435 {
0436     /*
0437      * Set a single color register. The values supplied are
0438      * already rounded down to the hardware's capabilities
0439      * (according to the entries in the `var' structure).
0440      * Return non-zero for invalid regno.
0441      */
0442     
0443     if (regno >= fb_info->cmap.len)
0444         return 1;
0445 
0446     if (fb_info->var.bits_per_pixel <= 8) {
0447         switch (fb_info->var.bits_per_pixel) {
0448         case 1:
0449             /* We shouldn't get here */
0450             break;
0451         case 2:
0452         case 4:
0453         case 8:
0454             if (macfb_setpalette)
0455                 macfb_setpalette(regno, red >> 8, green >> 8,
0456                          blue >> 8, fb_info);
0457             else
0458                 return 1;
0459             break;
0460         }
0461     } else if (regno < 16) {
0462         switch (fb_info->var.bits_per_pixel) {
0463         case 16:
0464             if (fb_info->var.red.offset == 10) {
0465                 /* 1:5:5:5 */
0466                 ((u32*) (fb_info->pseudo_palette))[regno] =
0467                     ((red   & 0xf800) >>  1) |
0468                     ((green & 0xf800) >>  6) |
0469                     ((blue  & 0xf800) >> 11) |
0470                     ((transp != 0) << 15);
0471             } else {
0472                 /* 0:5:6:5 */
0473                 ((u32*) (fb_info->pseudo_palette))[regno] =
0474                     ((red   & 0xf800) >>  0) |
0475                     ((green & 0xfc00) >>  5) |
0476                     ((blue  & 0xf800) >> 11);
0477             }
0478             break;
0479         /*
0480          * 24-bit colour almost doesn't exist on 68k Macs --
0481          * https://support.apple.com/kb/TA28634 (Old Article: 10992)
0482          */
0483         case 24:
0484         case 32:
0485             red   >>= 8;
0486             green >>= 8;
0487             blue  >>= 8;
0488             ((u32 *)(fb_info->pseudo_palette))[regno] =
0489                 (red   << fb_info->var.red.offset) |
0490                 (green << fb_info->var.green.offset) |
0491                 (blue  << fb_info->var.blue.offset);
0492             break;
0493         }
0494     }
0495 
0496     return 0;
0497 }
0498 
0499 static const struct fb_ops macfb_ops = {
0500     .owner      = THIS_MODULE,
0501     .fb_setcolreg   = macfb_setcolreg,
0502     .fb_fillrect    = cfb_fillrect,
0503     .fb_copyarea    = cfb_copyarea,
0504     .fb_imageblit   = cfb_imageblit,
0505 };
0506 
0507 static void __init macfb_setup(char *options)
0508 {
0509     char *this_opt;
0510 
0511     if (!options || !*options)
0512         return;
0513 
0514     while ((this_opt = strsep(&options, ",")) != NULL) {
0515         if (!*this_opt)
0516             continue;
0517 
0518         if (!strcmp(this_opt, "inverse"))
0519             fb_invert_cmaps();
0520         else
0521             if (!strcmp(this_opt, "vidtest"))
0522                 vidtest = 1; /* enable experimental CLUT code */
0523     }
0524 }
0525 
0526 static void __init iounmap_macfb(void)
0527 {
0528     if (dafb_cmap_regs)
0529         iounmap(dafb_cmap_regs);
0530     if (v8_brazil_cmap_regs)
0531         iounmap(v8_brazil_cmap_regs);
0532     if (rbv_cmap_regs)
0533         iounmap(rbv_cmap_regs);
0534     if (civic_cmap_regs)
0535         iounmap(civic_cmap_regs);
0536     if (csc_cmap_regs)
0537         iounmap(csc_cmap_regs);
0538 }
0539 
0540 static int __init macfb_init(void)
0541 {
0542     int video_cmap_len, video_is_nubus = 0;
0543     struct nubus_rsrc *ndev = NULL;
0544     char *option = NULL;
0545     int err;
0546 
0547     if (fb_get_options("macfb", &option))
0548         return -ENODEV;
0549     macfb_setup(option);
0550 
0551     if (!MACH_IS_MAC) 
0552         return -ENODEV;
0553 
0554     if (mac_bi_data.id == MAC_MODEL_Q630 ||
0555         mac_bi_data.id == MAC_MODEL_P588)
0556         return -ENODEV; /* See valkyriefb.c */
0557 
0558     macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF;
0559     macfb_defined.yres = mac_bi_data.dimensions >> 16;
0560     macfb_defined.bits_per_pixel = mac_bi_data.videodepth;
0561 
0562     macfb_fix.line_length = mac_bi_data.videorow;
0563     macfb_fix.smem_len    = macfb_fix.line_length * macfb_defined.yres;
0564     /* Note: physical address (since 2.1.127) */
0565     macfb_fix.smem_start  = mac_bi_data.videoaddr;
0566 
0567     /*
0568      * This is actually redundant with the initial mappings.
0569      * However, there are some non-obvious aspects to the way
0570      * those mappings are set up, so this is in fact the safest
0571      * way to ensure that this driver will work on every possible Mac
0572      */
0573     fb_info.screen_base = ioremap(mac_bi_data.videoaddr,
0574                       macfb_fix.smem_len);
0575     if (!fb_info.screen_base)
0576         return -ENODEV;
0577 
0578     pr_info("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk\n",
0579             macfb_fix.smem_start, fb_info.screen_base,
0580             macfb_fix.smem_len / 1024);
0581     pr_info("macfb: mode is %dx%dx%d, linelength=%d\n",
0582             macfb_defined.xres, macfb_defined.yres,
0583             macfb_defined.bits_per_pixel, macfb_fix.line_length);
0584 
0585     /* Fill in the available video resolution */
0586     macfb_defined.xres_virtual = macfb_defined.xres;
0587     macfb_defined.yres_virtual = macfb_defined.yres;
0588     macfb_defined.height       = PIXEL_TO_MM(macfb_defined.yres);
0589     macfb_defined.width        = PIXEL_TO_MM(macfb_defined.xres);
0590 
0591     /* Some dummy values for timing to make fbset happy */
0592     macfb_defined.pixclock     = 10000000 / macfb_defined.xres *
0593                      1000 / macfb_defined.yres;
0594     macfb_defined.left_margin  = (macfb_defined.xres / 8) & 0xf8;
0595     macfb_defined.hsync_len    = (macfb_defined.xres / 8) & 0xf8;
0596 
0597     switch (macfb_defined.bits_per_pixel) {
0598     case 1:
0599         macfb_defined.red.length = macfb_defined.bits_per_pixel;
0600         macfb_defined.green.length = macfb_defined.bits_per_pixel;
0601         macfb_defined.blue.length = macfb_defined.bits_per_pixel;
0602         video_cmap_len = 2;
0603         macfb_fix.visual = FB_VISUAL_MONO01;
0604         break;
0605     case 2:
0606     case 4:
0607     case 8:
0608         macfb_defined.red.length = macfb_defined.bits_per_pixel;
0609         macfb_defined.green.length = macfb_defined.bits_per_pixel;
0610         macfb_defined.blue.length = macfb_defined.bits_per_pixel;
0611         video_cmap_len = 1 << macfb_defined.bits_per_pixel;
0612         macfb_fix.visual = FB_VISUAL_PSEUDOCOLOR;
0613         break;
0614     case 16:
0615         macfb_defined.transp.offset = 15;
0616         macfb_defined.transp.length = 1;
0617         macfb_defined.red.offset = 10;
0618         macfb_defined.red.length = 5;
0619         macfb_defined.green.offset = 5;
0620         macfb_defined.green.length = 5;
0621         macfb_defined.blue.offset = 0;
0622         macfb_defined.blue.length = 5;
0623         video_cmap_len = 16;
0624         /*
0625          * Should actually be FB_VISUAL_DIRECTCOLOR, but this
0626          * works too
0627          */
0628         macfb_fix.visual = FB_VISUAL_TRUECOLOR;
0629         break;
0630     case 24:
0631     case 32:
0632         macfb_defined.red.offset = 16;
0633         macfb_defined.red.length = 8;
0634         macfb_defined.green.offset = 8;
0635         macfb_defined.green.length = 8;
0636         macfb_defined.blue.offset = 0;
0637         macfb_defined.blue.length = 8;
0638         video_cmap_len = 16;
0639         macfb_fix.visual = FB_VISUAL_TRUECOLOR;
0640         break;
0641     default:
0642         pr_err("macfb: unknown or unsupported bit depth: %d\n",
0643                macfb_defined.bits_per_pixel);
0644         err = -EINVAL;
0645         goto fail_unmap;
0646     }
0647     
0648     /*
0649      * We take a wild guess that if the video physical address is
0650      * in nubus slot space, that the nubus card is driving video.
0651      * Penguin really ought to tell us whether we are using internal
0652      * video or not.
0653      * Hopefully we only find one of them.  Otherwise our NuBus
0654      * code is really broken :-)
0655      */
0656 
0657     for_each_func_rsrc(ndev) {
0658         unsigned long base = ndev->board->slot_addr;
0659 
0660         if (mac_bi_data.videoaddr < base ||
0661             mac_bi_data.videoaddr - base > 0xFFFFFF)
0662             continue;
0663 
0664         if (ndev->category != NUBUS_CAT_DISPLAY ||
0665             ndev->type != NUBUS_TYPE_VIDEO)
0666             continue;
0667 
0668         video_is_nubus = 1;
0669         slot_addr = (unsigned char *)base;
0670 
0671         switch(ndev->dr_hw) {
0672         case NUBUS_DRHW_APPLE_MDC:
0673             strcpy(macfb_fix.id, "Mac Disp. Card");
0674             macfb_setpalette = mdc_setpalette;
0675             break;
0676         case NUBUS_DRHW_APPLE_TFB:
0677             strcpy(macfb_fix.id, "Toby");
0678             macfb_setpalette = toby_setpalette;
0679             break;
0680         case NUBUS_DRHW_APPLE_JET:
0681             strcpy(macfb_fix.id, "Jet");
0682             macfb_setpalette = jet_setpalette;
0683             break;
0684         default:
0685             strcpy(macfb_fix.id, "Generic NuBus");
0686             break;
0687         }
0688     }
0689 
0690     /* If it's not a NuBus card, it must be internal video */
0691     if (!video_is_nubus)
0692         switch (mac_bi_data.id) {
0693         /*
0694          * DAFB Quadras
0695          * Note: these first four have the v7 DAFB, which is
0696          * known to be rather unlike the ones used in the
0697          * other models
0698          */
0699         case MAC_MODEL_P475:
0700         case MAC_MODEL_P475F:
0701         case MAC_MODEL_P575:
0702         case MAC_MODEL_Q605:
0703 
0704         case MAC_MODEL_Q800:
0705         case MAC_MODEL_Q650:
0706         case MAC_MODEL_Q610:
0707         case MAC_MODEL_C650:
0708         case MAC_MODEL_C610:
0709         case MAC_MODEL_Q700:
0710         case MAC_MODEL_Q900:
0711         case MAC_MODEL_Q950:
0712             strcpy(macfb_fix.id, "DAFB");
0713             macfb_setpalette = dafb_setpalette;
0714             dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);
0715             break;
0716 
0717         /*
0718          * LC II uses the V8 framebuffer
0719          */
0720         case MAC_MODEL_LCII:
0721             strcpy(macfb_fix.id, "V8");
0722             macfb_setpalette = v8_brazil_setpalette;
0723             v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
0724             break;
0725 
0726         /*
0727          * IIvi, IIvx use the "Brazil" framebuffer (which is
0728          * very much like the V8, it seems, and probably uses
0729          * the same DAC)
0730          */
0731         case MAC_MODEL_IIVI:
0732         case MAC_MODEL_IIVX:
0733         case MAC_MODEL_P600:
0734             strcpy(macfb_fix.id, "Brazil");
0735             macfb_setpalette = v8_brazil_setpalette;
0736             v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
0737             break;
0738 
0739         /*
0740          * LC III (and friends) use the Sonora framebuffer
0741          * Incidentally this is also used in the non-AV models
0742          * of the x100 PowerMacs
0743          * These do in fact seem to use the same DAC interface
0744          * as the LC II.
0745          */
0746         case MAC_MODEL_LCIII:
0747         case MAC_MODEL_P520:
0748         case MAC_MODEL_P550:
0749         case MAC_MODEL_P460:
0750             strcpy(macfb_fix.id, "Sonora");
0751             macfb_setpalette = v8_brazil_setpalette;
0752             v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
0753             break;
0754 
0755         /*
0756          * IIci and IIsi use the infamous RBV chip
0757          * (the IIsi is just a rebadged and crippled
0758          * IIci in a different case, BTW)
0759          */
0760         case MAC_MODEL_IICI:
0761         case MAC_MODEL_IISI:
0762             strcpy(macfb_fix.id, "RBV");
0763             macfb_setpalette = rbv_setpalette;
0764             rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);
0765             break;
0766 
0767         /*
0768          * AVs use the Civic framebuffer
0769          */
0770         case MAC_MODEL_Q840:
0771         case MAC_MODEL_C660:
0772             strcpy(macfb_fix.id, "Civic");
0773             macfb_setpalette = civic_setpalette;
0774             civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
0775             break;
0776 
0777         
0778         /*
0779          * Assorted weirdos
0780          * We think this may be like the LC II
0781          */
0782         case MAC_MODEL_LC:
0783             strcpy(macfb_fix.id, "LC");
0784             if (vidtest) {
0785                 macfb_setpalette = v8_brazil_setpalette;
0786                 v8_brazil_cmap_regs =
0787                     ioremap(DAC_BASE, 0x1000);
0788             }
0789             break;
0790 
0791         /*
0792          * We think this may be like the LC II
0793          */
0794         case MAC_MODEL_CCL:
0795             strcpy(macfb_fix.id, "Color Classic");
0796             if (vidtest) {
0797                 macfb_setpalette = v8_brazil_setpalette;
0798                 v8_brazil_cmap_regs =
0799                     ioremap(DAC_BASE, 0x1000);
0800             }
0801             break;
0802 
0803         /*
0804          * And we *do* mean "weirdos"
0805          */
0806         case MAC_MODEL_TV:
0807             strcpy(macfb_fix.id, "Mac TV");
0808             break;
0809 
0810         /*
0811          * These don't have colour, so no need to worry
0812          */
0813         case MAC_MODEL_SE30:
0814         case MAC_MODEL_CLII:
0815             strcpy(macfb_fix.id, "Monochrome");
0816             break;
0817 
0818         /*
0819          * Powerbooks are particularly difficult.  Many of
0820          * them have separate framebuffers for external and
0821          * internal video, which is admittedly pretty cool,
0822          * but will be a bit of a headache to support here.
0823          * Also, many of them are grayscale, and we don't
0824          * really support that.
0825          */
0826 
0827         /*
0828          * Slot 0 ROM says TIM. No external video. B&W.
0829          */
0830         case MAC_MODEL_PB140:
0831         case MAC_MODEL_PB145:
0832         case MAC_MODEL_PB170:
0833             strcpy(macfb_fix.id, "DDC");
0834             break;
0835 
0836         /*
0837          * Internal is GSC, External (if present) is ViSC
0838          */
0839         case MAC_MODEL_PB150:   /* no external video */
0840         case MAC_MODEL_PB160:
0841         case MAC_MODEL_PB165:
0842         case MAC_MODEL_PB180:
0843         case MAC_MODEL_PB210:
0844         case MAC_MODEL_PB230:
0845             strcpy(macfb_fix.id, "GSC");
0846             break;
0847 
0848         /*
0849          * Internal is TIM, External is ViSC
0850          */
0851         case MAC_MODEL_PB165C:
0852         case MAC_MODEL_PB180C:
0853             strcpy(macfb_fix.id, "TIM");
0854             break;
0855 
0856         /*
0857          * Internal is CSC, External is Keystone+Ariel.
0858          */
0859         case MAC_MODEL_PB190:   /* external video is optional */
0860         case MAC_MODEL_PB520:
0861         case MAC_MODEL_PB250:
0862         case MAC_MODEL_PB270C:
0863         case MAC_MODEL_PB280:
0864         case MAC_MODEL_PB280C:
0865             strcpy(macfb_fix.id, "CSC");
0866             macfb_setpalette = csc_setpalette;
0867             csc_cmap_regs = ioremap(CSC_BASE, 0x1000);
0868             break;
0869 
0870         default:
0871             strcpy(macfb_fix.id, "Unknown");
0872             break;
0873         }
0874 
0875     fb_info.fbops       = &macfb_ops;
0876     fb_info.var     = macfb_defined;
0877     fb_info.fix     = macfb_fix;
0878     fb_info.pseudo_palette  = pseudo_palette;
0879     fb_info.flags       = FBINFO_DEFAULT;
0880 
0881     err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
0882     if (err)
0883         goto fail_unmap;
0884 
0885     err = register_framebuffer(&fb_info);
0886     if (err)
0887         goto fail_dealloc;
0888 
0889     fb_info(&fb_info, "%s frame buffer device\n", fb_info.fix.id);
0890 
0891     return 0;
0892 
0893 fail_dealloc:
0894     fb_dealloc_cmap(&fb_info.cmap);
0895 fail_unmap:
0896     iounmap(fb_info.screen_base);
0897     iounmap_macfb();
0898     return err;
0899 }
0900 
0901 module_init(macfb_init);
0902 MODULE_LICENSE("GPL");