Blame view

drivers/video/macfb.c 23.1 KB
34c41d0ab   Finn Thain   macfb: cleanup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  /*
   * macfb.c: Generic framebuffer for Macs whose colourmaps/modes we
   * don't know how to set.
   *
   * (c) 1999 David Huggins-Daines <dhd@debian.org>
   *
   * Primarily based on vesafb.c, by Gerd Knorr
   * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
   *
   * Also uses information and code from:
   *
   * The original macfb.c from Linux/mac68k 2.0, by Alan Cox, Juergen
   * Mellinger, Mikael Forselius, Michael Schmitz, and others.
   *
   * valkyriefb.c, by Martin Costabel, Kevin Schoedel, Barry Nathan, Dan
   * Jacobowitz, Paul Mackerras, Fabio Riccardi, and Geert Uytterhoeven.
   *
   * The VideoToolbox "Bugs" web page at
   * http://rajsky.psych.nyu.edu/Tips/VideoBugs.html
   *
   * This code is free software.  You may copy, modify, and distribute
   * it subject to the terms and conditions of the GNU General Public
   * License, version 2, or any later version, at your convenience.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
  
  #include <linux/module.h>
  #include <linux/kernel.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
29
30
  #include <linux/errno.h>
  #include <linux/string.h>
  #include <linux/mm.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
35
36
37
  #include <linux/delay.h>
  #include <linux/nubus.h>
  #include <linux/init.h>
  #include <linux/fb.h>
  
  #include <asm/setup.h>
  #include <asm/bootinfo.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
  #include <asm/macintosh.h>
  #include <asm/io.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
43
44
45
46
47
  
  /* Common DAC base address for the LC, RBV, Valkyrie, and IIvx */
  #define DAC_BASE 0x50f24000
  
  /* Some addresses for the DAFB */
  #define DAFB_BASE 0xf9800200
  
  /* Address for the built-in Civic framebuffer in Quadra AVs */
34c41d0ab   Finn Thain   macfb: cleanup
48
  #define CIVIC_BASE 0x50f30800
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
52
53
54
  
  /* GSC (Gray Scale Controller) base address */
  #define GSC_BASE 0x50F20000
  
  /* CSC (Color Screen Controller) base address */
  #define CSC_BASE 0x50F20000
34c41d0ab   Finn Thain   macfb: cleanup
55
56
57
  static int (*macfb_setpalette)(unsigned int regno, unsigned int red,
  			       unsigned int green, unsigned int blue,
  			       struct fb_info *info);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58

3839d01d6   Finn Thain   macfb annotations...
59
  static struct {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  	unsigned char addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  	unsigned char lut;
3839d01d6   Finn Thain   macfb annotations...
62
  } __iomem *v8_brazil_cmap_regs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63

3839d01d6   Finn Thain   macfb annotations...
64
  static struct {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
67
68
69
  	unsigned char addr;
  	char pad1[3]; /* word aligned */
  	unsigned char lut;
  	char pad2[3]; /* word aligned */
  	unsigned char cntl; /* a guess as to purpose */
3839d01d6   Finn Thain   macfb annotations...
70
  } __iomem *rbv_cmap_regs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71

3839d01d6   Finn Thain   macfb annotations...
72
  static struct {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
74
75
76
  	unsigned long reset;
  	unsigned long pad1[3];
  	unsigned char pad2[3];
  	unsigned char lut;
3839d01d6   Finn Thain   macfb annotations...
77
  } __iomem *dafb_cmap_regs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78

3839d01d6   Finn Thain   macfb annotations...
79
  static struct {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
81
82
83
84
85
86
87
  	unsigned char addr;	/* OFFSET: 0x00 */
  	unsigned char pad1[15];
  	unsigned char lut;	/* OFFSET: 0x10 */
  	unsigned char pad2[15];
  	unsigned char status;	/* OFFSET: 0x20 */
  	unsigned char pad3[7];
  	unsigned long vbl_addr;	/* OFFSET: 0x28 */
  	unsigned int  status2;	/* OFFSET: 0x2C */
3839d01d6   Finn Thain   macfb annotations...
88
  } __iomem *civic_cmap_regs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89

3839d01d6   Finn Thain   macfb annotations...
90
  static struct {
34c41d0ab   Finn Thain   macfb: cleanup
91
92
93
94
95
96
  	char pad1[0x40];
  	unsigned char clut_waddr;	/* 0x40 */
  	char pad2;
  	unsigned char clut_data;	/* 0x42 */
  	char pad3[0x3];
  	unsigned char clut_raddr;	/* 0x46 */
3839d01d6   Finn Thain   macfb annotations...
97
  } __iomem *csc_cmap_regs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98

34c41d0ab   Finn Thain   macfb: cleanup
99
  /* The registers in these structs are in NuBus slot space */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  struct mdc_cmap_regs {
  	char pad1[0x200200];
  	unsigned char addr;
  	char pad2[6];
  	unsigned char lut;
  };
  
  struct toby_cmap_regs {
  	char pad1[0x90018];
  	unsigned char lut; /* TFBClutWDataReg, offset 0x90018 */
  	char pad2[3];
  	unsigned char addr; /* TFBClutAddrReg, offset 0x9001C */
  };
  
  struct jet_cmap_regs {
  	char pad1[0xe0e000];
  	unsigned char addr;
  	unsigned char lut;
  };
