18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * macfb.c: Generic framebuffer for Macs whose colourmaps/modes we 48c2ecf20Sopenharmony_ci * don't know how to set. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * (c) 1999 David Huggins-Daines <dhd@debian.org> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Primarily based on vesafb.c, by Gerd Knorr 98c2ecf20Sopenharmony_ci * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Also uses information and code from: 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * The original macfb.c from Linux/mac68k 2.0, by Alan Cox, Juergen 148c2ecf20Sopenharmony_ci * Mellinger, Mikael Forselius, Michael Schmitz, and others. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * valkyriefb.c, by Martin Costabel, Kevin Schoedel, Barry Nathan, Dan 178c2ecf20Sopenharmony_ci * Jacobowitz, Paul Mackerras, Fabio Riccardi, and Geert Uytterhoeven. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * The VideoToolbox "Bugs" web page at 208c2ecf20Sopenharmony_ci * http://rajsky.psych.nyu.edu/Tips/VideoBugs.html 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include <linux/module.h> 248c2ecf20Sopenharmony_ci#include <linux/kernel.h> 258c2ecf20Sopenharmony_ci#include <linux/errno.h> 268c2ecf20Sopenharmony_ci#include <linux/string.h> 278c2ecf20Sopenharmony_ci#include <linux/mm.h> 288c2ecf20Sopenharmony_ci#include <linux/delay.h> 298c2ecf20Sopenharmony_ci#include <linux/nubus.h> 308c2ecf20Sopenharmony_ci#include <linux/init.h> 318c2ecf20Sopenharmony_ci#include <linux/fb.h> 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include <asm/setup.h> 348c2ecf20Sopenharmony_ci#include <asm/macintosh.h> 358c2ecf20Sopenharmony_ci#include <asm/io.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* Common DAC base address for the LC, RBV, Valkyrie, and IIvx */ 388c2ecf20Sopenharmony_ci#define DAC_BASE 0x50f24000 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* Some addresses for the DAFB */ 418c2ecf20Sopenharmony_ci#define DAFB_BASE 0xf9800200 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* Address for the built-in Civic framebuffer in Quadra AVs */ 448c2ecf20Sopenharmony_ci#define CIVIC_BASE 0x50f30800 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* GSC (Gray Scale Controller) base address */ 478c2ecf20Sopenharmony_ci#define GSC_BASE 0x50F20000 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* CSC (Color Screen Controller) base address */ 508c2ecf20Sopenharmony_ci#define CSC_BASE 0x50F20000 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic int (*macfb_setpalette)(unsigned int regno, unsigned int red, 538c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 548c2ecf20Sopenharmony_ci struct fb_info *info); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic struct { 578c2ecf20Sopenharmony_ci unsigned char addr; 588c2ecf20Sopenharmony_ci unsigned char lut; 598c2ecf20Sopenharmony_ci} __iomem *v8_brazil_cmap_regs; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistatic struct { 628c2ecf20Sopenharmony_ci unsigned char addr; 638c2ecf20Sopenharmony_ci char pad1[3]; /* word aligned */ 648c2ecf20Sopenharmony_ci unsigned char lut; 658c2ecf20Sopenharmony_ci char pad2[3]; /* word aligned */ 668c2ecf20Sopenharmony_ci unsigned char cntl; /* a guess as to purpose */ 678c2ecf20Sopenharmony_ci} __iomem *rbv_cmap_regs; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic struct { 708c2ecf20Sopenharmony_ci unsigned long reset; 718c2ecf20Sopenharmony_ci unsigned long pad1[3]; 728c2ecf20Sopenharmony_ci unsigned char pad2[3]; 738c2ecf20Sopenharmony_ci unsigned char lut; 748c2ecf20Sopenharmony_ci} __iomem *dafb_cmap_regs; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistatic struct { 778c2ecf20Sopenharmony_ci unsigned char addr; /* OFFSET: 0x00 */ 788c2ecf20Sopenharmony_ci unsigned char pad1[15]; 798c2ecf20Sopenharmony_ci unsigned char lut; /* OFFSET: 0x10 */ 808c2ecf20Sopenharmony_ci unsigned char pad2[15]; 818c2ecf20Sopenharmony_ci unsigned char status; /* OFFSET: 0x20 */ 828c2ecf20Sopenharmony_ci unsigned char pad3[7]; 838c2ecf20Sopenharmony_ci unsigned long vbl_addr; /* OFFSET: 0x28 */ 848c2ecf20Sopenharmony_ci unsigned int status2; /* OFFSET: 0x2C */ 858c2ecf20Sopenharmony_ci} __iomem *civic_cmap_regs; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistatic struct { 888c2ecf20Sopenharmony_ci char pad1[0x40]; 898c2ecf20Sopenharmony_ci unsigned char clut_waddr; /* 0x40 */ 908c2ecf20Sopenharmony_ci char pad2; 918c2ecf20Sopenharmony_ci unsigned char clut_data; /* 0x42 */ 928c2ecf20Sopenharmony_ci char pad3[0x3]; 938c2ecf20Sopenharmony_ci unsigned char clut_raddr; /* 0x46 */ 948c2ecf20Sopenharmony_ci} __iomem *csc_cmap_regs; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* The registers in these structs are in NuBus slot space */ 978c2ecf20Sopenharmony_cistruct mdc_cmap_regs { 988c2ecf20Sopenharmony_ci char pad1[0x200200]; 998c2ecf20Sopenharmony_ci unsigned char addr; 1008c2ecf20Sopenharmony_ci char pad2[6]; 1018c2ecf20Sopenharmony_ci unsigned char lut; 1028c2ecf20Sopenharmony_ci}; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistruct toby_cmap_regs { 1058c2ecf20Sopenharmony_ci char pad1[0x90018]; 1068c2ecf20Sopenharmony_ci unsigned char lut; /* TFBClutWDataReg, offset 0x90018 */ 1078c2ecf20Sopenharmony_ci char pad2[3]; 1088c2ecf20Sopenharmony_ci unsigned char addr; /* TFBClutAddrReg, offset 0x9001C */ 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistruct jet_cmap_regs { 1128c2ecf20Sopenharmony_ci char pad1[0xe0e000]; 1138c2ecf20Sopenharmony_ci unsigned char addr; 1148c2ecf20Sopenharmony_ci unsigned char lut; 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define PIXEL_TO_MM(a) (((a)*10)/28) /* width in mm at 72 dpi */ 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic struct fb_var_screeninfo macfb_defined = { 1208c2ecf20Sopenharmony_ci .activate = FB_ACTIVATE_NOW, 1218c2ecf20Sopenharmony_ci .right_margin = 32, 1228c2ecf20Sopenharmony_ci .upper_margin = 16, 1238c2ecf20Sopenharmony_ci .lower_margin = 4, 1248c2ecf20Sopenharmony_ci .vsync_len = 4, 1258c2ecf20Sopenharmony_ci .vmode = FB_VMODE_NONINTERLACED, 1268c2ecf20Sopenharmony_ci}; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic struct fb_fix_screeninfo macfb_fix = { 1298c2ecf20Sopenharmony_ci .type = FB_TYPE_PACKED_PIXELS, 1308c2ecf20Sopenharmony_ci .accel = FB_ACCEL_NONE, 1318c2ecf20Sopenharmony_ci}; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic void *slot_addr; 1348c2ecf20Sopenharmony_cistatic struct fb_info fb_info; 1358c2ecf20Sopenharmony_cistatic u32 pseudo_palette[16]; 1368c2ecf20Sopenharmony_cistatic int vidtest; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci/* 1398c2ecf20Sopenharmony_ci * Unlike the Valkyrie, the DAFB cannot set individual colormap 1408c2ecf20Sopenharmony_ci * registers. Therefore, we do what the MacOS driver does (no 1418c2ecf20Sopenharmony_ci * kidding!) and simply set them one by one until we hit the one we 1428c2ecf20Sopenharmony_ci * want. 1438c2ecf20Sopenharmony_ci */ 1448c2ecf20Sopenharmony_cistatic int dafb_setpalette(unsigned int regno, unsigned int red, 1458c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 1468c2ecf20Sopenharmony_ci struct fb_info *info) 1478c2ecf20Sopenharmony_ci{ 1488c2ecf20Sopenharmony_ci static int lastreg = -2; 1498c2ecf20Sopenharmony_ci unsigned long flags; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci local_irq_save(flags); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci /* 1548c2ecf20Sopenharmony_ci * fbdev will set an entire colourmap, but X won't. Hopefully 1558c2ecf20Sopenharmony_ci * this should accommodate both of them 1568c2ecf20Sopenharmony_ci */ 1578c2ecf20Sopenharmony_ci if (regno != lastreg + 1) { 1588c2ecf20Sopenharmony_ci int i; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci /* Stab in the dark trying to reset the CLUT pointer */ 1618c2ecf20Sopenharmony_ci nubus_writel(0, &dafb_cmap_regs->reset); 1628c2ecf20Sopenharmony_ci nop(); 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci /* Loop until we get to the register we want */ 1658c2ecf20Sopenharmony_ci for (i = 0; i < regno; i++) { 1668c2ecf20Sopenharmony_ci nubus_writeb(info->cmap.red[i] >> 8, 1678c2ecf20Sopenharmony_ci &dafb_cmap_regs->lut); 1688c2ecf20Sopenharmony_ci nop(); 1698c2ecf20Sopenharmony_ci nubus_writeb(info->cmap.green[i] >> 8, 1708c2ecf20Sopenharmony_ci &dafb_cmap_regs->lut); 1718c2ecf20Sopenharmony_ci nop(); 1728c2ecf20Sopenharmony_ci nubus_writeb(info->cmap.blue[i] >> 8, 1738c2ecf20Sopenharmony_ci &dafb_cmap_regs->lut); 1748c2ecf20Sopenharmony_ci nop(); 1758c2ecf20Sopenharmony_ci } 1768c2ecf20Sopenharmony_ci } 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci nubus_writeb(red, &dafb_cmap_regs->lut); 1798c2ecf20Sopenharmony_ci nop(); 1808c2ecf20Sopenharmony_ci nubus_writeb(green, &dafb_cmap_regs->lut); 1818c2ecf20Sopenharmony_ci nop(); 1828c2ecf20Sopenharmony_ci nubus_writeb(blue, &dafb_cmap_regs->lut); 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci local_irq_restore(flags); 1858c2ecf20Sopenharmony_ci lastreg = regno; 1868c2ecf20Sopenharmony_ci return 0; 1878c2ecf20Sopenharmony_ci} 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci/* V8 and Brazil seem to use the same DAC. Sonora does as well. */ 1908c2ecf20Sopenharmony_cistatic int v8_brazil_setpalette(unsigned int regno, unsigned int red, 1918c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 1928c2ecf20Sopenharmony_ci struct fb_info *info) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci unsigned int bpp = info->var.bits_per_pixel; 1958c2ecf20Sopenharmony_ci unsigned long flags; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci local_irq_save(flags); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci /* On these chips, the CLUT register numbers are spread out 2008c2ecf20Sopenharmony_ci * across the register space. Thus: 2018c2ecf20Sopenharmony_ci * In 8bpp, all regnos are valid. 2028c2ecf20Sopenharmony_ci * In 4bpp, the regnos are 0x0f, 0x1f, 0x2f, etc, etc 2038c2ecf20Sopenharmony_ci * In 2bpp, the regnos are 0x3f, 0x7f, 0xbf, 0xff 2048c2ecf20Sopenharmony_ci */ 2058c2ecf20Sopenharmony_ci regno = (regno << (8 - bpp)) | (0xFF >> bpp); 2068c2ecf20Sopenharmony_ci nubus_writeb(regno, &v8_brazil_cmap_regs->addr); 2078c2ecf20Sopenharmony_ci nop(); 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci /* send one color channel at a time */ 2108c2ecf20Sopenharmony_ci nubus_writeb(red, &v8_brazil_cmap_regs->lut); 2118c2ecf20Sopenharmony_ci nop(); 2128c2ecf20Sopenharmony_ci nubus_writeb(green, &v8_brazil_cmap_regs->lut); 2138c2ecf20Sopenharmony_ci nop(); 2148c2ecf20Sopenharmony_ci nubus_writeb(blue, &v8_brazil_cmap_regs->lut); 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci local_irq_restore(flags); 2178c2ecf20Sopenharmony_ci return 0; 2188c2ecf20Sopenharmony_ci} 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci/* RAM-Based Video */ 2218c2ecf20Sopenharmony_cistatic int rbv_setpalette(unsigned int regno, unsigned int red, 2228c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 2238c2ecf20Sopenharmony_ci struct fb_info *info) 2248c2ecf20Sopenharmony_ci{ 2258c2ecf20Sopenharmony_ci unsigned long flags; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci local_irq_save(flags); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci /* From the VideoToolbox driver. Seems to be saying that 2308c2ecf20Sopenharmony_ci * regno #254 and #255 are the important ones for 1-bit color, 2318c2ecf20Sopenharmony_ci * regno #252-255 are the important ones for 2-bit color, etc. 2328c2ecf20Sopenharmony_ci */ 2338c2ecf20Sopenharmony_ci regno += 256 - (1 << info->var.bits_per_pixel); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci /* reset clut? (VideoToolbox sez "not necessary") */ 2368c2ecf20Sopenharmony_ci nubus_writeb(0xFF, &rbv_cmap_regs->cntl); 2378c2ecf20Sopenharmony_ci nop(); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci /* tell clut which address to use. */ 2408c2ecf20Sopenharmony_ci nubus_writeb(regno, &rbv_cmap_regs->addr); 2418c2ecf20Sopenharmony_ci nop(); 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci /* send one color channel at a time. */ 2448c2ecf20Sopenharmony_ci nubus_writeb(red, &rbv_cmap_regs->lut); 2458c2ecf20Sopenharmony_ci nop(); 2468c2ecf20Sopenharmony_ci nubus_writeb(green, &rbv_cmap_regs->lut); 2478c2ecf20Sopenharmony_ci nop(); 2488c2ecf20Sopenharmony_ci nubus_writeb(blue, &rbv_cmap_regs->lut); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci local_irq_restore(flags); 2518c2ecf20Sopenharmony_ci return 0; 2528c2ecf20Sopenharmony_ci} 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci/* Macintosh Display Card (8*24) */ 2558c2ecf20Sopenharmony_cistatic int mdc_setpalette(unsigned int regno, unsigned int red, 2568c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 2578c2ecf20Sopenharmony_ci struct fb_info *info) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci struct mdc_cmap_regs *cmap_regs = slot_addr; 2608c2ecf20Sopenharmony_ci unsigned long flags; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci local_irq_save(flags); 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci /* the nop's are there to order writes. */ 2658c2ecf20Sopenharmony_ci nubus_writeb(regno, &cmap_regs->addr); 2668c2ecf20Sopenharmony_ci nop(); 2678c2ecf20Sopenharmony_ci nubus_writeb(red, &cmap_regs->lut); 2688c2ecf20Sopenharmony_ci nop(); 2698c2ecf20Sopenharmony_ci nubus_writeb(green, &cmap_regs->lut); 2708c2ecf20Sopenharmony_ci nop(); 2718c2ecf20Sopenharmony_ci nubus_writeb(blue, &cmap_regs->lut); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci local_irq_restore(flags); 2748c2ecf20Sopenharmony_ci return 0; 2758c2ecf20Sopenharmony_ci} 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci/* Toby frame buffer */ 2788c2ecf20Sopenharmony_cistatic int toby_setpalette(unsigned int regno, unsigned int red, 2798c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 2808c2ecf20Sopenharmony_ci struct fb_info *info) 2818c2ecf20Sopenharmony_ci{ 2828c2ecf20Sopenharmony_ci struct toby_cmap_regs *cmap_regs = slot_addr; 2838c2ecf20Sopenharmony_ci unsigned int bpp = info->var.bits_per_pixel; 2848c2ecf20Sopenharmony_ci unsigned long flags; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci red = ~red; 2878c2ecf20Sopenharmony_ci green = ~green; 2888c2ecf20Sopenharmony_ci blue = ~blue; 2898c2ecf20Sopenharmony_ci regno = (regno << (8 - bpp)) | (0xFF >> bpp); 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci local_irq_save(flags); 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci nubus_writeb(regno, &cmap_regs->addr); 2948c2ecf20Sopenharmony_ci nop(); 2958c2ecf20Sopenharmony_ci nubus_writeb(red, &cmap_regs->lut); 2968c2ecf20Sopenharmony_ci nop(); 2978c2ecf20Sopenharmony_ci nubus_writeb(green, &cmap_regs->lut); 2988c2ecf20Sopenharmony_ci nop(); 2998c2ecf20Sopenharmony_ci nubus_writeb(blue, &cmap_regs->lut); 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci local_irq_restore(flags); 3028c2ecf20Sopenharmony_ci return 0; 3038c2ecf20Sopenharmony_ci} 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci/* Jet frame buffer */ 3068c2ecf20Sopenharmony_cistatic int jet_setpalette(unsigned int regno, unsigned int red, 3078c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 3088c2ecf20Sopenharmony_ci struct fb_info *info) 3098c2ecf20Sopenharmony_ci{ 3108c2ecf20Sopenharmony_ci struct jet_cmap_regs *cmap_regs = slot_addr; 3118c2ecf20Sopenharmony_ci unsigned long flags; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci local_irq_save(flags); 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci nubus_writeb(regno, &cmap_regs->addr); 3168c2ecf20Sopenharmony_ci nop(); 3178c2ecf20Sopenharmony_ci nubus_writeb(red, &cmap_regs->lut); 3188c2ecf20Sopenharmony_ci nop(); 3198c2ecf20Sopenharmony_ci nubus_writeb(green, &cmap_regs->lut); 3208c2ecf20Sopenharmony_ci nop(); 3218c2ecf20Sopenharmony_ci nubus_writeb(blue, &cmap_regs->lut); 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci local_irq_restore(flags); 3248c2ecf20Sopenharmony_ci return 0; 3258c2ecf20Sopenharmony_ci} 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci/* 3288c2ecf20Sopenharmony_ci * Civic framebuffer -- Quadra AV built-in video. A chip 3298c2ecf20Sopenharmony_ci * called Sebastian holds the actual color palettes, and 3308c2ecf20Sopenharmony_ci * apparently, there are two different banks of 512K RAM 3318c2ecf20Sopenharmony_ci * which can act as separate framebuffers for doing video 3328c2ecf20Sopenharmony_ci * input and viewing the screen at the same time! The 840AV 3338c2ecf20Sopenharmony_ci * Can add another 1MB RAM to give the two framebuffers 3348c2ecf20Sopenharmony_ci * 1MB RAM apiece. 3358c2ecf20Sopenharmony_ci */ 3368c2ecf20Sopenharmony_cistatic int civic_setpalette(unsigned int regno, unsigned int red, 3378c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 3388c2ecf20Sopenharmony_ci struct fb_info *info) 3398c2ecf20Sopenharmony_ci{ 3408c2ecf20Sopenharmony_ci unsigned long flags; 3418c2ecf20Sopenharmony_ci int clut_status; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci local_irq_save(flags); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci /* Set the register address */ 3468c2ecf20Sopenharmony_ci nubus_writeb(regno, &civic_cmap_regs->addr); 3478c2ecf20Sopenharmony_ci nop(); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci /* 3508c2ecf20Sopenharmony_ci * Grab a status word and do some checking; 3518c2ecf20Sopenharmony_ci * Then finally write the clut! 3528c2ecf20Sopenharmony_ci */ 3538c2ecf20Sopenharmony_ci clut_status = nubus_readb(&civic_cmap_regs->status2); 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci if ((clut_status & 0x0008) == 0) 3568c2ecf20Sopenharmony_ci { 3578c2ecf20Sopenharmony_ci#if 0 3588c2ecf20Sopenharmony_ci if ((clut_status & 0x000D) != 0) 3598c2ecf20Sopenharmony_ci { 3608c2ecf20Sopenharmony_ci nubus_writeb(0x00, &civic_cmap_regs->lut); 3618c2ecf20Sopenharmony_ci nop(); 3628c2ecf20Sopenharmony_ci nubus_writeb(0x00, &civic_cmap_regs->lut); 3638c2ecf20Sopenharmony_ci nop(); 3648c2ecf20Sopenharmony_ci } 3658c2ecf20Sopenharmony_ci#endif 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci nubus_writeb(red, &civic_cmap_regs->lut); 3688c2ecf20Sopenharmony_ci nop(); 3698c2ecf20Sopenharmony_ci nubus_writeb(green, &civic_cmap_regs->lut); 3708c2ecf20Sopenharmony_ci nop(); 3718c2ecf20Sopenharmony_ci nubus_writeb(blue, &civic_cmap_regs->lut); 3728c2ecf20Sopenharmony_ci nop(); 3738c2ecf20Sopenharmony_ci nubus_writeb(0x00, &civic_cmap_regs->lut); 3748c2ecf20Sopenharmony_ci } 3758c2ecf20Sopenharmony_ci else 3768c2ecf20Sopenharmony_ci { 3778c2ecf20Sopenharmony_ci unsigned char junk; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci junk = nubus_readb(&civic_cmap_regs->lut); 3808c2ecf20Sopenharmony_ci nop(); 3818c2ecf20Sopenharmony_ci junk = nubus_readb(&civic_cmap_regs->lut); 3828c2ecf20Sopenharmony_ci nop(); 3838c2ecf20Sopenharmony_ci junk = nubus_readb(&civic_cmap_regs->lut); 3848c2ecf20Sopenharmony_ci nop(); 3858c2ecf20Sopenharmony_ci junk = nubus_readb(&civic_cmap_regs->lut); 3868c2ecf20Sopenharmony_ci nop(); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci if ((clut_status & 0x000D) != 0) 3898c2ecf20Sopenharmony_ci { 3908c2ecf20Sopenharmony_ci nubus_writeb(0x00, &civic_cmap_regs->lut); 3918c2ecf20Sopenharmony_ci nop(); 3928c2ecf20Sopenharmony_ci nubus_writeb(0x00, &civic_cmap_regs->lut); 3938c2ecf20Sopenharmony_ci nop(); 3948c2ecf20Sopenharmony_ci } 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci nubus_writeb(red, &civic_cmap_regs->lut); 3978c2ecf20Sopenharmony_ci nop(); 3988c2ecf20Sopenharmony_ci nubus_writeb(green, &civic_cmap_regs->lut); 3998c2ecf20Sopenharmony_ci nop(); 4008c2ecf20Sopenharmony_ci nubus_writeb(blue, &civic_cmap_regs->lut); 4018c2ecf20Sopenharmony_ci nop(); 4028c2ecf20Sopenharmony_ci nubus_writeb(junk, &civic_cmap_regs->lut); 4038c2ecf20Sopenharmony_ci } 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci local_irq_restore(flags); 4068c2ecf20Sopenharmony_ci return 0; 4078c2ecf20Sopenharmony_ci} 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci/* 4108c2ecf20Sopenharmony_ci * The CSC is the framebuffer on the PowerBook 190 series 4118c2ecf20Sopenharmony_ci * (and the 5300 too, but that's a PowerMac). This function 4128c2ecf20Sopenharmony_ci * brought to you in part by the ECSC driver for MkLinux. 4138c2ecf20Sopenharmony_ci */ 4148c2ecf20Sopenharmony_cistatic int csc_setpalette(unsigned int regno, unsigned int red, 4158c2ecf20Sopenharmony_ci unsigned int green, unsigned int blue, 4168c2ecf20Sopenharmony_ci struct fb_info *info) 4178c2ecf20Sopenharmony_ci{ 4188c2ecf20Sopenharmony_ci unsigned long flags; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci local_irq_save(flags); 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci udelay(1); /* mklinux on PB 5300 waits for 260 ns */ 4238c2ecf20Sopenharmony_ci nubus_writeb(regno, &csc_cmap_regs->clut_waddr); 4248c2ecf20Sopenharmony_ci nubus_writeb(red, &csc_cmap_regs->clut_data); 4258c2ecf20Sopenharmony_ci nubus_writeb(green, &csc_cmap_regs->clut_data); 4268c2ecf20Sopenharmony_ci nubus_writeb(blue, &csc_cmap_regs->clut_data); 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci local_irq_restore(flags); 4298c2ecf20Sopenharmony_ci return 0; 4308c2ecf20Sopenharmony_ci} 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_cistatic int macfb_setcolreg(unsigned regno, unsigned red, unsigned green, 4338c2ecf20Sopenharmony_ci unsigned blue, unsigned transp, 4348c2ecf20Sopenharmony_ci struct fb_info *fb_info) 4358c2ecf20Sopenharmony_ci{ 4368c2ecf20Sopenharmony_ci /* 4378c2ecf20Sopenharmony_ci * Set a single color register. The values supplied are 4388c2ecf20Sopenharmony_ci * already rounded down to the hardware's capabilities 4398c2ecf20Sopenharmony_ci * (according to the entries in the `var' structure). 4408c2ecf20Sopenharmony_ci * Return non-zero for invalid regno. 4418c2ecf20Sopenharmony_ci */ 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci if (regno >= fb_info->cmap.len) 4448c2ecf20Sopenharmony_ci return 1; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci if (fb_info->var.bits_per_pixel <= 8) { 4478c2ecf20Sopenharmony_ci switch (fb_info->var.bits_per_pixel) { 4488c2ecf20Sopenharmony_ci case 1: 4498c2ecf20Sopenharmony_ci /* We shouldn't get here */ 4508c2ecf20Sopenharmony_ci break; 4518c2ecf20Sopenharmony_ci case 2: 4528c2ecf20Sopenharmony_ci case 4: 4538c2ecf20Sopenharmony_ci case 8: 4548c2ecf20Sopenharmony_ci if (macfb_setpalette) 4558c2ecf20Sopenharmony_ci macfb_setpalette(regno, red >> 8, green >> 8, 4568c2ecf20Sopenharmony_ci blue >> 8, fb_info); 4578c2ecf20Sopenharmony_ci else 4588c2ecf20Sopenharmony_ci return 1; 4598c2ecf20Sopenharmony_ci break; 4608c2ecf20Sopenharmony_ci } 4618c2ecf20Sopenharmony_ci } else if (regno < 16) { 4628c2ecf20Sopenharmony_ci switch (fb_info->var.bits_per_pixel) { 4638c2ecf20Sopenharmony_ci case 16: 4648c2ecf20Sopenharmony_ci if (fb_info->var.red.offset == 10) { 4658c2ecf20Sopenharmony_ci /* 1:5:5:5 */ 4668c2ecf20Sopenharmony_ci ((u32*) (fb_info->pseudo_palette))[regno] = 4678c2ecf20Sopenharmony_ci ((red & 0xf800) >> 1) | 4688c2ecf20Sopenharmony_ci ((green & 0xf800) >> 6) | 4698c2ecf20Sopenharmony_ci ((blue & 0xf800) >> 11) | 4708c2ecf20Sopenharmony_ci ((transp != 0) << 15); 4718c2ecf20Sopenharmony_ci } else { 4728c2ecf20Sopenharmony_ci /* 0:5:6:5 */ 4738c2ecf20Sopenharmony_ci ((u32*) (fb_info->pseudo_palette))[regno] = 4748c2ecf20Sopenharmony_ci ((red & 0xf800) >> 0) | 4758c2ecf20Sopenharmony_ci ((green & 0xfc00) >> 5) | 4768c2ecf20Sopenharmony_ci ((blue & 0xf800) >> 11); 4778c2ecf20Sopenharmony_ci } 4788c2ecf20Sopenharmony_ci break; 4798c2ecf20Sopenharmony_ci /* 4808c2ecf20Sopenharmony_ci * 24-bit colour almost doesn't exist on 68k Macs -- 4818c2ecf20Sopenharmony_ci * https://support.apple.com/kb/TA28634 (Old Article: 10992) 4828c2ecf20Sopenharmony_ci */ 4838c2ecf20Sopenharmony_ci case 24: 4848c2ecf20Sopenharmony_ci case 32: 4858c2ecf20Sopenharmony_ci red >>= 8; 4868c2ecf20Sopenharmony_ci green >>= 8; 4878c2ecf20Sopenharmony_ci blue >>= 8; 4888c2ecf20Sopenharmony_ci ((u32 *)(fb_info->pseudo_palette))[regno] = 4898c2ecf20Sopenharmony_ci (red << fb_info->var.red.offset) | 4908c2ecf20Sopenharmony_ci (green << fb_info->var.green.offset) | 4918c2ecf20Sopenharmony_ci (blue << fb_info->var.blue.offset); 4928c2ecf20Sopenharmony_ci break; 4938c2ecf20Sopenharmony_ci } 4948c2ecf20Sopenharmony_ci } 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci return 0; 4978c2ecf20Sopenharmony_ci} 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_cistatic const struct fb_ops macfb_ops = { 5008c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 5018c2ecf20Sopenharmony_ci .fb_setcolreg = macfb_setcolreg, 5028c2ecf20Sopenharmony_ci .fb_fillrect = cfb_fillrect, 5038c2ecf20Sopenharmony_ci .fb_copyarea = cfb_copyarea, 5048c2ecf20Sopenharmony_ci .fb_imageblit = cfb_imageblit, 5058c2ecf20Sopenharmony_ci}; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_cistatic void __init macfb_setup(char *options) 5088c2ecf20Sopenharmony_ci{ 5098c2ecf20Sopenharmony_ci char *this_opt; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci if (!options || !*options) 5128c2ecf20Sopenharmony_ci return; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci while ((this_opt = strsep(&options, ",")) != NULL) { 5158c2ecf20Sopenharmony_ci if (!*this_opt) 5168c2ecf20Sopenharmony_ci continue; 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci if (!strcmp(this_opt, "inverse")) 5198c2ecf20Sopenharmony_ci fb_invert_cmaps(); 5208c2ecf20Sopenharmony_ci else 5218c2ecf20Sopenharmony_ci if (!strcmp(this_opt, "vidtest")) 5228c2ecf20Sopenharmony_ci vidtest = 1; /* enable experimental CLUT code */ 5238c2ecf20Sopenharmony_ci } 5248c2ecf20Sopenharmony_ci} 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_cistatic void __init iounmap_macfb(void) 5278c2ecf20Sopenharmony_ci{ 5288c2ecf20Sopenharmony_ci if (dafb_cmap_regs) 5298c2ecf20Sopenharmony_ci iounmap(dafb_cmap_regs); 5308c2ecf20Sopenharmony_ci if (v8_brazil_cmap_regs) 5318c2ecf20Sopenharmony_ci iounmap(v8_brazil_cmap_regs); 5328c2ecf20Sopenharmony_ci if (rbv_cmap_regs) 5338c2ecf20Sopenharmony_ci iounmap(rbv_cmap_regs); 5348c2ecf20Sopenharmony_ci if (civic_cmap_regs) 5358c2ecf20Sopenharmony_ci iounmap(civic_cmap_regs); 5368c2ecf20Sopenharmony_ci if (csc_cmap_regs) 5378c2ecf20Sopenharmony_ci iounmap(csc_cmap_regs); 5388c2ecf20Sopenharmony_ci} 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_cistatic int __init macfb_init(void) 5418c2ecf20Sopenharmony_ci{ 5428c2ecf20Sopenharmony_ci int video_cmap_len, video_is_nubus = 0; 5438c2ecf20Sopenharmony_ci struct nubus_rsrc *ndev = NULL; 5448c2ecf20Sopenharmony_ci char *option = NULL; 5458c2ecf20Sopenharmony_ci int err; 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci if (fb_get_options("macfb", &option)) 5488c2ecf20Sopenharmony_ci return -ENODEV; 5498c2ecf20Sopenharmony_ci macfb_setup(option); 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci if (!MACH_IS_MAC) 5528c2ecf20Sopenharmony_ci return -ENODEV; 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci if (mac_bi_data.id == MAC_MODEL_Q630 || 5558c2ecf20Sopenharmony_ci mac_bi_data.id == MAC_MODEL_P588) 5568c2ecf20Sopenharmony_ci return -ENODEV; /* See valkyriefb.c */ 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF; 5598c2ecf20Sopenharmony_ci macfb_defined.yres = mac_bi_data.dimensions >> 16; 5608c2ecf20Sopenharmony_ci macfb_defined.bits_per_pixel = mac_bi_data.videodepth; 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci macfb_fix.line_length = mac_bi_data.videorow; 5638c2ecf20Sopenharmony_ci macfb_fix.smem_len = macfb_fix.line_length * macfb_defined.yres; 5648c2ecf20Sopenharmony_ci /* Note: physical address (since 2.1.127) */ 5658c2ecf20Sopenharmony_ci macfb_fix.smem_start = mac_bi_data.videoaddr; 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci /* 5688c2ecf20Sopenharmony_ci * This is actually redundant with the initial mappings. 5698c2ecf20Sopenharmony_ci * However, there are some non-obvious aspects to the way 5708c2ecf20Sopenharmony_ci * those mappings are set up, so this is in fact the safest 5718c2ecf20Sopenharmony_ci * way to ensure that this driver will work on every possible Mac 5728c2ecf20Sopenharmony_ci */ 5738c2ecf20Sopenharmony_ci fb_info.screen_base = ioremap(mac_bi_data.videoaddr, 5748c2ecf20Sopenharmony_ci macfb_fix.smem_len); 5758c2ecf20Sopenharmony_ci if (!fb_info.screen_base) 5768c2ecf20Sopenharmony_ci return -ENODEV; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci pr_info("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk\n", 5798c2ecf20Sopenharmony_ci macfb_fix.smem_start, fb_info.screen_base, 5808c2ecf20Sopenharmony_ci macfb_fix.smem_len / 1024); 5818c2ecf20Sopenharmony_ci pr_info("macfb: mode is %dx%dx%d, linelength=%d\n", 5828c2ecf20Sopenharmony_ci macfb_defined.xres, macfb_defined.yres, 5838c2ecf20Sopenharmony_ci macfb_defined.bits_per_pixel, macfb_fix.line_length); 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci /* Fill in the available video resolution */ 5868c2ecf20Sopenharmony_ci macfb_defined.xres_virtual = macfb_defined.xres; 5878c2ecf20Sopenharmony_ci macfb_defined.yres_virtual = macfb_defined.yres; 5888c2ecf20Sopenharmony_ci macfb_defined.height = PIXEL_TO_MM(macfb_defined.yres); 5898c2ecf20Sopenharmony_ci macfb_defined.width = PIXEL_TO_MM(macfb_defined.xres); 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci /* Some dummy values for timing to make fbset happy */ 5928c2ecf20Sopenharmony_ci macfb_defined.pixclock = 10000000 / macfb_defined.xres * 5938c2ecf20Sopenharmony_ci 1000 / macfb_defined.yres; 5948c2ecf20Sopenharmony_ci macfb_defined.left_margin = (macfb_defined.xres / 8) & 0xf8; 5958c2ecf20Sopenharmony_ci macfb_defined.hsync_len = (macfb_defined.xres / 8) & 0xf8; 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci switch (macfb_defined.bits_per_pixel) { 5988c2ecf20Sopenharmony_ci case 1: 5998c2ecf20Sopenharmony_ci macfb_defined.red.length = macfb_defined.bits_per_pixel; 6008c2ecf20Sopenharmony_ci macfb_defined.green.length = macfb_defined.bits_per_pixel; 6018c2ecf20Sopenharmony_ci macfb_defined.blue.length = macfb_defined.bits_per_pixel; 6028c2ecf20Sopenharmony_ci video_cmap_len = 2; 6038c2ecf20Sopenharmony_ci macfb_fix.visual = FB_VISUAL_MONO01; 6048c2ecf20Sopenharmony_ci break; 6058c2ecf20Sopenharmony_ci case 2: 6068c2ecf20Sopenharmony_ci case 4: 6078c2ecf20Sopenharmony_ci case 8: 6088c2ecf20Sopenharmony_ci macfb_defined.red.length = macfb_defined.bits_per_pixel; 6098c2ecf20Sopenharmony_ci macfb_defined.green.length = macfb_defined.bits_per_pixel; 6108c2ecf20Sopenharmony_ci macfb_defined.blue.length = macfb_defined.bits_per_pixel; 6118c2ecf20Sopenharmony_ci video_cmap_len = 1 << macfb_defined.bits_per_pixel; 6128c2ecf20Sopenharmony_ci macfb_fix.visual = FB_VISUAL_PSEUDOCOLOR; 6138c2ecf20Sopenharmony_ci break; 6148c2ecf20Sopenharmony_ci case 16: 6158c2ecf20Sopenharmony_ci macfb_defined.transp.offset = 15; 6168c2ecf20Sopenharmony_ci macfb_defined.transp.length = 1; 6178c2ecf20Sopenharmony_ci macfb_defined.red.offset = 10; 6188c2ecf20Sopenharmony_ci macfb_defined.red.length = 5; 6198c2ecf20Sopenharmony_ci macfb_defined.green.offset = 5; 6208c2ecf20Sopenharmony_ci macfb_defined.green.length = 5; 6218c2ecf20Sopenharmony_ci macfb_defined.blue.offset = 0; 6228c2ecf20Sopenharmony_ci macfb_defined.blue.length = 5; 6238c2ecf20Sopenharmony_ci video_cmap_len = 16; 6248c2ecf20Sopenharmony_ci /* 6258c2ecf20Sopenharmony_ci * Should actually be FB_VISUAL_DIRECTCOLOR, but this 6268c2ecf20Sopenharmony_ci * works too 6278c2ecf20Sopenharmony_ci */ 6288c2ecf20Sopenharmony_ci macfb_fix.visual = FB_VISUAL_TRUECOLOR; 6298c2ecf20Sopenharmony_ci break; 6308c2ecf20Sopenharmony_ci case 24: 6318c2ecf20Sopenharmony_ci case 32: 6328c2ecf20Sopenharmony_ci macfb_defined.red.offset = 16; 6338c2ecf20Sopenharmony_ci macfb_defined.red.length = 8; 6348c2ecf20Sopenharmony_ci macfb_defined.green.offset = 8; 6358c2ecf20Sopenharmony_ci macfb_defined.green.length = 8; 6368c2ecf20Sopenharmony_ci macfb_defined.blue.offset = 0; 6378c2ecf20Sopenharmony_ci macfb_defined.blue.length = 8; 6388c2ecf20Sopenharmony_ci video_cmap_len = 16; 6398c2ecf20Sopenharmony_ci macfb_fix.visual = FB_VISUAL_TRUECOLOR; 6408c2ecf20Sopenharmony_ci break; 6418c2ecf20Sopenharmony_ci default: 6428c2ecf20Sopenharmony_ci pr_err("macfb: unknown or unsupported bit depth: %d\n", 6438c2ecf20Sopenharmony_ci macfb_defined.bits_per_pixel); 6448c2ecf20Sopenharmony_ci err = -EINVAL; 6458c2ecf20Sopenharmony_ci goto fail_unmap; 6468c2ecf20Sopenharmony_ci } 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci /* 6498c2ecf20Sopenharmony_ci * We take a wild guess that if the video physical address is 6508c2ecf20Sopenharmony_ci * in nubus slot space, that the nubus card is driving video. 6518c2ecf20Sopenharmony_ci * Penguin really ought to tell us whether we are using internal 6528c2ecf20Sopenharmony_ci * video or not. 6538c2ecf20Sopenharmony_ci * Hopefully we only find one of them. Otherwise our NuBus 6548c2ecf20Sopenharmony_ci * code is really broken :-) 6558c2ecf20Sopenharmony_ci */ 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci for_each_func_rsrc(ndev) { 6588c2ecf20Sopenharmony_ci unsigned long base = ndev->board->slot_addr; 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci if (mac_bi_data.videoaddr < base || 6618c2ecf20Sopenharmony_ci mac_bi_data.videoaddr - base > 0xFFFFFF) 6628c2ecf20Sopenharmony_ci continue; 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci if (ndev->category != NUBUS_CAT_DISPLAY || 6658c2ecf20Sopenharmony_ci ndev->type != NUBUS_TYPE_VIDEO) 6668c2ecf20Sopenharmony_ci continue; 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci video_is_nubus = 1; 6698c2ecf20Sopenharmony_ci slot_addr = (unsigned char *)base; 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci switch(ndev->dr_hw) { 6728c2ecf20Sopenharmony_ci case NUBUS_DRHW_APPLE_MDC: 6738c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Mac Disp. Card"); 6748c2ecf20Sopenharmony_ci macfb_setpalette = mdc_setpalette; 6758c2ecf20Sopenharmony_ci break; 6768c2ecf20Sopenharmony_ci case NUBUS_DRHW_APPLE_TFB: 6778c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Toby"); 6788c2ecf20Sopenharmony_ci macfb_setpalette = toby_setpalette; 6798c2ecf20Sopenharmony_ci break; 6808c2ecf20Sopenharmony_ci case NUBUS_DRHW_APPLE_JET: 6818c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Jet"); 6828c2ecf20Sopenharmony_ci macfb_setpalette = jet_setpalette; 6838c2ecf20Sopenharmony_ci break; 6848c2ecf20Sopenharmony_ci default: 6858c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Generic NuBus"); 6868c2ecf20Sopenharmony_ci break; 6878c2ecf20Sopenharmony_ci } 6888c2ecf20Sopenharmony_ci } 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci /* If it's not a NuBus card, it must be internal video */ 6918c2ecf20Sopenharmony_ci if (!video_is_nubus) 6928c2ecf20Sopenharmony_ci switch (mac_bi_data.id) { 6938c2ecf20Sopenharmony_ci /* 6948c2ecf20Sopenharmony_ci * DAFB Quadras 6958c2ecf20Sopenharmony_ci * Note: these first four have the v7 DAFB, which is 6968c2ecf20Sopenharmony_ci * known to be rather unlike the ones used in the 6978c2ecf20Sopenharmony_ci * other models 6988c2ecf20Sopenharmony_ci */ 6998c2ecf20Sopenharmony_ci case MAC_MODEL_P475: 7008c2ecf20Sopenharmony_ci case MAC_MODEL_P475F: 7018c2ecf20Sopenharmony_ci case MAC_MODEL_P575: 7028c2ecf20Sopenharmony_ci case MAC_MODEL_Q605: 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci case MAC_MODEL_Q800: 7058c2ecf20Sopenharmony_ci case MAC_MODEL_Q650: 7068c2ecf20Sopenharmony_ci case MAC_MODEL_Q610: 7078c2ecf20Sopenharmony_ci case MAC_MODEL_C650: 7088c2ecf20Sopenharmony_ci case MAC_MODEL_C610: 7098c2ecf20Sopenharmony_ci case MAC_MODEL_Q700: 7108c2ecf20Sopenharmony_ci case MAC_MODEL_Q900: 7118c2ecf20Sopenharmony_ci case MAC_MODEL_Q950: 7128c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "DAFB"); 7138c2ecf20Sopenharmony_ci macfb_setpalette = dafb_setpalette; 7148c2ecf20Sopenharmony_ci dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000); 7158c2ecf20Sopenharmony_ci break; 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci /* 7188c2ecf20Sopenharmony_ci * LC II uses the V8 framebuffer 7198c2ecf20Sopenharmony_ci */ 7208c2ecf20Sopenharmony_ci case MAC_MODEL_LCII: 7218c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "V8"); 7228c2ecf20Sopenharmony_ci macfb_setpalette = v8_brazil_setpalette; 7238c2ecf20Sopenharmony_ci v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000); 7248c2ecf20Sopenharmony_ci break; 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci /* 7278c2ecf20Sopenharmony_ci * IIvi, IIvx use the "Brazil" framebuffer (which is 7288c2ecf20Sopenharmony_ci * very much like the V8, it seems, and probably uses 7298c2ecf20Sopenharmony_ci * the same DAC) 7308c2ecf20Sopenharmony_ci */ 7318c2ecf20Sopenharmony_ci case MAC_MODEL_IIVI: 7328c2ecf20Sopenharmony_ci case MAC_MODEL_IIVX: 7338c2ecf20Sopenharmony_ci case MAC_MODEL_P600: 7348c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Brazil"); 7358c2ecf20Sopenharmony_ci macfb_setpalette = v8_brazil_setpalette; 7368c2ecf20Sopenharmony_ci v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000); 7378c2ecf20Sopenharmony_ci break; 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci /* 7408c2ecf20Sopenharmony_ci * LC III (and friends) use the Sonora framebuffer 7418c2ecf20Sopenharmony_ci * Incidentally this is also used in the non-AV models 7428c2ecf20Sopenharmony_ci * of the x100 PowerMacs 7438c2ecf20Sopenharmony_ci * These do in fact seem to use the same DAC interface 7448c2ecf20Sopenharmony_ci * as the LC II. 7458c2ecf20Sopenharmony_ci */ 7468c2ecf20Sopenharmony_ci case MAC_MODEL_LCIII: 7478c2ecf20Sopenharmony_ci case MAC_MODEL_P520: 7488c2ecf20Sopenharmony_ci case MAC_MODEL_P550: 7498c2ecf20Sopenharmony_ci case MAC_MODEL_P460: 7508c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Sonora"); 7518c2ecf20Sopenharmony_ci macfb_setpalette = v8_brazil_setpalette; 7528c2ecf20Sopenharmony_ci v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000); 7538c2ecf20Sopenharmony_ci break; 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ci /* 7568c2ecf20Sopenharmony_ci * IIci and IIsi use the infamous RBV chip 7578c2ecf20Sopenharmony_ci * (the IIsi is just a rebadged and crippled 7588c2ecf20Sopenharmony_ci * IIci in a different case, BTW) 7598c2ecf20Sopenharmony_ci */ 7608c2ecf20Sopenharmony_ci case MAC_MODEL_IICI: 7618c2ecf20Sopenharmony_ci case MAC_MODEL_IISI: 7628c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "RBV"); 7638c2ecf20Sopenharmony_ci macfb_setpalette = rbv_setpalette; 7648c2ecf20Sopenharmony_ci rbv_cmap_regs = ioremap(DAC_BASE, 0x1000); 7658c2ecf20Sopenharmony_ci break; 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci /* 7688c2ecf20Sopenharmony_ci * AVs use the Civic framebuffer 7698c2ecf20Sopenharmony_ci */ 7708c2ecf20Sopenharmony_ci case MAC_MODEL_Q840: 7718c2ecf20Sopenharmony_ci case MAC_MODEL_C660: 7728c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Civic"); 7738c2ecf20Sopenharmony_ci macfb_setpalette = civic_setpalette; 7748c2ecf20Sopenharmony_ci civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000); 7758c2ecf20Sopenharmony_ci break; 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci /* 7798c2ecf20Sopenharmony_ci * Assorted weirdos 7808c2ecf20Sopenharmony_ci * We think this may be like the LC II 7818c2ecf20Sopenharmony_ci */ 7828c2ecf20Sopenharmony_ci case MAC_MODEL_LC: 7838c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "LC"); 7848c2ecf20Sopenharmony_ci if (vidtest) { 7858c2ecf20Sopenharmony_ci macfb_setpalette = v8_brazil_setpalette; 7868c2ecf20Sopenharmony_ci v8_brazil_cmap_regs = 7878c2ecf20Sopenharmony_ci ioremap(DAC_BASE, 0x1000); 7888c2ecf20Sopenharmony_ci } 7898c2ecf20Sopenharmony_ci break; 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci /* 7928c2ecf20Sopenharmony_ci * We think this may be like the LC II 7938c2ecf20Sopenharmony_ci */ 7948c2ecf20Sopenharmony_ci case MAC_MODEL_CCL: 7958c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Color Classic"); 7968c2ecf20Sopenharmony_ci if (vidtest) { 7978c2ecf20Sopenharmony_ci macfb_setpalette = v8_brazil_setpalette; 7988c2ecf20Sopenharmony_ci v8_brazil_cmap_regs = 7998c2ecf20Sopenharmony_ci ioremap(DAC_BASE, 0x1000); 8008c2ecf20Sopenharmony_ci } 8018c2ecf20Sopenharmony_ci break; 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci /* 8048c2ecf20Sopenharmony_ci * And we *do* mean "weirdos" 8058c2ecf20Sopenharmony_ci */ 8068c2ecf20Sopenharmony_ci case MAC_MODEL_TV: 8078c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Mac TV"); 8088c2ecf20Sopenharmony_ci break; 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_ci /* 8118c2ecf20Sopenharmony_ci * These don't have colour, so no need to worry 8128c2ecf20Sopenharmony_ci */ 8138c2ecf20Sopenharmony_ci case MAC_MODEL_SE30: 8148c2ecf20Sopenharmony_ci case MAC_MODEL_CLII: 8158c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Monochrome"); 8168c2ecf20Sopenharmony_ci break; 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci /* 8198c2ecf20Sopenharmony_ci * Powerbooks are particularly difficult. Many of 8208c2ecf20Sopenharmony_ci * them have separate framebuffers for external and 8218c2ecf20Sopenharmony_ci * internal video, which is admittedly pretty cool, 8228c2ecf20Sopenharmony_ci * but will be a bit of a headache to support here. 8238c2ecf20Sopenharmony_ci * Also, many of them are grayscale, and we don't 8248c2ecf20Sopenharmony_ci * really support that. 8258c2ecf20Sopenharmony_ci */ 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci /* 8288c2ecf20Sopenharmony_ci * Slot 0 ROM says TIM. No external video. B&W. 8298c2ecf20Sopenharmony_ci */ 8308c2ecf20Sopenharmony_ci case MAC_MODEL_PB140: 8318c2ecf20Sopenharmony_ci case MAC_MODEL_PB145: 8328c2ecf20Sopenharmony_ci case MAC_MODEL_PB170: 8338c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "DDC"); 8348c2ecf20Sopenharmony_ci break; 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_ci /* 8378c2ecf20Sopenharmony_ci * Internal is GSC, External (if present) is ViSC 8388c2ecf20Sopenharmony_ci */ 8398c2ecf20Sopenharmony_ci case MAC_MODEL_PB150: /* no external video */ 8408c2ecf20Sopenharmony_ci case MAC_MODEL_PB160: 8418c2ecf20Sopenharmony_ci case MAC_MODEL_PB165: 8428c2ecf20Sopenharmony_ci case MAC_MODEL_PB180: 8438c2ecf20Sopenharmony_ci case MAC_MODEL_PB210: 8448c2ecf20Sopenharmony_ci case MAC_MODEL_PB230: 8458c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "GSC"); 8468c2ecf20Sopenharmony_ci break; 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ci /* 8498c2ecf20Sopenharmony_ci * Internal is TIM, External is ViSC 8508c2ecf20Sopenharmony_ci */ 8518c2ecf20Sopenharmony_ci case MAC_MODEL_PB165C: 8528c2ecf20Sopenharmony_ci case MAC_MODEL_PB180C: 8538c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "TIM"); 8548c2ecf20Sopenharmony_ci break; 8558c2ecf20Sopenharmony_ci 8568c2ecf20Sopenharmony_ci /* 8578c2ecf20Sopenharmony_ci * Internal is CSC, External is Keystone+Ariel. 8588c2ecf20Sopenharmony_ci */ 8598c2ecf20Sopenharmony_ci case MAC_MODEL_PB190: /* external video is optional */ 8608c2ecf20Sopenharmony_ci case MAC_MODEL_PB520: 8618c2ecf20Sopenharmony_ci case MAC_MODEL_PB250: 8628c2ecf20Sopenharmony_ci case MAC_MODEL_PB270C: 8638c2ecf20Sopenharmony_ci case MAC_MODEL_PB280: 8648c2ecf20Sopenharmony_ci case MAC_MODEL_PB280C: 8658c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "CSC"); 8668c2ecf20Sopenharmony_ci macfb_setpalette = csc_setpalette; 8678c2ecf20Sopenharmony_ci csc_cmap_regs = ioremap(CSC_BASE, 0x1000); 8688c2ecf20Sopenharmony_ci break; 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci default: 8718c2ecf20Sopenharmony_ci strcpy(macfb_fix.id, "Unknown"); 8728c2ecf20Sopenharmony_ci break; 8738c2ecf20Sopenharmony_ci } 8748c2ecf20Sopenharmony_ci 8758c2ecf20Sopenharmony_ci fb_info.fbops = &macfb_ops; 8768c2ecf20Sopenharmony_ci fb_info.var = macfb_defined; 8778c2ecf20Sopenharmony_ci fb_info.fix = macfb_fix; 8788c2ecf20Sopenharmony_ci fb_info.pseudo_palette = pseudo_palette; 8798c2ecf20Sopenharmony_ci fb_info.flags = FBINFO_DEFAULT; 8808c2ecf20Sopenharmony_ci 8818c2ecf20Sopenharmony_ci err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0); 8828c2ecf20Sopenharmony_ci if (err) 8838c2ecf20Sopenharmony_ci goto fail_unmap; 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci err = register_framebuffer(&fb_info); 8868c2ecf20Sopenharmony_ci if (err) 8878c2ecf20Sopenharmony_ci goto fail_dealloc; 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci fb_info(&fb_info, "%s frame buffer device\n", fb_info.fix.id); 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci return 0; 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_cifail_dealloc: 8948c2ecf20Sopenharmony_ci fb_dealloc_cmap(&fb_info.cmap); 8958c2ecf20Sopenharmony_cifail_unmap: 8968c2ecf20Sopenharmony_ci iounmap(fb_info.screen_base); 8978c2ecf20Sopenharmony_ci iounmap_macfb(); 8988c2ecf20Sopenharmony_ci return err; 8998c2ecf20Sopenharmony_ci} 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_cimodule_init(macfb_init); 9028c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 903