blob: e707e617bf1c77006e5142221bbb614a5176882f [file] [log] [blame]
Finn Thain34c41d02009-11-04 00:47:28 +11001/*
2 * macfb.c: Generic framebuffer for Macs whose colourmaps/modes we
3 * don't know how to set.
4 *
5 * (c) 1999 David Huggins-Daines <dhd@debian.org>
6 *
7 * Primarily based on vesafb.c, by Gerd Knorr
8 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
9 *
10 * Also uses information and code from:
11 *
12 * The original macfb.c from Linux/mac68k 2.0, by Alan Cox, Juergen
13 * Mellinger, Mikael Forselius, Michael Schmitz, and others.
14 *
15 * valkyriefb.c, by Martin Costabel, Kevin Schoedel, Barry Nathan, Dan
16 * Jacobowitz, Paul Mackerras, Fabio Riccardi, and Geert Uytterhoeven.
17 *
18 * The VideoToolbox "Bugs" web page at
19 * http://rajsky.psych.nyu.edu/Tips/VideoBugs.html
20 *
21 * This code is free software. You may copy, modify, and distribute
22 * it subject to the terms and conditions of the GNU General Public
23 * License, version 2, or any later version, at your convenience.
24 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <linux/module.h>
27#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/errno.h>
29#include <linux/string.h>
30#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/delay.h>
32#include <linux/nubus.h>
33#include <linux/init.h>
34#include <linux/fb.h>
35
36#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/macintosh.h>
38#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40/* Common DAC base address for the LC, RBV, Valkyrie, and IIvx */
41#define DAC_BASE 0x50f24000
42
43/* Some addresses for the DAFB */
44#define DAFB_BASE 0xf9800200
45
46/* Address for the built-in Civic framebuffer in Quadra AVs */
Finn Thain34c41d02009-11-04 00:47:28 +110047#define CIVIC_BASE 0x50f30800
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49/* GSC (Gray Scale Controller) base address */
50#define GSC_BASE 0x50F20000
51
52/* CSC (Color Screen Controller) base address */
53#define CSC_BASE 0x50F20000
54
Finn Thain34c41d02009-11-04 00:47:28 +110055static int (*macfb_setpalette)(unsigned int regno, unsigned int red,
56 unsigned int green, unsigned int blue,
57 struct fb_info *info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Finn Thain3839d012008-11-18 20:45:22 +010059static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 unsigned char addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 unsigned char lut;
Finn Thain3839d012008-11-18 20:45:22 +010062} __iomem *v8_brazil_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Finn Thain3839d012008-11-18 20:45:22 +010064static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 unsigned char addr;
66 char pad1[3]; /* word aligned */
67 unsigned char lut;
68 char pad2[3]; /* word aligned */
69 unsigned char cntl; /* a guess as to purpose */
Finn Thain3839d012008-11-18 20:45:22 +010070} __iomem *rbv_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Finn Thain3839d012008-11-18 20:45:22 +010072static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 unsigned long reset;
74 unsigned long pad1[3];
75 unsigned char pad2[3];
76 unsigned char lut;
Finn Thain3839d012008-11-18 20:45:22 +010077} __iomem *dafb_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Finn Thain3839d012008-11-18 20:45:22 +010079static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 unsigned char addr; /* OFFSET: 0x00 */
81 unsigned char pad1[15];
82 unsigned char lut; /* OFFSET: 0x10 */
83 unsigned char pad2[15];
84 unsigned char status; /* OFFSET: 0x20 */
85 unsigned char pad3[7];
86 unsigned long vbl_addr; /* OFFSET: 0x28 */
87 unsigned int status2; /* OFFSET: 0x2C */
Finn Thain3839d012008-11-18 20:45:22 +010088} __iomem *civic_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Finn Thain3839d012008-11-18 20:45:22 +010090static struct {
Finn Thain34c41d02009-11-04 00:47:28 +110091 char pad1[0x40];
92 unsigned char clut_waddr; /* 0x40 */
93 char pad2;
94 unsigned char clut_data; /* 0x42 */
95 char pad3[0x3];
96 unsigned char clut_raddr; /* 0x46 */
Finn Thain3839d012008-11-18 20:45:22 +010097} __iomem *csc_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Finn Thain34c41d02009-11-04 00:47:28 +110099/* The registers in these structs are in NuBus slot space */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100struct mdc_cmap_regs {
101 char pad1[0x200200];
102 unsigned char addr;
103 char pad2[6];
104 unsigned char lut;
105};
106
107struct toby_cmap_regs {
108 char pad1[0x90018];
109 unsigned char lut; /* TFBClutWDataReg, offset 0x90018 */
110 char pad2[3];
111 unsigned char addr; /* TFBClutAddrReg, offset 0x9001C */
112};
113
114struct jet_cmap_regs {
115 char pad1[0xe0e000];
116 unsigned char addr;
117 unsigned char lut;
118};
119
Finn Thain34c41d02009-11-04 00:47:28 +1100120#define PIXEL_TO_MM(a) (((a)*10)/28) /* width in mm at 72 dpi */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static struct fb_var_screeninfo macfb_defined = {
Finn Thain34c41d02009-11-04 00:47:28 +1100123 .bits_per_pixel = 8,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .activate = FB_ACTIVATE_NOW,
125 .width = -1,
126 .height = -1,
127 .right_margin = 32,
128 .upper_margin = 16,
129 .lower_margin = 4,
130 .vsync_len = 4,
131 .vmode = FB_VMODE_NONINTERLACED,
132};
133
134static struct fb_fix_screeninfo macfb_fix = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 .type = FB_TYPE_PACKED_PIXELS,
136 .accel = FB_ACCEL_NONE,
137};
138
Finn Thain99e11ab2009-11-04 00:51:18 +1100139static void *slot_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140static struct fb_info fb_info;
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700141static u32 pseudo_palette[16];
Finn Thain34c41d02009-11-04 00:47:28 +1100142static int inverse;
143static int vidtest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Finn Thain34c41d02009-11-04 00:47:28 +1100145/*
146 * Unlike the Valkyrie, the DAFB cannot set individual colormap
147 * registers. Therefore, we do what the MacOS driver does (no
148 * kidding!) and simply set them one by one until we hit the one we
149 * want.
150 */
151static int dafb_setpalette(unsigned int regno, unsigned int red,
152 unsigned int green, unsigned int blue,
153 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 static int lastreg = -1;
156 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100159
160 /*
161 * fbdev will set an entire colourmap, but X won't. Hopefully
162 * this should accommodate both of them
163 */
164 if (regno != lastreg + 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 int i;
Finn Thain34c41d02009-11-04 00:47:28 +1100166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 /* Stab in the dark trying to reset the CLUT pointer */
168 nubus_writel(0, &dafb_cmap_regs->reset);
169 nop();
Finn Thain34c41d02009-11-04 00:47:28 +1100170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 /* Loop until we get to the register we want */
172 for (i = 0; i < regno; i++) {
Finn Thain34c41d02009-11-04 00:47:28 +1100173 nubus_writeb(info->cmap.red[i] >> 8,
174 &dafb_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 nop();
Finn Thain34c41d02009-11-04 00:47:28 +1100176 nubus_writeb(info->cmap.green[i] >> 8,
177 &dafb_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 nop();
Finn Thain34c41d02009-11-04 00:47:28 +1100179 nubus_writeb(info->cmap.blue[i] >> 8,
180 &dafb_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 nop();
182 }
183 }
Finn Thain34c41d02009-11-04 00:47:28 +1100184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 nubus_writeb(red, &dafb_cmap_regs->lut);
186 nop();
187 nubus_writeb(green, &dafb_cmap_regs->lut);
188 nop();
189 nubus_writeb(blue, &dafb_cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 local_irq_restore(flags);
192 lastreg = regno;
193 return 0;
194}
195
196/* V8 and Brazil seem to use the same DAC. Sonora does as well. */
Finn Thain34c41d02009-11-04 00:47:28 +1100197static int v8_brazil_setpalette(unsigned int regno, unsigned int red,
198 unsigned int green, unsigned int blue,
199 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 unsigned int bpp = info->var.bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 unsigned long flags;
203
Finn Thain34c41d02009-11-04 00:47:28 +1100204 if (bpp > 8)
205 return 1; /* failsafe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 local_irq_save(flags);
208
209 /* On these chips, the CLUT register numbers are spread out
Finn Thain34c41d02009-11-04 00:47:28 +1100210 * across the register space. Thus:
211 * In 8bpp, all regnos are valid.
212 * In 4bpp, the regnos are 0x0f, 0x1f, 0x2f, etc, etc
213 * In 2bpp, the regnos are 0x3f, 0x7f, 0xbf, 0xff
214 */
Finn Thain99e11ab2009-11-04 00:51:18 +1100215 regno = (regno << (8 - bpp)) | (0xFF >> bpp);
216 nubus_writeb(regno, &v8_brazil_cmap_regs->addr);
Finn Thain34c41d02009-11-04 00:47:28 +1100217 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 /* send one color channel at a time */
Finn Thain99e11ab2009-11-04 00:51:18 +1100220 nubus_writeb(red, &v8_brazil_cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100221 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100222 nubus_writeb(green, &v8_brazil_cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100223 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100224 nubus_writeb(blue, &v8_brazil_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Finn Thain34c41d02009-11-04 00:47:28 +1100226 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 return 0;
228}
229
Finn Thain34c41d02009-11-04 00:47:28 +1100230/* RAM-Based Video */
231static int rbv_setpalette(unsigned int regno, unsigned int red,
232 unsigned int green, unsigned int blue,
233 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 unsigned long flags;
236
Finn Thain34c41d02009-11-04 00:47:28 +1100237 if (info->var.bits_per_pixel > 8)
238 return 1; /* failsafe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 /* From the VideoToolbox driver. Seems to be saying that
243 * regno #254 and #255 are the important ones for 1-bit color,
244 * regno #252-255 are the important ones for 2-bit color, etc.
245 */
Finn Thain99e11ab2009-11-04 00:51:18 +1100246 regno += 256 - (1 << info->var.bits_per_pixel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 /* reset clut? (VideoToolbox sez "not necessary") */
Finn Thain34c41d02009-11-04 00:47:28 +1100249 nubus_writeb(0xFF, &rbv_cmap_regs->cntl);
250 nop();
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 /* tell clut which address to use. */
Finn Thain99e11ab2009-11-04 00:51:18 +1100253 nubus_writeb(regno, &rbv_cmap_regs->addr);
Finn Thain34c41d02009-11-04 00:47:28 +1100254 nop();
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 /* send one color channel at a time. */
Finn Thain99e11ab2009-11-04 00:51:18 +1100257 nubus_writeb(red, &rbv_cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100258 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100259 nubus_writeb(green, &rbv_cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100260 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100261 nubus_writeb(blue, &rbv_cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100262
263 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return 0;
265}
266
Finn Thain34c41d02009-11-04 00:47:28 +1100267/* Macintosh Display Card (8*24) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268static int mdc_setpalette(unsigned int regno, unsigned int red,
269 unsigned int green, unsigned int blue,
270 struct fb_info *info)
271{
Finn Thain99e11ab2009-11-04 00:51:18 +1100272 struct mdc_cmap_regs *cmap_regs = slot_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 unsigned long flags;
274
275 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* the nop's are there to order writes. */
Finn Thain99e11ab2009-11-04 00:51:18 +1100278 nubus_writeb(regno, &cmap_regs->addr);
Finn Thain34c41d02009-11-04 00:47:28 +1100279 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100280 nubus_writeb(red, &cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100281 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100282 nubus_writeb(green, &cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100283 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100284 nubus_writeb(blue, &cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286 local_irq_restore(flags);
287 return 0;
288}
289
290/* Toby frame buffer */
291static int toby_setpalette(unsigned int regno, unsigned int red,
292 unsigned int green, unsigned int blue,
Finn Thain34c41d02009-11-04 00:47:28 +1100293 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Finn Thain99e11ab2009-11-04 00:51:18 +1100295 struct toby_cmap_regs *cmap_regs = slot_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 unsigned int bpp = info->var.bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 unsigned long flags;
298
Finn Thain99e11ab2009-11-04 00:51:18 +1100299 red = ~red;
300 green = ~green;
301 blue = ~blue;
302 regno = (regno << (8 - bpp)) | (0xFF >> bpp);
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100305
Finn Thain99e11ab2009-11-04 00:51:18 +1100306 nubus_writeb(regno, &cmap_regs->addr);
Finn Thain34c41d02009-11-04 00:47:28 +1100307 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100308 nubus_writeb(red, &cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100309 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100310 nubus_writeb(green, &cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100311 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100312 nubus_writeb(blue, &cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 local_irq_restore(flags);
315 return 0;
316}
317
318/* Jet frame buffer */
319static int jet_setpalette(unsigned int regno, unsigned int red,
320 unsigned int green, unsigned int blue,
321 struct fb_info *info)
322{
Finn Thain99e11ab2009-11-04 00:51:18 +1100323 struct jet_cmap_regs *cmap_regs = slot_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 unsigned long flags;
325
326 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100327
328 nubus_writeb(regno, &cmap_regs->addr);
329 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100330 nubus_writeb(red, &cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100331 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100332 nubus_writeb(green, &cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100333 nop();
Finn Thain99e11ab2009-11-04 00:51:18 +1100334 nubus_writeb(blue, &cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 local_irq_restore(flags);
337 return 0;
338}
339
340/*
341 * Civic framebuffer -- Quadra AV built-in video. A chip
342 * called Sebastian holds the actual color palettes, and
Finn Thain34c41d02009-11-04 00:47:28 +1100343 * apparently, there are two different banks of 512K RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 * which can act as separate framebuffers for doing video
345 * input and viewing the screen at the same time! The 840AV
Finn Thain34c41d02009-11-04 00:47:28 +1100346 * Can add another 1MB RAM to give the two framebuffers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 * 1MB RAM apiece.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 */
Finn Thain34c41d02009-11-04 00:47:28 +1100349static int civic_setpalette(unsigned int regno, unsigned int red,
350 unsigned int green, unsigned int blue,
351 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 unsigned long flags;
354 int clut_status;
355
Finn Thain34c41d02009-11-04 00:47:28 +1100356 if (info->var.bits_per_pixel > 8)
357 return 1; /* failsafe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Finn Thain34c41d02009-11-04 00:47:28 +1100361 /* Set the register address */
362 nubus_writeb(regno, &civic_cmap_regs->addr);
363 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 /*
366 * Grab a status word and do some checking;
367 * Then finally write the clut!
368 */
369 clut_status = nubus_readb(&civic_cmap_regs->status2);
370
371 if ((clut_status & 0x0008) == 0)
372 {
373#if 0
374 if ((clut_status & 0x000D) != 0)
375 {
Finn Thain34c41d02009-11-04 00:47:28 +1100376 nubus_writeb(0x00, &civic_cmap_regs->lut);
377 nop();
378 nubus_writeb(0x00, &civic_cmap_regs->lut);
379 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
381#endif
382
Finn Thain34c41d02009-11-04 00:47:28 +1100383 nubus_writeb(red, &civic_cmap_regs->lut);
384 nop();
385 nubus_writeb(green, &civic_cmap_regs->lut);
386 nop();
387 nubus_writeb(blue, &civic_cmap_regs->lut);
388 nop();
389 nubus_writeb(0x00, &civic_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391 else
392 {
393 unsigned char junk;
394
Finn Thain34c41d02009-11-04 00:47:28 +1100395 junk = nubus_readb(&civic_cmap_regs->lut);
396 nop();
397 junk = nubus_readb(&civic_cmap_regs->lut);
398 nop();
399 junk = nubus_readb(&civic_cmap_regs->lut);
400 nop();
401 junk = nubus_readb(&civic_cmap_regs->lut);
402 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 if ((clut_status & 0x000D) != 0)
405 {
Finn Thain34c41d02009-11-04 00:47:28 +1100406 nubus_writeb(0x00, &civic_cmap_regs->lut);
407 nop();
408 nubus_writeb(0x00, &civic_cmap_regs->lut);
409 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
411
Finn Thain34c41d02009-11-04 00:47:28 +1100412 nubus_writeb(red, &civic_cmap_regs->lut);
413 nop();
414 nubus_writeb(green, &civic_cmap_regs->lut);
415 nop();
416 nubus_writeb(blue, &civic_cmap_regs->lut);
417 nop();
418 nubus_writeb(junk, &civic_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420
421 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return 0;
423}
424
425/*
426 * The CSC is the framebuffer on the PowerBook 190 series
427 * (and the 5300 too, but that's a PowerMac). This function
428 * brought to you in part by the ECSC driver for MkLinux.
429 */
Finn Thain34c41d02009-11-04 00:47:28 +1100430static int csc_setpalette(unsigned int regno, unsigned int red,
431 unsigned int green, unsigned int blue,
432 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Finn Thain99e11ab2009-11-04 00:51:18 +1100434 unsigned long flags;
435
436 local_irq_save(flags);
437
438 udelay(1); /* mklinux on PB 5300 waits for 260 ns */
Finn Thain3839d012008-11-18 20:45:22 +0100439 nubus_writeb(regno, &csc_cmap_regs->clut_waddr);
Finn Thain99e11ab2009-11-04 00:51:18 +1100440 nubus_writeb(red, &csc_cmap_regs->clut_data);
Finn Thain3839d012008-11-18 20:45:22 +0100441 nubus_writeb(green, &csc_cmap_regs->clut_data);
Finn Thain99e11ab2009-11-04 00:51:18 +1100442 nubus_writeb(blue, &csc_cmap_regs->clut_data);
443
444 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return 0;
446}
447
448static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
449 unsigned blue, unsigned transp,
450 struct fb_info *fb_info)
451{
452 /*
Finn Thain34c41d02009-11-04 00:47:28 +1100453 * Set a single color register. The values supplied are
454 * already rounded down to the hardware's capabilities
455 * (according to the entries in the `var' structure).
456 * Return non-zero for invalid regno.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 */
458
459 if (regno >= fb_info->cmap.len)
460 return 1;
461
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700462 if (fb_info->var.bits_per_pixel <= 8) {
463 switch (fb_info->var.bits_per_pixel) {
464 case 1:
465 /* We shouldn't get here */
466 break;
467 case 2:
468 case 4:
469 case 8:
470 if (macfb_setpalette)
Finn Thain99e11ab2009-11-04 00:51:18 +1100471 macfb_setpalette(regno, red >> 8, green >> 8,
472 blue >> 8, fb_info);
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700473 else
474 return 1;
475 break;
476 }
477 } else if (regno < 16) {
478 switch (fb_info->var.bits_per_pixel) {
479 case 16:
480 if (fb_info->var.red.offset == 10) {
481 /* 1:5:5:5 */
482 ((u32*) (fb_info->pseudo_palette))[regno] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 ((red & 0xf800) >> 1) |
484 ((green & 0xf800) >> 6) |
485 ((blue & 0xf800) >> 11) |
486 ((transp != 0) << 15);
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700487 } else {
488 /* 0:5:6:5 */
489 ((u32*) (fb_info->pseudo_palette))[regno] =
Finn Thain34c41d02009-11-04 00:47:28 +1100490 ((red & 0xf800) >> 0) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 ((green & 0xfc00) >> 5) |
492 ((blue & 0xf800) >> 11);
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700493 }
494 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100495 /*
496 * 24-bit colour almost doesn't exist on 68k Macs --
497 * http://support.apple.com/kb/TA28634 (Old Article: 10992)
498 */
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700499 case 24:
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700500 case 32:
501 red >>= 8;
502 green >>= 8;
503 blue >>= 8;
504 ((u32 *)(fb_info->pseudo_palette))[regno] =
Finn Thain34c41d02009-11-04 00:47:28 +1100505 (red << fb_info->var.red.offset) |
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700506 (green << fb_info->var.green.offset) |
507 (blue << fb_info->var.blue.offset);
508 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700510 }
511
512 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
515static struct fb_ops macfb_ops = {
516 .owner = THIS_MODULE,
517 .fb_setcolreg = macfb_setcolreg,
518 .fb_fillrect = cfb_fillrect,
519 .fb_copyarea = cfb_copyarea,
520 .fb_imageblit = cfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521};
522
Adrian Bunk511e7482008-07-25 19:46:26 -0700523static void __init macfb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
525 char *this_opt;
Finn Thain34c41d02009-11-04 00:47:28 +1100526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 if (!options || !*options)
528 return;
Finn Thain34c41d02009-11-04 00:47:28 +1100529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 while ((this_opt = strsep(&options, ",")) != NULL) {
Finn Thain34c41d02009-11-04 00:47:28 +1100531 if (!*this_opt)
532 continue;
533
534 if (!strcmp(this_opt, "inverse"))
535 inverse = 1;
536 else
537 if (!strcmp(this_opt, "vidtest"))
538 vidtest = 1; /* enable experimental CLUT code */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
540}
541
Amol Lad164a7652006-12-08 02:40:09 -0800542static void __init iounmap_macfb(void)
543{
Amol Lad164a7652006-12-08 02:40:09 -0800544 if (dafb_cmap_regs)
545 iounmap(dafb_cmap_regs);
546 if (v8_brazil_cmap_regs)
547 iounmap(v8_brazil_cmap_regs);
548 if (rbv_cmap_regs)
549 iounmap(rbv_cmap_regs);
550 if (civic_cmap_regs)
551 iounmap(civic_cmap_regs);
552 if (csc_cmap_regs)
553 iounmap(csc_cmap_regs);
554}
555
Al Viroed1705a2006-01-12 01:06:39 -0800556static int __init macfb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
558 int video_cmap_len, video_is_nubus = 0;
Finn Thain189e19e2018-01-13 17:37:13 -0500559 struct nubus_rsrc *ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 char *option = NULL;
Al Viroed1705a2006-01-12 01:06:39 -0800561 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 if (fb_get_options("macfb", &option))
564 return -ENODEV;
565 macfb_setup(option);
566
567 if (!MACH_IS_MAC)
Al Viroed1705a2006-01-12 01:06:39 -0800568 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Finn Thain11e8fac2009-11-04 00:43:52 +1100570 if (mac_bi_data.id == MAC_MODEL_Q630 ||
571 mac_bi_data.id == MAC_MODEL_P588)
572 return -ENODEV; /* See valkyriefb.c */
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF;
575 macfb_defined.yres = mac_bi_data.dimensions >> 16;
576 macfb_defined.bits_per_pixel = mac_bi_data.videodepth;
Finn Thain34c41d02009-11-04 00:47:28 +1100577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 macfb_fix.line_length = mac_bi_data.videorow;
Finn Thain34c41d02009-11-04 00:47:28 +1100579 macfb_fix.smem_len = macfb_fix.line_length * macfb_defined.yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 /* Note: physical address (since 2.1.127) */
Finn Thain34c41d02009-11-04 00:47:28 +1100581 macfb_fix.smem_start = mac_bi_data.videoaddr;
582
583 /*
584 * This is actually redundant with the initial mappings.
585 * However, there are some non-obvious aspects to the way
586 * those mappings are set up, so this is in fact the safest
587 * way to ensure that this driver will work on every possible Mac
588 */
Finn Thain99e11ab2009-11-04 00:51:18 +1100589 fb_info.screen_base = ioremap(mac_bi_data.videoaddr,
590 macfb_fix.smem_len);
591 if (!fb_info.screen_base)
592 return -ENODEV;
593
Finn Thaind9070fc2011-10-24 01:11:10 +1100594 pr_info("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk\n",
595 macfb_fix.smem_start, fb_info.screen_base,
596 macfb_fix.smem_len / 1024);
597 pr_info("macfb: mode is %dx%dx%d, linelength=%d\n",
598 macfb_defined.xres, macfb_defined.yres,
599 macfb_defined.bits_per_pixel, macfb_fix.line_length);
Finn Thain34c41d02009-11-04 00:47:28 +1100600
Finn Thain99e11ab2009-11-04 00:51:18 +1100601 /* Fill in the available video resolution */
Finn Thain34c41d02009-11-04 00:47:28 +1100602 macfb_defined.xres_virtual = macfb_defined.xres;
603 macfb_defined.yres_virtual = macfb_defined.yres;
604 macfb_defined.height = PIXEL_TO_MM(macfb_defined.yres);
605 macfb_defined.width = PIXEL_TO_MM(macfb_defined.xres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Finn Thain99e11ab2009-11-04 00:51:18 +1100607 /* Some dummy values for timing to make fbset happy */
Finn Thain34c41d02009-11-04 00:47:28 +1100608 macfb_defined.pixclock = 10000000 / macfb_defined.xres *
609 1000 / macfb_defined.yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 macfb_defined.left_margin = (macfb_defined.xres / 8) & 0xf8;
611 macfb_defined.hsync_len = (macfb_defined.xres / 8) & 0xf8;
612
613 switch (macfb_defined.bits_per_pixel) {
614 case 1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 macfb_defined.red.length = macfb_defined.bits_per_pixel;
616 macfb_defined.green.length = macfb_defined.bits_per_pixel;
617 macfb_defined.blue.length = macfb_defined.bits_per_pixel;
Finn Thaind9070fc2011-10-24 01:11:10 +1100618 video_cmap_len = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 macfb_fix.visual = FB_VISUAL_MONO01;
620 break;
621 case 2:
622 case 4:
623 case 8:
624 macfb_defined.red.length = macfb_defined.bits_per_pixel;
625 macfb_defined.green.length = macfb_defined.bits_per_pixel;
626 macfb_defined.blue.length = macfb_defined.bits_per_pixel;
627 video_cmap_len = 1 << macfb_defined.bits_per_pixel;
628 macfb_fix.visual = FB_VISUAL_PSEUDOCOLOR;
629 break;
630 case 16:
631 macfb_defined.transp.offset = 15;
632 macfb_defined.transp.length = 1;
633 macfb_defined.red.offset = 10;
634 macfb_defined.red.length = 5;
635 macfb_defined.green.offset = 5;
636 macfb_defined.green.length = 5;
637 macfb_defined.blue.offset = 0;
638 macfb_defined.blue.length = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 video_cmap_len = 16;
Finn Thain34c41d02009-11-04 00:47:28 +1100640 /*
641 * Should actually be FB_VISUAL_DIRECTCOLOR, but this
642 * works too
643 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 macfb_fix.visual = FB_VISUAL_TRUECOLOR;
645 break;
646 case 24:
647 case 32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 macfb_defined.red.offset = 16;
649 macfb_defined.red.length = 8;
650 macfb_defined.green.offset = 8;
651 macfb_defined.green.length = 8;
652 macfb_defined.blue.offset = 0;
653 macfb_defined.blue.length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 video_cmap_len = 16;
655 macfb_fix.visual = FB_VISUAL_TRUECOLOR;
Finn Thain99e11ab2009-11-04 00:51:18 +1100656 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 default:
Finn Thaind9070fc2011-10-24 01:11:10 +1100658 pr_err("macfb: unknown or unsupported bit depth: %d\n",
Finn Thain34c41d02009-11-04 00:47:28 +1100659 macfb_defined.bits_per_pixel);
Finn Thaind9070fc2011-10-24 01:11:10 +1100660 err = -EINVAL;
661 goto fail_unmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
663
Finn Thain34c41d02009-11-04 00:47:28 +1100664 /*
665 * We take a wild guess that if the video physical address is
666 * in nubus slot space, that the nubus card is driving video.
667 * Penguin really ought to tell us whether we are using internal
668 * video or not.
669 * Hopefully we only find one of them. Otherwise our NuBus
670 * code is really broken :-)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Finn Thain41b84812018-01-13 17:37:13 -0500673 for_each_func_rsrc(ndev) {
Finn Thain99e11ab2009-11-04 00:51:18 +1100674 unsigned long base = ndev->board->slot_addr;
675
676 if (mac_bi_data.videoaddr < base ||
677 mac_bi_data.videoaddr - base > 0xFFFFFF)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 continue;
Finn Thain99e11ab2009-11-04 00:51:18 +1100679
Finn Thain41b84812018-01-13 17:37:13 -0500680 if (ndev->category != NUBUS_CAT_DISPLAY ||
681 ndev->type != NUBUS_TYPE_VIDEO)
682 continue;
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 video_is_nubus = 1;
Finn Thain99e11ab2009-11-04 00:51:18 +1100685 slot_addr = (unsigned char *)base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 switch(ndev->dr_hw) {
688 case NUBUS_DRHW_APPLE_MDC:
Finn Thain89c223a2008-11-18 20:40:40 +0100689 strcpy(macfb_fix.id, "Mac Disp. Card");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 macfb_setpalette = mdc_setpalette;
691 macfb_defined.activate = FB_ACTIVATE_NOW;
692 break;
693 case NUBUS_DRHW_APPLE_TFB:
Finn Thain89c223a2008-11-18 20:40:40 +0100694 strcpy(macfb_fix.id, "Toby");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 macfb_setpalette = toby_setpalette;
696 macfb_defined.activate = FB_ACTIVATE_NOW;
697 break;
698 case NUBUS_DRHW_APPLE_JET:
Finn Thain89c223a2008-11-18 20:40:40 +0100699 strcpy(macfb_fix.id, "Jet");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 macfb_setpalette = jet_setpalette;
701 macfb_defined.activate = FB_ACTIVATE_NOW;
Finn Thain34c41d02009-11-04 00:47:28 +1100702 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 default:
Finn Thain89c223a2008-11-18 20:40:40 +0100704 strcpy(macfb_fix.id, "Generic NuBus");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 break;
706 }
707 }
708
709 /* If it's not a NuBus card, it must be internal video */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 if (!video_is_nubus)
Finn Thain34c41d02009-11-04 00:47:28 +1100711 switch (mac_bi_data.id) {
712 /*
713 * DAFB Quadras
714 * Note: these first four have the v7 DAFB, which is
715 * known to be rather unlike the ones used in the
716 * other models
717 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 case MAC_MODEL_P475:
719 case MAC_MODEL_P475F:
720 case MAC_MODEL_P575:
721 case MAC_MODEL_Q605:
Finn Thain34c41d02009-11-04 00:47:28 +1100722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 case MAC_MODEL_Q800:
724 case MAC_MODEL_Q650:
725 case MAC_MODEL_Q610:
726 case MAC_MODEL_C650:
727 case MAC_MODEL_C610:
728 case MAC_MODEL_Q700:
729 case MAC_MODEL_Q900:
730 case MAC_MODEL_Q950:
Finn Thain89c223a2008-11-18 20:40:40 +0100731 strcpy(macfb_fix.id, "DAFB");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 macfb_setpalette = dafb_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100734 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 break;
736
Finn Thain34c41d02009-11-04 00:47:28 +1100737 /*
738 * LC II uses the V8 framebuffer
739 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 case MAC_MODEL_LCII:
Finn Thain89c223a2008-11-18 20:40:40 +0100741 strcpy(macfb_fix.id, "V8");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 macfb_setpalette = v8_brazil_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100744 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100746
747 /*
748 * IIvi, IIvx use the "Brazil" framebuffer (which is
749 * very much like the V8, it seems, and probably uses
750 * the same DAC)
751 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 case MAC_MODEL_IIVI:
753 case MAC_MODEL_IIVX:
754 case MAC_MODEL_P600:
Finn Thain89c223a2008-11-18 20:40:40 +0100755 strcpy(macfb_fix.id, "Brazil");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 macfb_setpalette = v8_brazil_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100758 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100760
761 /*
762 * LC III (and friends) use the Sonora framebuffer
763 * Incidentally this is also used in the non-AV models
764 * of the x100 PowerMacs
765 * These do in fact seem to use the same DAC interface
766 * as the LC II.
767 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 case MAC_MODEL_LCIII:
769 case MAC_MODEL_P520:
770 case MAC_MODEL_P550:
771 case MAC_MODEL_P460:
Finn Thain89c223a2008-11-18 20:40:40 +0100772 strcpy(macfb_fix.id, "Sonora");
Finn Thaind9070fc2011-10-24 01:11:10 +1100773 macfb_setpalette = v8_brazil_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100775 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 break;
777
Finn Thain34c41d02009-11-04 00:47:28 +1100778 /*
779 * IIci and IIsi use the infamous RBV chip
780 * (the IIsi is just a rebadged and crippled
781 * IIci in a different case, BTW)
782 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 case MAC_MODEL_IICI:
784 case MAC_MODEL_IISI:
Finn Thain89c223a2008-11-18 20:40:40 +0100785 strcpy(macfb_fix.id, "RBV");
Finn Thaind9070fc2011-10-24 01:11:10 +1100786 macfb_setpalette = rbv_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100788 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 break;
790
Finn Thain34c41d02009-11-04 00:47:28 +1100791 /*
792 * AVs use the Civic framebuffer
793 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 case MAC_MODEL_Q840:
795 case MAC_MODEL_C660:
Finn Thain89c223a2008-11-18 20:40:40 +0100796 strcpy(macfb_fix.id, "Civic");
Finn Thaind9070fc2011-10-24 01:11:10 +1100797 macfb_setpalette = civic_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100799 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 break;
801
802
Finn Thain34c41d02009-11-04 00:47:28 +1100803 /*
804 * Assorted weirdos
805 * We think this may be like the LC II
806 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 case MAC_MODEL_LC:
Finn Thaind9070fc2011-10-24 01:11:10 +1100808 strcpy(macfb_fix.id, "LC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 if (vidtest) {
810 macfb_setpalette = v8_brazil_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 v8_brazil_cmap_regs =
812 ioremap(DAC_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100813 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100816
817 /*
818 * We think this may be like the LC II
819 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 case MAC_MODEL_CCL:
Finn Thaind9070fc2011-10-24 01:11:10 +1100821 strcpy(macfb_fix.id, "Color Classic");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (vidtest) {
823 macfb_setpalette = v8_brazil_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 v8_brazil_cmap_regs =
825 ioremap(DAC_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100826 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 break;
829
Finn Thain34c41d02009-11-04 00:47:28 +1100830 /*
831 * And we *do* mean "weirdos"
832 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 case MAC_MODEL_TV:
Finn Thain89c223a2008-11-18 20:40:40 +0100834 strcpy(macfb_fix.id, "Mac TV");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 break;
836
Finn Thain34c41d02009-11-04 00:47:28 +1100837 /*
838 * These don't have colour, so no need to worry
839 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 case MAC_MODEL_SE30:
841 case MAC_MODEL_CLII:
Finn Thain89c223a2008-11-18 20:40:40 +0100842 strcpy(macfb_fix.id, "Monochrome");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 break;
844
Finn Thain34c41d02009-11-04 00:47:28 +1100845 /*
846 * Powerbooks are particularly difficult. Many of
847 * them have separate framebuffers for external and
848 * internal video, which is admittedly pretty cool,
849 * but will be a bit of a headache to support here.
850 * Also, many of them are grayscale, and we don't
851 * really support that.
852 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Finn Thain99e11ab2009-11-04 00:51:18 +1100854 /*
855 * Slot 0 ROM says TIM. No external video. B&W.
856 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 case MAC_MODEL_PB140:
858 case MAC_MODEL_PB145:
859 case MAC_MODEL_PB170:
Finn Thain89c223a2008-11-18 20:40:40 +0100860 strcpy(macfb_fix.id, "DDC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 break;
862
Finn Thain34c41d02009-11-04 00:47:28 +1100863 /*
864 * Internal is GSC, External (if present) is ViSC
865 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 case MAC_MODEL_PB150: /* no external video */
867 case MAC_MODEL_PB160:
868 case MAC_MODEL_PB165:
869 case MAC_MODEL_PB180:
870 case MAC_MODEL_PB210:
871 case MAC_MODEL_PB230:
Finn Thain89c223a2008-11-18 20:40:40 +0100872 strcpy(macfb_fix.id, "GSC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 break;
874
Finn Thain34c41d02009-11-04 00:47:28 +1100875 /*
876 * Internal is TIM, External is ViSC
877 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 case MAC_MODEL_PB165C:
879 case MAC_MODEL_PB180C:
Finn Thain89c223a2008-11-18 20:40:40 +0100880 strcpy(macfb_fix.id, "TIM");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 break;
882
Finn Thain34c41d02009-11-04 00:47:28 +1100883 /*
884 * Internal is CSC, External is Keystone+Ariel.
885 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 case MAC_MODEL_PB190: /* external video is optional */
887 case MAC_MODEL_PB520:
888 case MAC_MODEL_PB250:
889 case MAC_MODEL_PB270C:
890 case MAC_MODEL_PB280:
891 case MAC_MODEL_PB280C:
Finn Thain89c223a2008-11-18 20:40:40 +0100892 strcpy(macfb_fix.id, "CSC");
Finn Thaind9070fc2011-10-24 01:11:10 +1100893 macfb_setpalette = csc_setpalette;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 csc_cmap_regs = ioremap(CSC_BASE, 0x1000);
Finn Thaind9070fc2011-10-24 01:11:10 +1100895 macfb_defined.activate = FB_ACTIVATE_NOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 default:
Finn Thain89c223a2008-11-18 20:40:40 +0100899 strcpy(macfb_fix.id, "Unknown");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 break;
901 }
902
903 fb_info.fbops = &macfb_ops;
904 fb_info.var = macfb_defined;
905 fb_info.fix = macfb_fix;
906 fb_info.pseudo_palette = pseudo_palette;
907 fb_info.flags = FBINFO_DEFAULT;
908
Finn Thain89c223a2008-11-18 20:40:40 +0100909 err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
910 if (err)
911 goto fail_unmap;
Finn Thain34c41d02009-11-04 00:47:28 +1100912
Al Viroed1705a2006-01-12 01:06:39 -0800913 err = register_framebuffer(&fb_info);
Finn Thain89c223a2008-11-18 20:40:40 +0100914 if (err)
915 goto fail_dealloc;
916
Joe Perches31b67802013-09-19 18:35:55 -0700917 fb_info(&fb_info, "%s frame buffer device\n", fb_info.fix.id);
Finn Thaind9070fc2011-10-24 01:11:10 +1100918
Finn Thain89c223a2008-11-18 20:40:40 +0100919 return 0;
920
921fail_dealloc:
922 fb_dealloc_cmap(&fb_info.cmap);
923fail_unmap:
924 iounmap(fb_info.screen_base);
925 iounmap_macfb();
Al Viroed1705a2006-01-12 01:06:39 -0800926 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
928
929module_init(macfb_init);
930MODULE_LICENSE("GPL");