34c41d0ab   Finn Thain   macfb: cleanup
119
  #define PIXEL_TO_MM(a)	(((a)*10)/28)	/* width in mm at 72 dpi */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
  static struct fb_var_screeninfo macfb_defined = {
34c41d0ab   Finn Thain   macfb: cleanup
122
  	.bits_per_pixel	= 8,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
124
125
126
127
128
129
130
131
132
133
  	.activate	= FB_ACTIVATE_NOW,
  	.width		= -1,
  	.height		= -1,
  	.right_margin	= 32,
  	.upper_margin	= 16,
  	.lower_margin	= 4,
  	.vsync_len	= 4,
  	.vmode		= FB_VMODE_NONINTERLACED,
  };
  
  static struct fb_fix_screeninfo macfb_fix = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
134
135
136
  	.type	= FB_TYPE_PACKED_PIXELS,
  	.accel	= FB_ACCEL_NONE,
  };
99e11ab20   Finn Thain   macfb: fix 24-bit...
137
  static void *slot_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
  static struct fb_info fb_info;
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
139
  static u32 pseudo_palette[16];
34c41d0ab   Finn Thain   macfb: cleanup
140
141
142
143
144
145
146
147
148
149
150
151
  static int inverse;
  static int vidtest;
  
  /*
   * Unlike the Valkyrie, the DAFB cannot set individual colormap
   * registers.  Therefore, we do what the MacOS driver does (no
   * kidding!) and simply set them one by one until we hit the one we
   * want.
   */
  static int dafb_setpalette(unsigned int regno, unsigned int red,
  			   unsigned int green, unsigned int blue,
  			   struct fb_info *info)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
154
  	static int lastreg = -1;
  	unsigned long flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155
156
  
  	local_irq_save(flags);
34c41d0ab   Finn Thain   macfb: cleanup
157
158
159
160
161
162
  
  	/*
  	 * fbdev will set an entire colourmap, but X won't.  Hopefully
  	 * this should accommodate both of them
  	 */
  	if (regno != lastreg + 1) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
163
  		int i;
34c41d0ab   Finn Thain   macfb: cleanup
164

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
166
167
  		/* Stab in the dark trying to reset the CLUT pointer */
  		nubus_writel(0, &dafb_cmap_regs->reset);
  		nop();
