blob: 8b246ee7c0691135f6a8f2726a0a4299f0dc5480 [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>
37#include <asm/bootinfo.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/macintosh.h>
39#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/* Common DAC base address for the LC, RBV, Valkyrie, and IIvx */
42#define DAC_BASE 0x50f24000
43
44/* Some addresses for the DAFB */
45#define DAFB_BASE 0xf9800200
46
47/* Address for the built-in Civic framebuffer in Quadra AVs */
Finn Thain34c41d02009-11-04 00:47:28 +110048#define CIVIC_BASE 0x50f30800
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/* GSC (Gray Scale Controller) base address */
51#define GSC_BASE 0x50F20000
52
53/* CSC (Color Screen Controller) base address */
54#define CSC_BASE 0x50F20000
55
Finn Thain34c41d02009-11-04 00:47:28 +110056static int (*macfb_setpalette)(unsigned int regno, unsigned int red,
57 unsigned int green, unsigned int blue,
58 struct fb_info *info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Finn Thain3839d012008-11-18 20:45:22 +010060static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 unsigned char addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 unsigned char lut;
Finn Thain3839d012008-11-18 20:45:22 +010063} __iomem *v8_brazil_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Finn Thain3839d012008-11-18 20:45:22 +010065static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 unsigned char addr;
67 char pad1[3]; /* word aligned */
68 unsigned char lut;
69 char pad2[3]; /* word aligned */
70 unsigned char cntl; /* a guess as to purpose */
Finn Thain3839d012008-11-18 20:45:22 +010071} __iomem *rbv_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Finn Thain3839d012008-11-18 20:45:22 +010073static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 unsigned long reset;
75 unsigned long pad1[3];
76 unsigned char pad2[3];
77 unsigned char lut;
Finn Thain3839d012008-11-18 20:45:22 +010078} __iomem *dafb_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Finn Thain3839d012008-11-18 20:45:22 +010080static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 unsigned char addr; /* OFFSET: 0x00 */
82 unsigned char pad1[15];
83 unsigned char lut; /* OFFSET: 0x10 */
84 unsigned char pad2[15];
85 unsigned char status; /* OFFSET: 0x20 */
86 unsigned char pad3[7];
87 unsigned long vbl_addr; /* OFFSET: 0x28 */
88 unsigned int status2; /* OFFSET: 0x2C */
Finn Thain3839d012008-11-18 20:45:22 +010089} __iomem *civic_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Finn Thain3839d012008-11-18 20:45:22 +010091static struct {
Finn Thain34c41d02009-11-04 00:47:28 +110092 char pad1[0x40];
93 unsigned char clut_waddr; /* 0x40 */
94 char pad2;
95 unsigned char clut_data; /* 0x42 */
96 char pad3[0x3];
97 unsigned char clut_raddr; /* 0x46 */
Finn Thain3839d012008-11-18 20:45:22 +010098} __iomem *csc_cmap_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Finn Thain34c41d02009-11-04 00:47:28 +1100100/* The registers in these structs are in NuBus slot space */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101struct mdc_cmap_regs {
102 char pad1[0x200200];
103 unsigned char addr;
104 char pad2[6];
105 unsigned char lut;
106};
107
108struct toby_cmap_regs {
109 char pad1[0x90018];
110 unsigned char lut; /* TFBClutWDataReg, offset 0x90018 */
111 char pad2[3];
112 unsigned char addr; /* TFBClutAddrReg, offset 0x9001C */
113};
114
115struct jet_cmap_regs {
116 char pad1[0xe0e000];
117 unsigned char addr;
118 unsigned char lut;
119};
120
Finn Thain34c41d02009-11-04 00:47:28 +1100121#define PIXEL_TO_MM(a) (((a)*10)/28) /* width in mm at 72 dpi */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123static int video_slot = 0;
124
125static struct fb_var_screeninfo macfb_defined = {
Finn Thain34c41d02009-11-04 00:47:28 +1100126 .bits_per_pixel = 8,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 .activate = FB_ACTIVATE_NOW,
128 .width = -1,
129 .height = -1,
130 .right_margin = 32,
131 .upper_margin = 16,
132 .lower_margin = 4,
133 .vsync_len = 4,
134 .vmode = FB_VMODE_NONINTERLACED,
135};
136
137static struct fb_fix_screeninfo macfb_fix = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .type = FB_TYPE_PACKED_PIXELS,
139 .accel = FB_ACCEL_NONE,
140};
141
142static struct fb_info fb_info;
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700143static u32 pseudo_palette[16];
Finn Thain34c41d02009-11-04 00:47:28 +1100144static int inverse;
145static int vidtest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Finn Thain34c41d02009-11-04 00:47:28 +1100147/*
148 * Unlike the Valkyrie, the DAFB cannot set individual colormap
149 * registers. Therefore, we do what the MacOS driver does (no
150 * kidding!) and simply set them one by one until we hit the one we
151 * want.
152 */
153static int dafb_setpalette(unsigned int regno, unsigned int red,
154 unsigned int green, unsigned int blue,
155 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 static int lastreg = -1;
158 unsigned long flags;
159
160 red >>= 8;
161 green >>= 8;
162 blue >>= 8;
163
164 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100165
166 /*
167 * fbdev will set an entire colourmap, but X won't. Hopefully
168 * this should accommodate both of them
169 */
170 if (regno != lastreg + 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 int i;
Finn Thain34c41d02009-11-04 00:47:28 +1100172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 /* Stab in the dark trying to reset the CLUT pointer */
174 nubus_writel(0, &dafb_cmap_regs->reset);
175 nop();
Finn Thain34c41d02009-11-04 00:47:28 +1100176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /* Loop until we get to the register we want */
178 for (i = 0; i < regno; i++) {
Finn Thain34c41d02009-11-04 00:47:28 +1100179 nubus_writeb(info->cmap.red[i] >> 8,
180 &dafb_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 nop();
Finn Thain34c41d02009-11-04 00:47:28 +1100182 nubus_writeb(info->cmap.green[i] >> 8,
183 &dafb_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 nop();
Finn Thain34c41d02009-11-04 00:47:28 +1100185 nubus_writeb(info->cmap.blue[i] >> 8,
186 &dafb_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 nop();
188 }
189 }
Finn Thain34c41d02009-11-04 00:47:28 +1100190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 nubus_writeb(red, &dafb_cmap_regs->lut);
192 nop();
193 nubus_writeb(green, &dafb_cmap_regs->lut);
194 nop();
195 nubus_writeb(blue, &dafb_cmap_regs->lut);
Finn Thain34c41d02009-11-04 00:47:28 +1100196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 local_irq_restore(flags);
198 lastreg = regno;
199 return 0;
200}
201
202/* V8 and Brazil seem to use the same DAC. Sonora does as well. */
Finn Thain34c41d02009-11-04 00:47:28 +1100203static int v8_brazil_setpalette(unsigned int regno, unsigned int red,
204 unsigned int green, unsigned int blue,
205 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
207 unsigned int bpp = info->var.bits_per_pixel;
208 unsigned char _red =red>>8;
209 unsigned char _green=green>>8;
210 unsigned char _blue =blue>>8;
211 unsigned char _regno;
212 unsigned long flags;
213
Finn Thain34c41d02009-11-04 00:47:28 +1100214 if (bpp > 8)
215 return 1; /* failsafe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 local_irq_save(flags);
218
219 /* On these chips, the CLUT register numbers are spread out
Finn Thain34c41d02009-11-04 00:47:28 +1100220 * across the register space. Thus:
221 * In 8bpp, all regnos are valid.
222 * In 4bpp, the regnos are 0x0f, 0x1f, 0x2f, etc, etc
223 * In 2bpp, the regnos are 0x3f, 0x7f, 0xbf, 0xff
224 */
225 _regno = (regno << (8 - bpp)) | (0xFF >> bpp);
226 nubus_writeb(_regno, &v8_brazil_cmap_regs->addr);
227 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 /* send one color channel at a time */
Finn Thain34c41d02009-11-04 00:47:28 +1100230 nubus_writeb(_red, &v8_brazil_cmap_regs->lut);
231 nop();
232 nubus_writeb(_green, &v8_brazil_cmap_regs->lut);
233 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 nubus_writeb(_blue, &v8_brazil_cmap_regs->lut);
235
Finn Thain34c41d02009-11-04 00:47:28 +1100236 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return 0;
238}
239
Finn Thain34c41d02009-11-04 00:47:28 +1100240/* RAM-Based Video */
241static int rbv_setpalette(unsigned int regno, unsigned int red,
242 unsigned int green, unsigned int blue,
243 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 /* use MSBs */
246 unsigned char _red =red>>8;
247 unsigned char _green=green>>8;
248 unsigned char _blue =blue>>8;
249 unsigned char _regno;
250 unsigned long flags;
251
Finn Thain34c41d02009-11-04 00:47:28 +1100252 if (info->var.bits_per_pixel > 8)
253 return 1; /* failsafe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /* From the VideoToolbox driver. Seems to be saying that
258 * regno #254 and #255 are the important ones for 1-bit color,
259 * regno #252-255 are the important ones for 2-bit color, etc.
260 */
261 _regno = regno + (256-(1 << info->var.bits_per_pixel));
262
263 /* reset clut? (VideoToolbox sez "not necessary") */
Finn Thain34c41d02009-11-04 00:47:28 +1100264 nubus_writeb(0xFF, &rbv_cmap_regs->cntl);
265 nop();
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 /* tell clut which address to use. */
Finn Thain34c41d02009-11-04 00:47:28 +1100268 nubus_writeb(_regno, &rbv_cmap_regs->addr);
269 nop();
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 /* send one color channel at a time. */
Finn Thain34c41d02009-11-04 00:47:28 +1100272 nubus_writeb(_red, &rbv_cmap_regs->lut);
273 nop();
274 nubus_writeb(_green, &rbv_cmap_regs->lut);
275 nop();
276 nubus_writeb(_blue, &rbv_cmap_regs->lut);
277
278 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 return 0;
280}
281
Finn Thain34c41d02009-11-04 00:47:28 +1100282/* Macintosh Display Card (8*24) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283static int mdc_setpalette(unsigned int regno, unsigned int red,
284 unsigned int green, unsigned int blue,
285 struct fb_info *info)
286{
287 volatile struct mdc_cmap_regs *cmap_regs =
288 nubus_slot_addr(video_slot);
289 /* use MSBs */
290 unsigned char _red =red>>8;
291 unsigned char _green=green>>8;
292 unsigned char _blue =blue>>8;
293 unsigned char _regno=regno;
294 unsigned long flags;
295
296 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 /* the nop's are there to order writes. */
Finn Thain34c41d02009-11-04 00:47:28 +1100299 nubus_writeb(_regno, &cmap_regs->addr);
300 nop();
301 nubus_writeb(_red, &cmap_regs->lut);
302 nop();
303 nubus_writeb(_green, &cmap_regs->lut);
304 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 nubus_writeb(_blue, &cmap_regs->lut);
306
307 local_irq_restore(flags);
308 return 0;
309}
310
311/* Toby frame buffer */
312static int toby_setpalette(unsigned int regno, unsigned int red,
313 unsigned int green, unsigned int blue,
Finn Thain34c41d02009-11-04 00:47:28 +1100314 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 volatile struct toby_cmap_regs *cmap_regs =
317 nubus_slot_addr(video_slot);
318 unsigned int bpp = info->var.bits_per_pixel;
319 /* use MSBs */
320 unsigned char _red =~(red>>8);
321 unsigned char _green=~(green>>8);
322 unsigned char _blue =~(blue>>8);
323 unsigned char _regno = (regno << (8 - bpp)) | (0xFF >> bpp);
324 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();
330 nubus_writeb(_red, &cmap_regs->lut);
331 nop();
332 nubus_writeb(_green, &cmap_regs->lut);
333 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 nubus_writeb(_blue, &cmap_regs->lut);
335
336 local_irq_restore(flags);
337 return 0;
338}
339
340/* Jet frame buffer */
341static int jet_setpalette(unsigned int regno, unsigned int red,
342 unsigned int green, unsigned int blue,
343 struct fb_info *info)
344{
345 volatile struct jet_cmap_regs *cmap_regs =
346 nubus_slot_addr(video_slot);
347 /* use MSBs */
348 unsigned char _red = (red>>8);
349 unsigned char _green = (green>>8);
350 unsigned char _blue = (blue>>8);
351 unsigned long flags;
352
353 local_irq_save(flags);
Finn Thain34c41d02009-11-04 00:47:28 +1100354
355 nubus_writeb(regno, &cmap_regs->addr);
356 nop();
357 nubus_writeb(_red, &cmap_regs->lut);
358 nop();
359 nubus_writeb(_green, &cmap_regs->lut);
360 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 nubus_writeb(_blue, &cmap_regs->lut);
362
363 local_irq_restore(flags);
364 return 0;
365}
366
367/*
368 * Civic framebuffer -- Quadra AV built-in video. A chip
369 * called Sebastian holds the actual color palettes, and
Finn Thain34c41d02009-11-04 00:47:28 +1100370 * apparently, there are two different banks of 512K RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 * which can act as separate framebuffers for doing video
372 * input and viewing the screen at the same time! The 840AV
Finn Thain34c41d02009-11-04 00:47:28 +1100373 * Can add another 1MB RAM to give the two framebuffers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 * 1MB RAM apiece.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 */
Finn Thain34c41d02009-11-04 00:47:28 +1100376static int civic_setpalette(unsigned int regno, unsigned int red,
377 unsigned int green, unsigned int blue,
378 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 unsigned long flags;
381 int clut_status;
382
Finn Thain34c41d02009-11-04 00:47:28 +1100383 if (info->var.bits_per_pixel > 8)
384 return 1; /* failsafe */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 red >>= 8;
387 green >>= 8;
388 blue >>= 8;
389
390 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Finn Thain34c41d02009-11-04 00:47:28 +1100392 /* Set the register address */
393 nubus_writeb(regno, &civic_cmap_regs->addr);
394 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 /*
397 * Grab a status word and do some checking;
398 * Then finally write the clut!
399 */
400 clut_status = nubus_readb(&civic_cmap_regs->status2);
401
402 if ((clut_status & 0x0008) == 0)
403 {
404#if 0
405 if ((clut_status & 0x000D) != 0)
406 {
Finn Thain34c41d02009-11-04 00:47:28 +1100407 nubus_writeb(0x00, &civic_cmap_regs->lut);
408 nop();
409 nubus_writeb(0x00, &civic_cmap_regs->lut);
410 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 }
412#endif
413
Finn Thain34c41d02009-11-04 00:47:28 +1100414 nubus_writeb(red, &civic_cmap_regs->lut);
415 nop();
416 nubus_writeb(green, &civic_cmap_regs->lut);
417 nop();
418 nubus_writeb(blue, &civic_cmap_regs->lut);
419 nop();
420 nubus_writeb(0x00, &civic_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
422 else
423 {
424 unsigned char junk;
425
Finn Thain34c41d02009-11-04 00:47:28 +1100426 junk = nubus_readb(&civic_cmap_regs->lut);
427 nop();
428 junk = nubus_readb(&civic_cmap_regs->lut);
429 nop();
430 junk = nubus_readb(&civic_cmap_regs->lut);
431 nop();
432 junk = nubus_readb(&civic_cmap_regs->lut);
433 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 if ((clut_status & 0x000D) != 0)
436 {
Finn Thain34c41d02009-11-04 00:47:28 +1100437 nubus_writeb(0x00, &civic_cmap_regs->lut);
438 nop();
439 nubus_writeb(0x00, &civic_cmap_regs->lut);
440 nop();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
442
Finn Thain34c41d02009-11-04 00:47:28 +1100443 nubus_writeb(red, &civic_cmap_regs->lut);
444 nop();
445 nubus_writeb(green, &civic_cmap_regs->lut);
446 nop();
447 nubus_writeb(blue, &civic_cmap_regs->lut);
448 nop();
449 nubus_writeb(junk, &civic_cmap_regs->lut);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 }
451
452 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 return 0;
454}
455
456/*
457 * The CSC is the framebuffer on the PowerBook 190 series
458 * (and the 5300 too, but that's a PowerMac). This function
459 * brought to you in part by the ECSC driver for MkLinux.
460 */
Finn Thain34c41d02009-11-04 00:47:28 +1100461static int csc_setpalette(unsigned int regno, unsigned int red,
462 unsigned int green, unsigned int blue,
463 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 mdelay(1);
Finn Thain3839d012008-11-18 20:45:22 +0100466 nubus_writeb(regno, &csc_cmap_regs->clut_waddr);
467 nubus_writeb(red, &csc_cmap_regs->clut_data);
468 nubus_writeb(green, &csc_cmap_regs->clut_data);
469 nubus_writeb(blue, &csc_cmap_regs->clut_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return 0;
471}
472
473static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
474 unsigned blue, unsigned transp,
475 struct fb_info *fb_info)
476{
477 /*
Finn Thain34c41d02009-11-04 00:47:28 +1100478 * Set a single color register. The values supplied are
479 * already rounded down to the hardware's capabilities
480 * (according to the entries in the `var' structure).
481 * Return non-zero for invalid regno.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 */
483
484 if (regno >= fb_info->cmap.len)
485 return 1;
486
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700487 if (fb_info->var.bits_per_pixel <= 8) {
488 switch (fb_info->var.bits_per_pixel) {
489 case 1:
490 /* We shouldn't get here */
491 break;
492 case 2:
493 case 4:
494 case 8:
495 if (macfb_setpalette)
496 macfb_setpalette(regno, red, green, blue,
497 fb_info);
498 else
499 return 1;
500 break;
501 }
502 } else if (regno < 16) {
503 switch (fb_info->var.bits_per_pixel) {
504 case 16:
505 if (fb_info->var.red.offset == 10) {
506 /* 1:5:5:5 */
507 ((u32*) (fb_info->pseudo_palette))[regno] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 ((red & 0xf800) >> 1) |
509 ((green & 0xf800) >> 6) |
510 ((blue & 0xf800) >> 11) |
511 ((transp != 0) << 15);
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700512 } else {
513 /* 0:5:6:5 */
514 ((u32*) (fb_info->pseudo_palette))[regno] =
Finn Thain34c41d02009-11-04 00:47:28 +1100515 ((red & 0xf800) >> 0) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 ((green & 0xfc00) >> 5) |
517 ((blue & 0xf800) >> 11);
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700518 }
519 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100520 /*
521 * 24-bit colour almost doesn't exist on 68k Macs --
522 * http://support.apple.com/kb/TA28634 (Old Article: 10992)
523 */
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700524 case 24:
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700525 case 32:
526 red >>= 8;
527 green >>= 8;
528 blue >>= 8;
529 ((u32 *)(fb_info->pseudo_palette))[regno] =
Finn Thain34c41d02009-11-04 00:47:28 +1100530 (red << fb_info->var.red.offset) |
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700531 (green << fb_info->var.green.offset) |
532 (blue << fb_info->var.blue.offset);
533 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
Antonino A. Daplas24fc7222007-07-17 04:05:37 -0700535 }
536
537 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538}
539
540static struct fb_ops macfb_ops = {
541 .owner = THIS_MODULE,
542 .fb_setcolreg = macfb_setcolreg,
543 .fb_fillrect = cfb_fillrect,
544 .fb_copyarea = cfb_copyarea,
545 .fb_imageblit = cfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546};
547
Adrian Bunk511e7482008-07-25 19:46:26 -0700548static void __init macfb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
550 char *this_opt;
Finn Thain34c41d02009-11-04 00:47:28 +1100551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (!options || !*options)
553 return;
Finn Thain34c41d02009-11-04 00:47:28 +1100554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 while ((this_opt = strsep(&options, ",")) != NULL) {
Finn Thain34c41d02009-11-04 00:47:28 +1100556 if (!*this_opt)
557 continue;
558
559 if (!strcmp(this_opt, "inverse"))
560 inverse = 1;
561 else
562 if (!strcmp(this_opt, "vidtest"))
563 vidtest = 1; /* enable experimental CLUT code */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565}
566
Amol Lad164a7652006-12-08 02:40:09 -0800567static void __init iounmap_macfb(void)
568{
Amol Lad164a7652006-12-08 02:40:09 -0800569 if (dafb_cmap_regs)
570 iounmap(dafb_cmap_regs);
571 if (v8_brazil_cmap_regs)
572 iounmap(v8_brazil_cmap_regs);
573 if (rbv_cmap_regs)
574 iounmap(rbv_cmap_regs);
575 if (civic_cmap_regs)
576 iounmap(civic_cmap_regs);
577 if (csc_cmap_regs)
578 iounmap(csc_cmap_regs);
579}
580
Al Viroed1705a2006-01-12 01:06:39 -0800581static int __init macfb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
583 int video_cmap_len, video_is_nubus = 0;
584 struct nubus_dev* ndev = NULL;
585 char *option = NULL;
Al Viroed1705a2006-01-12 01:06:39 -0800586 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 if (fb_get_options("macfb", &option))
589 return -ENODEV;
590 macfb_setup(option);
591
592 if (!MACH_IS_MAC)
Al Viroed1705a2006-01-12 01:06:39 -0800593 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Finn Thain11e8fac2009-11-04 00:43:52 +1100595 if (mac_bi_data.id == MAC_MODEL_Q630 ||
596 mac_bi_data.id == MAC_MODEL_P588)
597 return -ENODEV; /* See valkyriefb.c */
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF;
600 macfb_defined.yres = mac_bi_data.dimensions >> 16;
601 macfb_defined.bits_per_pixel = mac_bi_data.videodepth;
Finn Thain34c41d02009-11-04 00:47:28 +1100602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 macfb_fix.line_length = mac_bi_data.videorow;
Finn Thain34c41d02009-11-04 00:47:28 +1100604 macfb_fix.smem_len = macfb_fix.line_length * macfb_defined.yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /* Note: physical address (since 2.1.127) */
Finn Thain34c41d02009-11-04 00:47:28 +1100606 macfb_fix.smem_start = mac_bi_data.videoaddr;
607
608 /*
609 * This is actually redundant with the initial mappings.
610 * However, there are some non-obvious aspects to the way
611 * those mappings are set up, so this is in fact the safest
612 * way to ensure that this driver will work on every possible Mac
613 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 fb_info.screen_base = ioremap(mac_bi_data.videoaddr, macfb_fix.smem_len);
615
616 printk("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk\n",
Finn Thain34c41d02009-11-04 00:47:28 +1100617 macfb_fix.smem_start, fb_info.screen_base,
618 macfb_fix.smem_len / 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 printk("macfb: mode is %dx%dx%d, linelength=%d\n",
Finn Thain34c41d02009-11-04 00:47:28 +1100620 macfb_defined.xres, macfb_defined.yres,
621 macfb_defined.bits_per_pixel, macfb_fix.line_length);
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 /*
Finn Thain34c41d02009-11-04 00:47:28 +1100624 * Fill in the available video resolution
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 */
Finn Thain34c41d02009-11-04 00:47:28 +1100626 macfb_defined.xres_virtual = macfb_defined.xres;
627 macfb_defined.yres_virtual = macfb_defined.yres;
628 macfb_defined.height = PIXEL_TO_MM(macfb_defined.yres);
629 macfb_defined.width = PIXEL_TO_MM(macfb_defined.xres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 printk("macfb: scrolling: redraw\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 /* some dummy values for timing to make fbset happy */
Finn Thain34c41d02009-11-04 00:47:28 +1100634 macfb_defined.pixclock = 10000000 / macfb_defined.xres *
635 1000 / macfb_defined.yres;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 macfb_defined.left_margin = (macfb_defined.xres / 8) & 0xf8;
637 macfb_defined.hsync_len = (macfb_defined.xres / 8) & 0xf8;
638
639 switch (macfb_defined.bits_per_pixel) {
640 case 1:
Finn Thain34c41d02009-11-04 00:47:28 +1100641 /*
642 * XXX: I think this will catch any program that tries
643 * to do FBIO_PUTCMAP when the visual is monochrome.
644 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 macfb_defined.red.length = macfb_defined.bits_per_pixel;
646 macfb_defined.green.length = macfb_defined.bits_per_pixel;
647 macfb_defined.blue.length = macfb_defined.bits_per_pixel;
648 video_cmap_len = 0;
649 macfb_fix.visual = FB_VISUAL_MONO01;
650 break;
651 case 2:
652 case 4:
653 case 8:
654 macfb_defined.red.length = macfb_defined.bits_per_pixel;
655 macfb_defined.green.length = macfb_defined.bits_per_pixel;
656 macfb_defined.blue.length = macfb_defined.bits_per_pixel;
657 video_cmap_len = 1 << macfb_defined.bits_per_pixel;
658 macfb_fix.visual = FB_VISUAL_PSEUDOCOLOR;
659 break;
660 case 16:
661 macfb_defined.transp.offset = 15;
662 macfb_defined.transp.length = 1;
663 macfb_defined.red.offset = 10;
664 macfb_defined.red.length = 5;
665 macfb_defined.green.offset = 5;
666 macfb_defined.green.length = 5;
667 macfb_defined.blue.offset = 0;
668 macfb_defined.blue.length = 5;
669 printk("macfb: directcolor: "
670 "size=1:5:5:5, shift=15:10:5:0\n");
671 video_cmap_len = 16;
Finn Thain34c41d02009-11-04 00:47:28 +1100672 /*
673 * Should actually be FB_VISUAL_DIRECTCOLOR, but this
674 * works too
675 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 macfb_fix.visual = FB_VISUAL_TRUECOLOR;
677 break;
678 case 24:
679 case 32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 macfb_defined.red.offset = 16;
681 macfb_defined.red.length = 8;
682 macfb_defined.green.offset = 8;
683 macfb_defined.green.length = 8;
684 macfb_defined.blue.offset = 0;
685 macfb_defined.blue.length = 8;
686 printk("macfb: truecolor: "
687 "size=0:8:8:8, shift=0:16:8:0\n");
688 video_cmap_len = 16;
689 macfb_fix.visual = FB_VISUAL_TRUECOLOR;
690 default:
691 video_cmap_len = 0;
692 macfb_fix.visual = FB_VISUAL_MONO01;
Finn Thain34c41d02009-11-04 00:47:28 +1100693 printk("macfb: unknown or unsupported bit depth: %d\n",
694 macfb_defined.bits_per_pixel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 break;
696 }
697
Finn Thain34c41d02009-11-04 00:47:28 +1100698 /*
699 * We take a wild guess that if the video physical address is
700 * in nubus slot space, that the nubus card is driving video.
701 * Penguin really ought to tell us whether we are using internal
702 * video or not.
703 * Hopefully we only find one of them. Otherwise our NuBus
704 * code is really broken :-)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 while ((ndev = nubus_find_type(NUBUS_CAT_DISPLAY, NUBUS_TYPE_VIDEO, ndev))
708 != NULL)
709 {
710 if (!(mac_bi_data.videoaddr >= ndev->board->slot_addr
711 && (mac_bi_data.videoaddr <
712 (unsigned long)nubus_slot_addr(ndev->board->slot+1))))
713 continue;
714 video_is_nubus = 1;
715 /* We should probably just use the slot address... */
716 video_slot = ndev->board->slot;
717
718 switch(ndev->dr_hw) {
719 case NUBUS_DRHW_APPLE_MDC:
Finn Thain89c223a2008-11-18 20:40:40 +0100720 strcpy(macfb_fix.id, "Mac Disp. Card");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 macfb_setpalette = mdc_setpalette;
722 macfb_defined.activate = FB_ACTIVATE_NOW;
723 break;
724 case NUBUS_DRHW_APPLE_TFB:
Finn Thain89c223a2008-11-18 20:40:40 +0100725 strcpy(macfb_fix.id, "Toby");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 macfb_setpalette = toby_setpalette;
727 macfb_defined.activate = FB_ACTIVATE_NOW;
728 break;
729 case NUBUS_DRHW_APPLE_JET:
Finn Thain89c223a2008-11-18 20:40:40 +0100730 strcpy(macfb_fix.id, "Jet");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 macfb_setpalette = jet_setpalette;
732 macfb_defined.activate = FB_ACTIVATE_NOW;
Finn Thain34c41d02009-11-04 00:47:28 +1100733 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 default:
Finn Thain89c223a2008-11-18 20:40:40 +0100735 strcpy(macfb_fix.id, "Generic NuBus");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 break;
737 }
738 }
739
740 /* If it's not a NuBus card, it must be internal video */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 if (!video_is_nubus)
Finn Thain34c41d02009-11-04 00:47:28 +1100742 switch (mac_bi_data.id) {
743 /*
744 * DAFB Quadras
745 * Note: these first four have the v7 DAFB, which is
746 * known to be rather unlike the ones used in the
747 * other models
748 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 case MAC_MODEL_P475:
750 case MAC_MODEL_P475F:
751 case MAC_MODEL_P575:
752 case MAC_MODEL_Q605:
Finn Thain34c41d02009-11-04 00:47:28 +1100753
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 case MAC_MODEL_Q800:
755 case MAC_MODEL_Q650:
756 case MAC_MODEL_Q610:
757 case MAC_MODEL_C650:
758 case MAC_MODEL_C610:
759 case MAC_MODEL_Q700:
760 case MAC_MODEL_Q900:
761 case MAC_MODEL_Q950:
Finn Thain89c223a2008-11-18 20:40:40 +0100762 strcpy(macfb_fix.id, "DAFB");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 macfb_setpalette = dafb_setpalette;
764 macfb_defined.activate = FB_ACTIVATE_NOW;
765 dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);
766 break;
767
Finn Thain34c41d02009-11-04 00:47:28 +1100768 /*
769 * LC II uses the V8 framebuffer
770 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 case MAC_MODEL_LCII:
Finn Thain89c223a2008-11-18 20:40:40 +0100772 strcpy(macfb_fix.id, "V8");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 macfb_setpalette = v8_brazil_setpalette;
774 macfb_defined.activate = FB_ACTIVATE_NOW;
775 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
776 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100777
778 /*
779 * IIvi, IIvx use the "Brazil" framebuffer (which is
780 * very much like the V8, it seems, and probably uses
781 * the same DAC)
782 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 case MAC_MODEL_IIVI:
784 case MAC_MODEL_IIVX:
785 case MAC_MODEL_P600:
Finn Thain89c223a2008-11-18 20:40:40 +0100786 strcpy(macfb_fix.id, "Brazil");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 macfb_setpalette = v8_brazil_setpalette;
788 macfb_defined.activate = FB_ACTIVATE_NOW;
789 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
790 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100791
792 /*
793 * LC III (and friends) use the Sonora framebuffer
794 * Incidentally this is also used in the non-AV models
795 * of the x100 PowerMacs
796 * These do in fact seem to use the same DAC interface
797 * as the LC II.
798 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 case MAC_MODEL_LCIII:
800 case MAC_MODEL_P520:
801 case MAC_MODEL_P550:
802 case MAC_MODEL_P460:
803 macfb_setpalette = v8_brazil_setpalette;
804 macfb_defined.activate = FB_ACTIVATE_NOW;
Finn Thain89c223a2008-11-18 20:40:40 +0100805 strcpy(macfb_fix.id, "Sonora");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
807 break;
808
Finn Thain34c41d02009-11-04 00:47:28 +1100809 /*
810 * IIci and IIsi use the infamous RBV chip
811 * (the IIsi is just a rebadged and crippled
812 * IIci in a different case, BTW)
813 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 case MAC_MODEL_IICI:
815 case MAC_MODEL_IISI:
816 macfb_setpalette = rbv_setpalette;
817 macfb_defined.activate = FB_ACTIVATE_NOW;
Finn Thain89c223a2008-11-18 20:40:40 +0100818 strcpy(macfb_fix.id, "RBV");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);
820 break;
821
Finn Thain34c41d02009-11-04 00:47:28 +1100822 /*
823 * AVs use the Civic framebuffer
824 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 case MAC_MODEL_Q840:
826 case MAC_MODEL_C660:
827 macfb_setpalette = civic_setpalette;
828 macfb_defined.activate = FB_ACTIVATE_NOW;
Finn Thain89c223a2008-11-18 20:40:40 +0100829 strcpy(macfb_fix.id, "Civic");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
831 break;
832
833
Finn Thain34c41d02009-11-04 00:47:28 +1100834 /*
835 * Assorted weirdos
836 * We think this may be like the LC II
837 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 case MAC_MODEL_LC:
839 if (vidtest) {
840 macfb_setpalette = v8_brazil_setpalette;
841 macfb_defined.activate = FB_ACTIVATE_NOW;
842 v8_brazil_cmap_regs =
843 ioremap(DAC_BASE, 0x1000);
844 }
Finn Thain89c223a2008-11-18 20:40:40 +0100845 strcpy(macfb_fix.id, "LC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100847
848 /*
849 * We think this may be like the LC II
850 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 case MAC_MODEL_CCL:
852 if (vidtest) {
853 macfb_setpalette = v8_brazil_setpalette;
854 macfb_defined.activate = FB_ACTIVATE_NOW;
855 v8_brazil_cmap_regs =
856 ioremap(DAC_BASE, 0x1000);
857 }
Finn Thain89c223a2008-11-18 20:40:40 +0100858 strcpy(macfb_fix.id, "Color Classic");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 break;
860
Finn Thain34c41d02009-11-04 00:47:28 +1100861 /*
862 * And we *do* mean "weirdos"
863 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 case MAC_MODEL_TV:
Finn Thain89c223a2008-11-18 20:40:40 +0100865 strcpy(macfb_fix.id, "Mac TV");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 break;
867
Finn Thain34c41d02009-11-04 00:47:28 +1100868 /*
869 * These don't have colour, so no need to worry
870 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 case MAC_MODEL_SE30:
872 case MAC_MODEL_CLII:
Finn Thain89c223a2008-11-18 20:40:40 +0100873 strcpy(macfb_fix.id, "Monochrome");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 break;
875
Finn Thain34c41d02009-11-04 00:47:28 +1100876 /*
877 * Powerbooks are particularly difficult. Many of
878 * them have separate framebuffers for external and
879 * internal video, which is admittedly pretty cool,
880 * but will be a bit of a headache to support here.
881 * Also, many of them are grayscale, and we don't
882 * really support that.
883 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
885 case MAC_MODEL_PB140:
886 case MAC_MODEL_PB145:
887 case MAC_MODEL_PB170:
Finn Thain89c223a2008-11-18 20:40:40 +0100888 strcpy(macfb_fix.id, "DDC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 break;
890
Finn Thain34c41d02009-11-04 00:47:28 +1100891 /*
892 * Internal is GSC, External (if present) is ViSC
893 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 case MAC_MODEL_PB150: /* no external video */
895 case MAC_MODEL_PB160:
896 case MAC_MODEL_PB165:
897 case MAC_MODEL_PB180:
898 case MAC_MODEL_PB210:
899 case MAC_MODEL_PB230:
Finn Thain89c223a2008-11-18 20:40:40 +0100900 strcpy(macfb_fix.id, "GSC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 break;
902
Finn Thain34c41d02009-11-04 00:47:28 +1100903 /*
904 * Internal is TIM, External is ViSC
905 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 case MAC_MODEL_PB165C:
907 case MAC_MODEL_PB180C:
Finn Thain89c223a2008-11-18 20:40:40 +0100908 strcpy(macfb_fix.id, "TIM");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 break;
910
Finn Thain34c41d02009-11-04 00:47:28 +1100911 /*
912 * Internal is CSC, External is Keystone+Ariel.
913 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 case MAC_MODEL_PB190: /* external video is optional */
915 case MAC_MODEL_PB520:
916 case MAC_MODEL_PB250:
917 case MAC_MODEL_PB270C:
918 case MAC_MODEL_PB280:
919 case MAC_MODEL_PB280C:
920 macfb_setpalette = csc_setpalette;
921 macfb_defined.activate = FB_ACTIVATE_NOW;
Finn Thain89c223a2008-11-18 20:40:40 +0100922 strcpy(macfb_fix.id, "CSC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 csc_cmap_regs = ioremap(CSC_BASE, 0x1000);
924 break;
Finn Thain34c41d02009-11-04 00:47:28 +1100925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 default:
Finn Thain89c223a2008-11-18 20:40:40 +0100927 strcpy(macfb_fix.id, "Unknown");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 break;
929 }
930
931 fb_info.fbops = &macfb_ops;
932 fb_info.var = macfb_defined;
933 fb_info.fix = macfb_fix;
934 fb_info.pseudo_palette = pseudo_palette;
935 fb_info.flags = FBINFO_DEFAULT;
936
Finn Thain89c223a2008-11-18 20:40:40 +0100937 err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
938 if (err)
939 goto fail_unmap;
Finn Thain34c41d02009-11-04 00:47:28 +1100940
Al Viroed1705a2006-01-12 01:06:39 -0800941 err = register_framebuffer(&fb_info);
Finn Thain89c223a2008-11-18 20:40:40 +0100942 if (err)
943 goto fail_dealloc;
944
945 printk("fb%d: %s frame buffer device\n",
946 fb_info.node, fb_info.fix.id);
947 return 0;
948
949fail_dealloc:
950 fb_dealloc_cmap(&fb_info.cmap);
951fail_unmap:
952 iounmap(fb_info.screen_base);
953 iounmap_macfb();
Al Viroed1705a2006-01-12 01:06:39 -0800954 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955}
956
957module_init(macfb_init);
958MODULE_LICENSE("GPL");