34c41d0ab   Finn Thain   macfb: cleanup
168

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
170
  		/* Loop until we get to the register we want */
  		for (i = 0; i < regno; i++) {
34c41d0ab   Finn Thain   macfb: cleanup
171
172
  			nubus_writeb(info->cmap.red[i] >> 8,
  				     &dafb_cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
173
  			nop();
34c41d0ab   Finn Thain   macfb: cleanup
174
175
  			nubus_writeb(info->cmap.green[i] >> 8,
  				     &dafb_cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
  			nop();
34c41d0ab   Finn Thain   macfb: cleanup
177
178
  			nubus_writeb(info->cmap.blue[i] >> 8,
  				     &dafb_cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
  			nop();
  		}
  	}
34c41d0ab   Finn Thain   macfb: cleanup
182

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
184
185
186
187
  	nubus_writeb(red, &dafb_cmap_regs->lut);
  	nop();
  	nubus_writeb(green, &dafb_cmap_regs->lut);
  	nop();
  	nubus_writeb(blue, &dafb_cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
188

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
190
191
192
193
194
  	local_irq_restore(flags);
  	lastreg = regno;
  	return 0;
  }
  
  /* V8 and Brazil seem to use the same DAC.  Sonora does as well. */
34c41d0ab   Finn Thain   macfb: cleanup
195
196
197
  static int v8_brazil_setpalette(unsigned int regno, unsigned int red,
  				unsigned int green, unsigned int blue,
  				struct fb_info *info)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198
199
  {
  	unsigned int bpp = info->var.bits_per_pixel;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
200
  	unsigned long flags;
34c41d0ab   Finn Thain   macfb: cleanup
201
202
  	if (bpp > 8)
  		return 1; /* failsafe */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
203
204
205
206
  
  	local_irq_save(flags);
  
  	/* On these chips, the CLUT register numbers are spread out
34c41d0ab   Finn Thain   macfb: cleanup
207
208
209
210
211
  	 * across the register space.  Thus:
  	 * In 8bpp, all regnos are valid.
  	 * In 4bpp, the regnos are 0x0f, 0x1f, 0x2f, etc, etc
  	 * In 2bpp, the regnos are 0x3f, 0x7f, 0xbf, 0xff
  	 */
99e11ab20   Finn Thain   macfb: fix 24-bit...
212
213
  	regno = (regno << (8 - bpp)) | (0xFF >> bpp);
  	nubus_writeb(regno, &v8_brazil_cmap_regs->addr);
34c41d0ab   Finn Thain   macfb: cleanup
214
  	nop();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
215
216
  
  	/* send one color channel at a time */
99e11ab20   Finn Thain   macfb: fix 24-bit...
217
  	nubus_writeb(red, &v8_brazil_cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
218
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
219
  	nubus_writeb(green, &v8_brazil_cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
220
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
221
  	nubus_writeb(blue, &v8_brazil_cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
222

34c41d0ab   Finn Thain   macfb: cleanup
223
  	local_irq_restore(flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
225
  	return 0;
  }
34c41d0ab   Finn Thain   macfb: cleanup
226
227
228
229
  /* RAM-Based Video */
  static int rbv_setpalette(unsigned int regno, unsigned int red,
  			  unsigned int green, unsigned int blue,
  			  struct fb_info *info)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231
  	unsigned long flags;
34c41d0ab   Finn Thain   macfb: cleanup
232
233
  	if (info->var.bits_per_pixel > 8)
  		return 1; /* failsafe */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
  
  	local_irq_save(flags);
34c41d0ab   Finn Thain   macfb: cleanup
236

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
239
240
  	/* From the VideoToolbox driver.  Seems to be saying that
  	 * regno #254 and #255 are the important ones for 1-bit color,
  	 * regno #252-255 are the important ones for 2-bit color, etc.
  	 */
99e11ab20   Finn Thain   macfb: fix 24-bit...
241
  	regno += 256 - (1 << info->var.bits_per_pixel);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
243
  
  	/* reset clut? (VideoToolbox sez "not necessary") */
34c41d0ab   Finn Thain   macfb: cleanup
244
245
  	nubus_writeb(0xFF, &rbv_cmap_regs->cntl);
  	nop();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246
  	/* tell clut which address to use. */
99e11ab20   Finn Thain   macfb: fix 24-bit...
247
  	nubus_writeb(regno, &rbv_cmap_regs->addr);
34c41d0ab   Finn Thain   macfb: cleanup
248
  	nop();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
  	/* send one color channel at a time. */
99e11ab20   Finn Thain   macfb: fix 24-bit...
250
  	nubus_writeb(red, &rbv_cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
251
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
252
  	nubus_writeb(green, &rbv_cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
253
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
254
  	nubus_writeb(blue, &rbv_cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
255
256
  
  	local_irq_restore(flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
257
258
  	return 0;
  }
34c41d0ab   Finn Thain   macfb: cleanup
259
  /* Macintosh Display Card (8*24) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260
261
262
263
  static int mdc_setpalette(unsigned int regno, unsigned int red,
  			  unsigned int green, unsigned int blue,
  			  struct fb_info *info)
  {
99e11ab20   Finn Thain   macfb: fix 24-bit...
264
  	struct mdc_cmap_regs *cmap_regs = slot_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
266
267
  	unsigned long flags;
  
  	local_irq_save(flags);
34c41d0ab   Finn Thain   macfb: cleanup
268

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
  	/* the nop's are there to order writes. */
99e11ab20   Finn Thain   macfb: fix 24-bit...
270
  	nubus_writeb(regno, &cmap_regs->addr);
34c41d0ab   Finn Thain   macfb: cleanup
271
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
272
  	nubus_writeb(red, &cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
273
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
274
  	nubus_writeb(green, &cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
275
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
276
  	nubus_writeb(blue, &cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277
278
279
280
281
282
283
284
  
  	local_irq_restore(flags);
  	return 0;
  }
  
  /* Toby frame buffer */
  static int toby_setpalette(unsigned int regno, unsigned int red,
  			   unsigned int green, unsigned int blue,
34c41d0ab   Finn Thain   macfb: cleanup
285
  			   struct fb_info *info)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286
  {
99e11ab20   Finn Thain   macfb: fix 24-bit...
287
  	struct toby_cmap_regs *cmap_regs = slot_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
  	unsigned int bpp = info->var.bits_per_pixel;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
289
  	unsigned long flags;
99e11ab20   Finn Thain   macfb: fix 24-bit...
290
291
292
293
  	red = ~red;
  	green = ~green;
  	blue = ~blue;
  	regno = (regno << (8 - bpp)) | (0xFF >> bpp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
294
  	local_irq_save(flags);
34c41d0ab   Finn Thain   macfb: cleanup
295

99e11ab20   Finn Thain   macfb: fix 24-bit...
296
  	nubus_writeb(regno, &cmap_regs->addr);
34c41d0ab   Finn Thain   macfb: cleanup
297
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
298
  	nubus_writeb(red, &cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
299
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
300
  	nubus_writeb(green, &cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
301
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
302
  	nubus_writeb(blue, &cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
303
304
305
306
307
308
309
310
311
312
  
  	local_irq_restore(flags);
  	return 0;
  }
  
  /* Jet frame buffer */
  static int jet_setpalette(unsigned int regno, unsigned int red,
  			  unsigned int green, unsigned int blue,
  			  struct fb_info *info)
  {
99e11ab20   Finn Thain   macfb: fix 24-bit...
313
  	struct jet_cmap_regs *cmap_regs = slot_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
314
315
316
  	unsigned long flags;
  
  	local_irq_save(flags);
34c41d0ab   Finn Thain   macfb: cleanup
317
318
319
  
  	nubus_writeb(regno, &cmap_regs->addr);
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
320
  	nubus_writeb(red, &cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
321
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
322
  	nubus_writeb(green, &cmap_regs->lut);
34c41d0ab   Finn Thain   macfb: cleanup
323
  	nop();
99e11ab20   Finn Thain   macfb: fix 24-bit...
324
  	nubus_writeb(blue, &cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
325
326
327
328
329
330
331
332
  
  	local_irq_restore(flags);
  	return 0;
  }
  
  /*
   * Civic framebuffer -- Quadra AV built-in video.  A chip
   * called Sebastian holds the actual color palettes, and
34c41d0ab   Finn Thain   macfb: cleanup
333
   * apparently, there are two different banks of 512K RAM
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
334
335
   * which can act as separate framebuffers for doing video
   * input and viewing the screen at the same time!  The 840AV
34c41d0ab   Finn Thain   macfb: cleanup
336
   * Can add another 1MB RAM to give the two framebuffers
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
337
   * 1MB RAM apiece.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
338
   */
34c41d0ab   Finn Thain   macfb: cleanup
339
340
341
  static int civic_setpalette(unsigned int regno, unsigned int red,
  			    unsigned int green, unsigned int blue,
  			    struct fb_info *info)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
342
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
344
345
  	unsigned long flags;
  	int clut_status;
  	
34c41d0ab   Finn Thain   macfb: cleanup
346
347
  	if (info->var.bits_per_pixel > 8)
  		return 1; /* failsafe */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
349
  	local_irq_save(flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350

34c41d0ab   Finn Thain   macfb: cleanup
351
352
353
  	/* Set the register address */
  	nubus_writeb(regno, &civic_cmap_regs->addr);
  	nop();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
355
356
357
358
359
360
361
362
363
364
365
  
  	/*
  	 * Grab a status word and do some checking;
  	 * Then finally write the clut!
  	 */
  	clut_status =  nubus_readb(&civic_cmap_regs->status2);
  
  	if ((clut_status & 0x0008) == 0)
  	{
  #if 0
  		if ((clut_status & 0x000D) != 0)
  		{
34c41d0ab   Finn Thain   macfb: cleanup
366
367
368
369
  			nubus_writeb(0x00, &civic_cmap_regs->lut);
  			nop();
  			nubus_writeb(0x00, &civic_cmap_regs->lut);
  			nop();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
370
371
  		}
  #endif
34c41d0ab   Finn Thain   macfb: cleanup
372
373
374
375
376
377
378
  		nubus_writeb(red, &civic_cmap_regs->lut);
  		nop();
  		nubus_writeb(green, &civic_cmap_regs->lut);
  		nop();
  		nubus_writeb(blue, &civic_cmap_regs->lut);
  		nop();
  		nubus_writeb(0x00, &civic_cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
379
380
381
382
  	}
  	else
  	{
  		unsigned char junk;
34c41d0ab   Finn Thain   macfb: cleanup
383
384
385
386
387
388
389
390
  		junk = nubus_readb(&civic_cmap_regs->lut);
  		nop();
  		junk = nubus_readb(&civic_cmap_regs->lut);
  		nop();
  		junk = nubus_readb(&civic_cmap_regs->lut);
  		nop();
  		junk = nubus_readb(&civic_cmap_regs->lut);
  		nop();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
391
392
393
  
  		if ((clut_status & 0x000D) != 0)
  		{
34c41d0ab   Finn Thain   macfb: cleanup
394
395
396
397
  			nubus_writeb(0x00, &civic_cmap_regs->lut);
  			nop();
  			nubus_writeb(0x00, &civic_cmap_regs->lut);
  			nop();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
398
  		}
34c41d0ab   Finn Thain   macfb: cleanup
399
400
401
402
403
404
405
  		nubus_writeb(red, &civic_cmap_regs->lut);
  		nop();
  		nubus_writeb(green, &civic_cmap_regs->lut);
  		nop();
  		nubus_writeb(blue, &civic_cmap_regs->lut);
  		nop();
  		nubus_writeb(junk, &civic_cmap_regs->lut);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
406
407
408
  	}
  
  	local_irq_restore(flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
409
410
411
412
413
414
415
416
  	return 0;
  }
  
  /*
   * The CSC is the framebuffer on the PowerBook 190 series
   * (and the 5300 too, but that's a PowerMac). This function
   * brought to you in part by the ECSC driver for MkLinux.
   */
34c41d0ab   Finn Thain   macfb: cleanup
417
418
419
  static int csc_setpalette(unsigned int regno, unsigned int red,
  			  unsigned int green, unsigned int blue,
  			  struct fb_info *info)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
420
  {
99e11ab20   Finn Thain   macfb: fix 24-bit...
421
422
423
424
425
  	unsigned long flags;
  
  	local_irq_save(flags);
  
  	udelay(1); /* mklinux on PB 5300 waits for 260 ns */
3839d01d6   Finn Thain   macfb annotations...
426
  	nubus_writeb(regno, &csc_cmap_regs->clut_waddr);
99e11ab20   Finn Thain   macfb: fix 24-bit...
427
  	nubus_writeb(red, &csc_cmap_regs->clut_data);
3839d01d6   Finn Thain   macfb annotations...
428
  	nubus_writeb(green, &csc_cmap_regs->clut_data);
99e11ab20   Finn Thain   macfb: fix 24-bit...
429
430
431
  	nubus_writeb(blue, &csc_cmap_regs->clut_data);
  
  	local_irq_restore(flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
432
433
434
435
436
437
438
439
  	return 0;
  }
  
  static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  			   unsigned blue, unsigned transp,
  			   struct fb_info *fb_info)
  {
  	/*
34c41d0ab   Finn Thain   macfb: cleanup
440
441
442
443
  	 * Set a single color register. The values supplied are
  	 * already rounded down to the hardware's capabilities
  	 * (according to the entries in the `var' structure).
  	 * Return non-zero for invalid regno.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
444
445
446
447
  	 */
  	
  	if (regno >= fb_info->cmap.len)
  		return 1;
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
448
449
450
451
452
453
454
455
456
  	if (fb_info->var.bits_per_pixel <= 8) {
  		switch (fb_info->var.bits_per_pixel) {
  		case 1:
  			/* We shouldn't get here */
  			break;
  		case 2:
  		case 4:
  		case 8:
  			if (macfb_setpalette)
99e11ab20   Finn Thain   macfb: fix 24-bit...
457
458
  				macfb_setpalette(regno, red >> 8, green >> 8,
  						 blue >> 8, fb_info);
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
459
460
461
462
463
464
465
466
467
468
  			else
  				return 1;
  			break;
  		}
  	} else if (regno < 16) {
  		switch (fb_info->var.bits_per_pixel) {
  		case 16:
  			if (fb_info->var.red.offset == 10) {
  				/* 1:5:5:5 */
  				((u32*) (fb_info->pseudo_palette))[regno] =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
469
470
471
472
  					((red   & 0xf800) >>  1) |
  					((green & 0xf800) >>  6) |
  					((blue  & 0xf800) >> 11) |
  					((transp != 0) << 15);
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
473
474
475
  			} else {
  				/* 0:5:6:5 */
  				((u32*) (fb_info->pseudo_palette))[regno] =
34c41d0ab   Finn Thain   macfb: cleanup
476
  					((red   & 0xf800) >>  0) |
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
477
478
  					((green & 0xfc00) >>  5) |
  					((blue  & 0xf800) >> 11);
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
479
480
  			}
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
481
482
483
484
  		/*
  		 * 24-bit colour almost doesn't exist on 68k Macs --
  		 * http://support.apple.com/kb/TA28634 (Old Article: 10992)
  		 */
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
485
  		case 24:
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
486
487
488
489
490
  		case 32:
  			red   >>= 8;
  			green >>= 8;
  			blue  >>= 8;
  			((u32 *)(fb_info->pseudo_palette))[regno] =
34c41d0ab   Finn Thain   macfb: cleanup
491
  				(red   << fb_info->var.red.offset) |
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
492
493
494
  				(green << fb_info->var.green.offset) |
  				(blue  << fb_info->var.blue.offset);
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
495
  		}
24fc72239   Antonino A. Daplas   macfb: fix pseudo...
496
497
498
  	}
  
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
499
500
501
502
503
504
505
506
  }
  
  static struct fb_ops macfb_ops = {
  	.owner		= THIS_MODULE,
  	.fb_setcolreg	= macfb_setcolreg,
  	.fb_fillrect	= cfb_fillrect,
  	.fb_copyarea	= cfb_copyarea,
  	.fb_imageblit	= cfb_imageblit,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
507
  };
511e7483a   Adrian Bunk   make macfb_setup(...
508
  static void __init macfb_setup(char *options)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
509
510
  {
  	char *this_opt;
34c41d0ab   Finn Thain   macfb: cleanup
511

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
512
513
  	if (!options || !*options)
  		return;
34c41d0ab   Finn Thain   macfb: cleanup
514

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
  	while ((this_opt = strsep(&options, ",")) != NULL) {
34c41d0ab   Finn Thain   macfb: cleanup
516
517
518
519
520
521
522
523
  		if (!*this_opt)
  			continue;
  
  		if (!strcmp(this_opt, "inverse"))
  			inverse = 1;
  		else
  			if (!strcmp(this_opt, "vidtest"))
  				vidtest = 1; /* enable experimental CLUT code */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
524
525
  	}
  }
164a765b9   Amol Lad   [PATCH] ioremap b...
526
527
  static void __init iounmap_macfb(void)
  {
164a765b9   Amol Lad   [PATCH] ioremap b...
528
529
530
531
532
533
534
535
536
537
538
  	if (dafb_cmap_regs)
  		iounmap(dafb_cmap_regs);
  	if (v8_brazil_cmap_regs)
  		iounmap(v8_brazil_cmap_regs);
  	if (rbv_cmap_regs)
  		iounmap(rbv_cmap_regs);
  	if (civic_cmap_regs)
  		iounmap(civic_cmap_regs);
  	if (csc_cmap_regs)
  		iounmap(csc_cmap_regs);
  }
ed1705afb   Al Viro   [PATCH] m68k: fix...
539
  static int __init macfb_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
540
541
542
543
  {
  	int video_cmap_len, video_is_nubus = 0;
  	struct nubus_dev* ndev = NULL;
  	char *option = NULL;
ed1705afb   Al Viro   [PATCH] m68k: fix...
544
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
545
546
547
548
549
550
  
  	if (fb_get_options("macfb", &option))
  		return -ENODEV;
  	macfb_setup(option);
  
  	if (!MACH_IS_MAC) 
ed1705afb   Al Viro   [PATCH] m68k: fix...
551
  		return -ENODEV;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
552

11e8faca2   Finn Thain   valkyriefb: vario...
553
554
555
  	if (mac_bi_data.id == MAC_MODEL_Q630 ||
  	    mac_bi_data.id == MAC_MODEL_P588)
  		return -ENODEV; /* See valkyriefb.c */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
556
557
558
  	macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF;
  	macfb_defined.yres = mac_bi_data.dimensions >> 16;
  	macfb_defined.bits_per_pixel = mac_bi_data.videodepth;
34c41d0ab   Finn Thain   macfb: cleanup
559

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
560
  	macfb_fix.line_length = mac_bi_data.videorow;
34c41d0ab   Finn Thain   macfb: cleanup
561
  	macfb_fix.smem_len    = macfb_fix.line_length * macfb_defined.yres;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
562
  	/* Note: physical address (since 2.1.127) */
34c41d0ab   Finn Thain   macfb: cleanup
563
564
565
566
567
568
569
570
  	macfb_fix.smem_start  = mac_bi_data.videoaddr;
  
  	/*
  	 * This is actually redundant with the initial mappings.
  	 * However, there are some non-obvious aspects to the way
  	 * those mappings are set up, so this is in fact the safest
  	 * way to ensure that this driver will work on every possible Mac
  	 */
99e11ab20   Finn Thain   macfb: fix 24-bit...
571
572
573
574
  	fb_info.screen_base = ioremap(mac_bi_data.videoaddr,
  				      macfb_fix.smem_len);
  	if (!fb_info.screen_base)
  		return -ENODEV;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
575
576
  	printk("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk
  ",
34c41d0ab   Finn Thain   macfb: cleanup
577
578
  	       macfb_fix.smem_start, fb_info.screen_base,
  	       macfb_fix.smem_len / 1024);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
579
580
  	printk("macfb: mode is %dx%dx%d, linelength=%d
  ",
34c41d0ab   Finn Thain   macfb: cleanup
581
582
  	       macfb_defined.xres, macfb_defined.yres,
  	       macfb_defined.bits_per_pixel, macfb_fix.line_length);
99e11ab20   Finn Thain   macfb: fix 24-bit...
583
  	/* Fill in the available video resolution */
34c41d0ab   Finn Thain   macfb: cleanup
584
585
586
587
  	macfb_defined.xres_virtual = macfb_defined.xres;
  	macfb_defined.yres_virtual = macfb_defined.yres;
  	macfb_defined.height       = PIXEL_TO_MM(macfb_defined.yres);
  	macfb_defined.width        = PIXEL_TO_MM(macfb_defined.xres);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
588

99e11ab20   Finn Thain   macfb: fix 24-bit...
589
  	/* Some dummy values for timing to make fbset happy */
34c41d0ab   Finn Thain   macfb: cleanup
590
591
  	macfb_defined.pixclock     = 10000000 / macfb_defined.xres *
  				     1000 / macfb_defined.yres;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
592
593
594
595
596
  	macfb_defined.left_margin  = (macfb_defined.xres / 8) & 0xf8;
  	macfb_defined.hsync_len    = (macfb_defined.xres / 8) & 0xf8;
  
  	switch (macfb_defined.bits_per_pixel) {
  	case 1:
34c41d0ab   Finn Thain   macfb: cleanup
597
598
599
600
  		/*
  		 * XXX: I think this will catch any program that tries
  		 * to do FBIO_PUTCMAP when the visual is monochrome.
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
  		macfb_defined.red.length = macfb_defined.bits_per_pixel;
  		macfb_defined.green.length = macfb_defined.bits_per_pixel;
  		macfb_defined.blue.length = macfb_defined.bits_per_pixel;
  		video_cmap_len = 0;
  		macfb_fix.visual = FB_VISUAL_MONO01;
  		break;
  	case 2:
  	case 4:
  	case 8:
  		macfb_defined.red.length = macfb_defined.bits_per_pixel;
  		macfb_defined.green.length = macfb_defined.bits_per_pixel;
  		macfb_defined.blue.length = macfb_defined.bits_per_pixel;
  		video_cmap_len = 1 << macfb_defined.bits_per_pixel;
  		macfb_fix.visual = FB_VISUAL_PSEUDOCOLOR;
  		break;
  	case 16:
  		macfb_defined.transp.offset = 15;
  		macfb_defined.transp.length = 1;
  		macfb_defined.red.offset = 10;
  		macfb_defined.red.length = 5;
  		macfb_defined.green.offset = 5;
  		macfb_defined.green.length = 5;
  		macfb_defined.blue.offset = 0;
  		macfb_defined.blue.length = 5;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
625
  		video_cmap_len = 16;
34c41d0ab   Finn Thain   macfb: cleanup
626
627
628
629
  		/*
  		 * Should actually be FB_VISUAL_DIRECTCOLOR, but this
  		 * works too
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
630
631
632
633
  		macfb_fix.visual = FB_VISUAL_TRUECOLOR;
  		break;
  	case 24:
  	case 32:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
634
635
636
637
638
639
  		macfb_defined.red.offset = 16;
  		macfb_defined.red.length = 8;
  		macfb_defined.green.offset = 8;
  		macfb_defined.green.length = 8;
  		macfb_defined.blue.offset = 0;
  		macfb_defined.blue.length = 8;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
640
641
  		video_cmap_len = 16;
  		macfb_fix.visual = FB_VISUAL_TRUECOLOR;
99e11ab20   Finn Thain   macfb: fix 24-bit...
642
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
643
644
645
  	default:
  		video_cmap_len = 0;
  		macfb_fix.visual = FB_VISUAL_MONO01;
34c41d0ab   Finn Thain   macfb: cleanup
646
647
648
  		printk("macfb: unknown or unsupported bit depth: %d
  ",
  		       macfb_defined.bits_per_pixel);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
649
650
651
  		break;
  	}
  	
34c41d0ab   Finn Thain   macfb: cleanup
652
653
654
655
656
657
658
  	/*
  	 * We take a wild guess that if the video physical address is
  	 * in nubus slot space, that the nubus card is driving video.
  	 * Penguin really ought to tell us whether we are using internal
  	 * video or not.
  	 * Hopefully we only find one of them.  Otherwise our NuBus
  	 * code is really broken :-)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
659
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
660

99e11ab20   Finn Thain   macfb: fix 24-bit...
661
662
  	while ((ndev = nubus_find_type(NUBUS_CAT_DISPLAY,
  				       NUBUS_TYPE_VIDEO, ndev)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
663
  	{
99e11ab20   Finn Thain   macfb: fix 24-bit...
664
665
666
667
  		unsigned long base = ndev->board->slot_addr;
  
  		if (mac_bi_data.videoaddr < base ||
  		    mac_bi_data.videoaddr - base > 0xFFFFFF)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
668
  			continue;
99e11ab20   Finn Thain   macfb: fix 24-bit...
669

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
670
  		video_is_nubus = 1;
99e11ab20   Finn Thain   macfb: fix 24-bit...
671
  		slot_addr = (unsigned char *)base;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
672
673
674
  
  		switch(ndev->dr_hw) {
  		case NUBUS_DRHW_APPLE_MDC:
89c223a61   Finn Thain   macfb: Do not ove...
675
  			strcpy(macfb_fix.id, "Mac Disp. Card");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
676
677
678
679
  			macfb_setpalette = mdc_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
  			break;
  		case NUBUS_DRHW_APPLE_TFB:
89c223a61   Finn Thain   macfb: Do not ove...
680
  			strcpy(macfb_fix.id, "Toby");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
681
682
683
684
  			macfb_setpalette = toby_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
  			break;
  		case NUBUS_DRHW_APPLE_JET:
89c223a61   Finn Thain   macfb: Do not ove...
685
  			strcpy(macfb_fix.id, "Jet");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
686
687
  			macfb_setpalette = jet_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
34c41d0ab   Finn Thain   macfb: cleanup
688
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
689
  		default:
89c223a61   Finn Thain   macfb: Do not ove...
690
  			strcpy(macfb_fix.id, "Generic NuBus");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
691
692
693
694
695
  			break;
  		}
  	}
  
  	/* If it's not a NuBus card, it must be internal video */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
696
  	if (!video_is_nubus)
34c41d0ab   Finn Thain   macfb: cleanup
697
698
699
700
701
702
703
  		switch (mac_bi_data.id) {
  		/*
  		 * DAFB Quadras
  		 * Note: these first four have the v7 DAFB, which is
  		 * known to be rather unlike the ones used in the
  		 * other models
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704
705
706
707
  		case MAC_MODEL_P475:
  		case MAC_MODEL_P475F:
  		case MAC_MODEL_P575:
  		case MAC_MODEL_Q605:
34c41d0ab   Finn Thain   macfb: cleanup
708

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
709
710
711
712
713
714
715
716
  		case MAC_MODEL_Q800:
  		case MAC_MODEL_Q650:
  		case MAC_MODEL_Q610:
  		case MAC_MODEL_C650:
  		case MAC_MODEL_C610:
  		case MAC_MODEL_Q700:
  		case MAC_MODEL_Q900:
  		case MAC_MODEL_Q950:
89c223a61   Finn Thain   macfb: Do not ove...
717
  			strcpy(macfb_fix.id, "DAFB");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
718
719
720
721
  			macfb_setpalette = dafb_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
  			dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
722
723
724
  		/*
  		 * LC II uses the V8 framebuffer
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
725
  		case MAC_MODEL_LCII:
89c223a61   Finn Thain   macfb: Do not ove...
726
  			strcpy(macfb_fix.id, "V8");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
727
728
729
730
  			macfb_setpalette = v8_brazil_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
  			v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
731
732
733
734
735
736
  
  		/*
  		 * IIvi, IIvx use the "Brazil" framebuffer (which is
  		 * very much like the V8, it seems, and probably uses
  		 * the same DAC)
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
737
738
739
  		case MAC_MODEL_IIVI:
  		case MAC_MODEL_IIVX:
  		case MAC_MODEL_P600:
89c223a61   Finn Thain   macfb: Do not ove...
740
  			strcpy(macfb_fix.id, "Brazil");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
741
742
743
744
  			macfb_setpalette = v8_brazil_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
  			v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
745
746
747
748
749
750
751
752
  
  		/*
  		 * LC III (and friends) use the Sonora framebuffer
  		 * Incidentally this is also used in the non-AV models
  		 * of the x100 PowerMacs
  		 * These do in fact seem to use the same DAC interface
  		 * as the LC II.
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
753
754
755
756
757
758
  		case MAC_MODEL_LCIII:
  		case MAC_MODEL_P520:
  		case MAC_MODEL_P550:
  		case MAC_MODEL_P460:
  			macfb_setpalette = v8_brazil_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
89c223a61   Finn Thain   macfb: Do not ove...
759
  			strcpy(macfb_fix.id, "Sonora");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
760
761
  			v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
762
763
764
765
766
  		/*
  		 * IIci and IIsi use the infamous RBV chip
  		 * (the IIsi is just a rebadged and crippled
  		 * IIci in a different case, BTW)
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
767
768
769
770
  		case MAC_MODEL_IICI:
  		case MAC_MODEL_IISI:
  			macfb_setpalette = rbv_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
89c223a61   Finn Thain   macfb: Do not ove...
771
  			strcpy(macfb_fix.id, "RBV");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
772
773
  			rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
774
775
776
  		/*
  		 * AVs use the Civic framebuffer
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
777
778
779
780
  		case MAC_MODEL_Q840:
  		case MAC_MODEL_C660:
  			macfb_setpalette = civic_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
89c223a61   Finn Thain   macfb: Do not ove...
781
  			strcpy(macfb_fix.id, "Civic");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
782
783
784
785
  			civic_cmap_regs = ioremap(CIVIC_BASE, 0x1000);
  			break;
  
  		
34c41d0ab   Finn Thain   macfb: cleanup
786
787
788
789
  		/*
  		 * Assorted weirdos
  		 * We think this may be like the LC II
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
790
791
792
793
794
795
796
  		case MAC_MODEL_LC:
  			if (vidtest) {
  				macfb_setpalette = v8_brazil_setpalette;
  				macfb_defined.activate = FB_ACTIVATE_NOW;
  				v8_brazil_cmap_regs =
  					ioremap(DAC_BASE, 0x1000);
  			}
89c223a61   Finn Thain   macfb: Do not ove...
797
  			strcpy(macfb_fix.id, "LC");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
798
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
799
800
801
802
  
  		/*
  		 * We think this may be like the LC II
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
803
804
805
806
807
808
809
  		case MAC_MODEL_CCL:
  			if (vidtest) {
  				macfb_setpalette = v8_brazil_setpalette;
  				macfb_defined.activate = FB_ACTIVATE_NOW;
  				v8_brazil_cmap_regs =
  					ioremap(DAC_BASE, 0x1000);
  			}
89c223a61   Finn Thain   macfb: Do not ove...
810
  			strcpy(macfb_fix.id, "Color Classic");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
811
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
812
813
814
  		/*
  		 * And we *do* mean "weirdos"
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
815
  		case MAC_MODEL_TV:
89c223a61   Finn Thain   macfb: Do not ove...
816
  			strcpy(macfb_fix.id, "Mac TV");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
817
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
818
819
820
  		/*
  		 * These don't have colour, so no need to worry
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
821
822
  		case MAC_MODEL_SE30:
  		case MAC_MODEL_CLII:
89c223a61   Finn Thain   macfb: Do not ove...
823
  			strcpy(macfb_fix.id, "Monochrome");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
824
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
825
826
827
828
829
830
831
832
  		/*
  		 * Powerbooks are particularly difficult.  Many of
  		 * them have separate framebuffers for external and
  		 * internal video, which is admittedly pretty cool,
  		 * but will be a bit of a headache to support here.
  		 * Also, many of them are grayscale, and we don't
  		 * really support that.
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
833

99e11ab20   Finn Thain   macfb: fix 24-bit...
834
835
836
  		/*
  		 * Slot 0 ROM says TIM. No external video. B&W.
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
837
838
839
  		case MAC_MODEL_PB140:
  		case MAC_MODEL_PB145:
  		case MAC_MODEL_PB170:
89c223a61   Finn Thain   macfb: Do not ove...
840
  			strcpy(macfb_fix.id, "DDC");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
841
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
842
843
844
  		/*
  		 * Internal is GSC, External (if present) is ViSC
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
845
846
847
848
849
850
  		case MAC_MODEL_PB150:	/* no external video */
  		case MAC_MODEL_PB160:
  		case MAC_MODEL_PB165:
  		case MAC_MODEL_PB180:
  		case MAC_MODEL_PB210:
  		case MAC_MODEL_PB230:
89c223a61   Finn Thain   macfb: Do not ove...
851
  			strcpy(macfb_fix.id, "GSC");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
852
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
853
854
855
  		/*
  		 * Internal is TIM, External is ViSC
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
856
857
  		case MAC_MODEL_PB165C:
  		case MAC_MODEL_PB180C:
89c223a61   Finn Thain   macfb: Do not ove...
858
  			strcpy(macfb_fix.id, "TIM");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
859
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
860
861
862
  		/*
  		 * Internal is CSC, External is Keystone+Ariel.
  		 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
863
864
865
866
867
868
869
870
  		case MAC_MODEL_PB190:	/* external video is optional */
  		case MAC_MODEL_PB520:
  		case MAC_MODEL_PB250:
  		case MAC_MODEL_PB270C:
  		case MAC_MODEL_PB280:
  		case MAC_MODEL_PB280C:
  			macfb_setpalette = csc_setpalette;
  			macfb_defined.activate = FB_ACTIVATE_NOW;
89c223a61   Finn Thain   macfb: Do not ove...
871
  			strcpy(macfb_fix.id, "CSC");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
872
873
  			csc_cmap_regs = ioremap(CSC_BASE, 0x1000);
  			break;
34c41d0ab   Finn Thain   macfb: cleanup
874

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
875
  		default:
89c223a61   Finn Thain   macfb: Do not ove...
876
  			strcpy(macfb_fix.id, "Unknown");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
877
878
879
880
881
882
883
884
  			break;
  		}
  
  	fb_info.fbops		= &macfb_ops;
  	fb_info.var		= macfb_defined;
  	fb_info.fix		= macfb_fix;
  	fb_info.pseudo_palette	= pseudo_palette;
  	fb_info.flags		= FBINFO_DEFAULT;
89c223a61   Finn Thain   macfb: Do not ove...
885
886
887
  	err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
  	if (err)
  		goto fail_unmap;
34c41d0ab   Finn Thain   macfb: cleanup
888

ed1705afb   Al Viro   [PATCH] m68k: fix...
889
  	err = register_framebuffer(&fb_info);
89c223a61   Finn Thain   macfb: Do not ove...
890
891
892
893
894
895
896
897
898
899
900
901
902
  	if (err)
  		goto fail_dealloc;
  
  	printk("fb%d: %s frame buffer device
  ",
  	       fb_info.node, fb_info.fix.id);
  	return 0;
  
  fail_dealloc:
  	fb_dealloc_cmap(&fb_info.cmap);
  fail_unmap:
  	iounmap(fb_info.screen_base);
  	iounmap_macfb();
ed1705afb   Al Viro   [PATCH] m68k: fix...
903
  	return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
904
905
906
907
  }
  
  module_init(macfb_init);
  MODULE_LICENSE("GPL");