blob: 335e3746555983bb4678c325fef450aab47f75ef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * platinumfb.c -- frame buffer device for the PowerMac 'platinum' display
3 *
4 * Copyright (C) 1998 Franz Sirl
5 *
6 * Frame buffer structure from:
7 * drivers/video/controlfb.c -- frame buffer device for
8 * Apple 'control' display chip.
9 * Copyright (C) 1998 Dan Jacobowitz
10 *
11 * Hardware information from:
12 * platinum.c: Console support for PowerMac "platinum" display adaptor.
13 * Copyright (C) 1996 Paul Mackerras and Mark Abene
14 *
15 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file COPYING in the main directory of this archive for
17 * more details.
18 */
19
20#include <linux/config.h>
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/errno.h>
24#include <linux/string.h>
25#include <linux/mm.h>
26#include <linux/tty.h>
27#include <linux/slab.h>
28#include <linux/vmalloc.h>
29#include <linux/delay.h>
30#include <linux/interrupt.h>
31#include <linux/fb.h>
32#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/nvram.h>
35#include <asm/io.h>
36#include <asm/prom.h>
37#include <asm/pgtable.h>
38#include <asm/of_device.h>
39
40#include "macmodes.h"
41#include "platinumfb.h"
42
43static int default_vmode = VMODE_NVRAM;
44static int default_cmode = CMODE_NVRAM;
45
46struct fb_info_platinum {
47 struct fb_info *info;
48
49 int vmode, cmode;
50 int xres, yres;
51 int vxres, vyres;
52 int xoffset, yoffset;
53
54 struct {
55 __u8 red, green, blue;
56 } palette[256];
57 u32 pseudo_palette[17];
58
59 volatile struct cmap_regs __iomem *cmap_regs;
60 unsigned long cmap_regs_phys;
61
62 volatile struct platinum_regs __iomem *platinum_regs;
63 unsigned long platinum_regs_phys;
64
65 __u8 __iomem *frame_buffer;
66 volatile __u8 __iomem *base_frame_buffer;
67 unsigned long frame_buffer_phys;
68
69 unsigned long total_vram;
70 int clktype;
71 int dactype;
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +110072
73 struct resource rsrc_fb, rsrc_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
75
76/*
77 * Frame buffer device API
78 */
79
80static int platinumfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
81 u_int transp, struct fb_info *info);
82static int platinumfb_blank(int blank_mode, struct fb_info *info);
83static int platinumfb_set_par (struct fb_info *info);
84static int platinumfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info);
85
86/*
87 * internal functions
88 */
89
90static inline int platinum_vram_reqd(int video_mode, int color_mode);
91static int read_platinum_sense(struct fb_info_platinum *pinfo);
92static void set_platinum_clock(struct fb_info_platinum *pinfo);
93static void platinum_set_hardware(struct fb_info_platinum *pinfo);
94static int platinum_var_to_par(struct fb_var_screeninfo *var,
95 struct fb_info_platinum *pinfo,
96 int check_only);
97
98/*
99 * Interface used by the world
100 */
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102static struct fb_ops platinumfb_ops = {
103 .owner = THIS_MODULE,
104 .fb_check_var = platinumfb_check_var,
105 .fb_set_par = platinumfb_set_par,
106 .fb_setcolreg = platinumfb_setcolreg,
107 .fb_blank = platinumfb_blank,
108 .fb_fillrect = cfb_fillrect,
109 .fb_copyarea = cfb_copyarea,
110 .fb_imageblit = cfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
113/*
114 * Checks a var structure
115 */
116static int platinumfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
117{
118 return platinum_var_to_par(var, info->par, 1);
119}
120
121/*
122 * Applies current var to display
123 */
124static int platinumfb_set_par (struct fb_info *info)
125{
126 struct fb_info_platinum *pinfo = info->par;
127 struct platinum_regvals *init;
128 int err, offset = 0x20;
129
130 if((err = platinum_var_to_par(&info->var, pinfo, 0))) {
131 printk (KERN_ERR "platinumfb_set_par: error calling"
132 " platinum_var_to_par: %d.\n", err);
133 return err;
134 }
135
136 platinum_set_hardware(pinfo);
137
138 init = platinum_reg_init[pinfo->vmode-1];
139
Benjamin Herrenschmidt9cf84d72005-12-13 17:48:35 +1100140 if ((pinfo->vmode == VMODE_832_624_75) && (pinfo->cmode > CMODE_8))
141 offset = 0x10;
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 info->screen_base = pinfo->frame_buffer + init->fb_offset + offset;
144 info->fix.smem_start = (pinfo->frame_buffer_phys) + init->fb_offset + offset;
145 info->fix.visual = (pinfo->cmode == CMODE_8) ?
146 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
Benjamin Herrenschmidt9cf84d72005-12-13 17:48:35 +1100147 info->fix.line_length = vmode_attrs[pinfo->vmode-1].hres * (1<<pinfo->cmode)
148 + offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 printk("line_length: %x\n", info->fix.line_length);
150 return 0;
151}
152
153static int platinumfb_blank(int blank, struct fb_info *fb)
154{
155/*
156 * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
157 * then the caller blanks by setting the CLUT (Color Look Up Table) to all
158 * black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due
159 * to e.g. a video mode which doesn't support it. Implements VESA suspend
160 * and powerdown modes on hardware that supports disabling hsync/vsync:
161 * blank_mode == 2: suspend vsync
162 * blank_mode == 3: suspend hsync
163 * blank_mode == 4: powerdown
164 */
165/* [danj] I think there's something fishy about those constants... */
166/*
167 struct fb_info_platinum *info = (struct fb_info_platinum *) fb;
168 int ctrl;
169
170 ctrl = ld_le32(&info->platinum_regs->ctrl.r) | 0x33;
171 if (blank)
172 --blank_mode;
173 if (blank & VESA_VSYNC_SUSPEND)
174 ctrl &= ~3;
175 if (blank & VESA_HSYNC_SUSPEND)
176 ctrl &= ~0x30;
177 out_le32(&info->platinum_regs->ctrl.r, ctrl);
178*/
179/* TODO: Figure out how the heck to powerdown this thing! */
180 return 0;
181}
182
183static int platinumfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
184 u_int transp, struct fb_info *info)
185{
186 struct fb_info_platinum *pinfo = info->par;
187 volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs;
188
189 if (regno > 255)
190 return 1;
191
192 red >>= 8;
193 green >>= 8;
194 blue >>= 8;
195
196 pinfo->palette[regno].red = red;
197 pinfo->palette[regno].green = green;
198 pinfo->palette[regno].blue = blue;
199
200 out_8(&cmap_regs->addr, regno); /* tell clut what addr to fill */
201 out_8(&cmap_regs->lut, red); /* send one color channel at */
202 out_8(&cmap_regs->lut, green); /* a time... */
203 out_8(&cmap_regs->lut, blue);
204
205 if (regno < 16) {
206 int i;
207 u32 *pal = info->pseudo_palette;
208 switch (pinfo->cmode) {
209 case CMODE_16:
210 pal[regno] = (regno << 10) | (regno << 5) | regno;
211 break;
212 case CMODE_32:
213 i = (regno << 8) | regno;
214 pal[regno] = (i << 16) | i;
215 break;
216 }
217 }
218
219 return 0;
220}
221
222static inline int platinum_vram_reqd(int video_mode, int color_mode)
223{
224 return vmode_attrs[video_mode-1].vres *
Benjamin Herrenschmidt9cf84d72005-12-13 17:48:35 +1100225 (vmode_attrs[video_mode-1].hres * (1<<color_mode) +
226 ((video_mode == VMODE_832_624_75) &&
227 (color_mode > CMODE_8)) ? 0x10 : 0x20) + 0x1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229
230#define STORE_D2(a, d) { \
231 out_8(&cmap_regs->addr, (a+32)); \
232 out_8(&cmap_regs->d2, (d)); \
233}
234
235static void set_platinum_clock(struct fb_info_platinum *pinfo)
236{
237 volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs;
238 struct platinum_regvals *init;
239
240 init = platinum_reg_init[pinfo->vmode-1];
241
242 STORE_D2(6, 0xc6);
243 out_8(&cmap_regs->addr,3+32);
244
245 if (in_8(&cmap_regs->d2) == 2) {
246 STORE_D2(7, init->clock_params[pinfo->clktype][0]);
247 STORE_D2(8, init->clock_params[pinfo->clktype][1]);
248 STORE_D2(3, 3);
249 } else {
250 STORE_D2(4, init->clock_params[pinfo->clktype][0]);
251 STORE_D2(5, init->clock_params[pinfo->clktype][1]);
252 STORE_D2(3, 2);
253 }
254
255 __delay(5000);
256 STORE_D2(9, 0xa6);
257}
258
259
260/* Now how about actually saying, Make it so! */
261/* Some things in here probably don't need to be done each time. */
262static void platinum_set_hardware(struct fb_info_platinum *pinfo)
263{
264 volatile struct platinum_regs __iomem *platinum_regs = pinfo->platinum_regs;
265 volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs;
266 struct platinum_regvals *init;
267 int i;
268 int vmode, cmode;
269
270 vmode = pinfo->vmode;
271 cmode = pinfo->cmode;
272
273 init = platinum_reg_init[vmode - 1];
274
275 /* Initialize display timing registers */
276 out_be32(&platinum_regs->reg[24].r, 7); /* turn display off */
277
278 for (i = 0; i < 26; ++i)
279 out_be32(&platinum_regs->reg[i+32].r, init->regs[i]);
280
281 out_be32(&platinum_regs->reg[26+32].r, (pinfo->total_vram == 0x100000 ?
282 init->offset[cmode] + 4 - cmode :
283 init->offset[cmode]));
284 out_be32(&platinum_regs->reg[16].r, (unsigned) pinfo->frame_buffer_phys+init->fb_offset+0x10);
285 out_be32(&platinum_regs->reg[18].r, init->pitch[cmode]);
286 out_be32(&platinum_regs->reg[19].r, (pinfo->total_vram == 0x100000 ?
287 init->mode[cmode+1] :
288 init->mode[cmode]));
289 out_be32(&platinum_regs->reg[20].r, (pinfo->total_vram == 0x100000 ? 0x11 : 0x1011));
290 out_be32(&platinum_regs->reg[21].r, 0x100);
291 out_be32(&platinum_regs->reg[22].r, 1);
292 out_be32(&platinum_regs->reg[23].r, 1);
293 out_be32(&platinum_regs->reg[26].r, 0xc00);
294 out_be32(&platinum_regs->reg[27].r, 0x235);
295 /* out_be32(&platinum_regs->reg[27].r, 0x2aa); */
296
297 STORE_D2(0, (pinfo->total_vram == 0x100000 ?
298 init->dacula_ctrl[cmode] & 0xf :
299 init->dacula_ctrl[cmode]));
300 STORE_D2(1, 4);
301 STORE_D2(2, 0);
302
303 set_platinum_clock(pinfo);
304
305 out_be32(&platinum_regs->reg[24].r, 0); /* turn display on */
306}
307
308/*
309 * Set misc info vars for this driver
310 */
311static void __devinit platinum_init_info(struct fb_info *info, struct fb_info_platinum *pinfo)
312{
313 /* Fill fb_info */
314 info->fbops = &platinumfb_ops;
315 info->pseudo_palette = pinfo->pseudo_palette;
316 info->flags = FBINFO_DEFAULT;
317 info->screen_base = pinfo->frame_buffer + 0x20;
318
319 fb_alloc_cmap(&info->cmap, 256, 0);
320
321 /* Fill fix common fields */
322 strcpy(info->fix.id, "platinum");
323 info->fix.mmio_start = pinfo->platinum_regs_phys;
324 info->fix.mmio_len = 0x1000;
325 info->fix.type = FB_TYPE_PACKED_PIXELS;
326 info->fix.smem_start = pinfo->frame_buffer_phys + 0x20; /* will be updated later */
327 info->fix.smem_len = pinfo->total_vram - 0x20;
328 info->fix.ywrapstep = 0;
329 info->fix.xpanstep = 0;
330 info->fix.ypanstep = 0;
331 info->fix.type_aux = 0;
332 info->fix.accel = FB_ACCEL_NONE;
333}
334
335
336static int __devinit platinum_init_fb(struct fb_info *info)
337{
338 struct fb_info_platinum *pinfo = info->par;
339 struct fb_var_screeninfo var;
340 int sense, rc;
341
342 sense = read_platinum_sense(pinfo);
343 printk(KERN_INFO "platinumfb: Monitor sense value = 0x%x, ", sense);
344
345 if (default_vmode == VMODE_NVRAM) {
346 default_vmode = nvram_read_byte(NV_VMODE);
347 if (default_vmode <= 0 || default_vmode > VMODE_MAX ||
348 !platinum_reg_init[default_vmode-1])
349 default_vmode = VMODE_CHOOSE;
350 }
351 if (default_vmode == VMODE_CHOOSE) {
352 default_vmode = mac_map_monitor_sense(sense);
353 }
354 if (default_vmode <= 0 || default_vmode > VMODE_MAX)
355 default_vmode = VMODE_640_480_60;
356 if (default_cmode == CMODE_NVRAM)
357 default_cmode = nvram_read_byte(NV_CMODE);
358 if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
359 default_cmode = CMODE_8;
360 /*
361 * Reduce the pixel size if we don't have enough VRAM.
362 */
363 while(default_cmode > CMODE_8 &&
364 platinum_vram_reqd(default_vmode, default_cmode) > pinfo->total_vram)
365 default_cmode--;
366
367 printk("platinumfb: Using video mode %d and color mode %d.\n", default_vmode, default_cmode);
368
369 /* Setup default var */
370 if (mac_vmode_to_var(default_vmode, default_cmode, &var) < 0) {
371 /* This shouldn't happen! */
372 printk("mac_vmode_to_var(%d, %d,) failed\n", default_vmode, default_cmode);
373try_again:
374 default_vmode = VMODE_640_480_60;
375 default_cmode = CMODE_8;
376 if (mac_vmode_to_var(default_vmode, default_cmode, &var) < 0) {
377 printk(KERN_ERR "platinumfb: mac_vmode_to_var() failed\n");
378 return -ENXIO;
379 }
380 }
381
382 /* Initialize info structure */
383 platinum_init_info(info, pinfo);
384
385 /* Apply default var */
386 info->var = var;
387 var.activate = FB_ACTIVATE_NOW;
388 rc = fb_set_var(info, &var);
389 if (rc && (default_vmode != VMODE_640_480_60 || default_cmode != CMODE_8))
390 goto try_again;
391
392 /* Register with fbdev layer */
393 rc = register_framebuffer(info);
394 if (rc < 0)
395 return rc;
396
397 printk(KERN_INFO "fb%d: Apple Platinum frame buffer device\n", info->node);
398
399 return 0;
400}
401
402/*
403 * Get the monitor sense value.
404 * Note that this can be called before calibrate_delay,
405 * so we can't use udelay.
406 */
407static int read_platinum_sense(struct fb_info_platinum *info)
408{
409 volatile struct platinum_regs __iomem *platinum_regs = info->platinum_regs;
410 int sense;
411
412 out_be32(&platinum_regs->reg[23].r, 7); /* turn off drivers */
413 __delay(2000);
414 sense = (~in_be32(&platinum_regs->reg[23].r) & 7) << 8;
415
416 /* drive each sense line low in turn and collect the other 2 */
417 out_be32(&platinum_regs->reg[23].r, 3); /* drive A low */
418 __delay(2000);
419 sense |= (~in_be32(&platinum_regs->reg[23].r) & 3) << 4;
420 out_be32(&platinum_regs->reg[23].r, 5); /* drive B low */
421 __delay(2000);
422 sense |= (~in_be32(&platinum_regs->reg[23].r) & 4) << 1;
423 sense |= (~in_be32(&platinum_regs->reg[23].r) & 1) << 2;
424 out_be32(&platinum_regs->reg[23].r, 6); /* drive C low */
425 __delay(2000);
426 sense |= (~in_be32(&platinum_regs->reg[23].r) & 6) >> 1;
427
428 out_be32(&platinum_regs->reg[23].r, 7); /* turn off drivers */
429
430 return sense;
431}
432
433/*
434 * This routine takes a user-supplied var, and picks the best vmode/cmode from it.
435 * It also updates the var structure to the actual mode data obtained
436 */
437static int platinum_var_to_par(struct fb_var_screeninfo *var,
438 struct fb_info_platinum *pinfo,
439 int check_only)
440{
441 int vmode, cmode;
442
443 if (mac_var_to_vmode(var, &vmode, &cmode) != 0) {
444 printk(KERN_ERR "platinum_var_to_par: mac_var_to_vmode unsuccessful.\n");
445 printk(KERN_ERR "platinum_var_to_par: var->xres = %d\n", var->xres);
446 printk(KERN_ERR "platinum_var_to_par: var->yres = %d\n", var->yres);
447 printk(KERN_ERR "platinum_var_to_par: var->xres_virtual = %d\n", var->xres_virtual);
448 printk(KERN_ERR "platinum_var_to_par: var->yres_virtual = %d\n", var->yres_virtual);
449 printk(KERN_ERR "platinum_var_to_par: var->bits_per_pixel = %d\n", var->bits_per_pixel);
450 printk(KERN_ERR "platinum_var_to_par: var->pixclock = %d\n", var->pixclock);
451 printk(KERN_ERR "platinum_var_to_par: var->vmode = %d\n", var->vmode);
452 return -EINVAL;
453 }
454
455 if (!platinum_reg_init[vmode-1]) {
456 printk(KERN_ERR "platinum_var_to_par, vmode %d not valid.\n", vmode);
457 return -EINVAL;
458 }
459
460 if (platinum_vram_reqd(vmode, cmode) > pinfo->total_vram) {
461 printk(KERN_ERR "platinum_var_to_par, not enough ram for vmode %d, cmode %d.\n", vmode, cmode);
462 return -EINVAL;
463 }
464
465 if (mac_vmode_to_var(vmode, cmode, var))
466 return -EINVAL;
467
468 if (check_only)
469 return 0;
470
471 pinfo->vmode = vmode;
472 pinfo->cmode = cmode;
473 pinfo->xres = vmode_attrs[vmode-1].hres;
474 pinfo->yres = vmode_attrs[vmode-1].vres;
475 pinfo->xoffset = 0;
476 pinfo->yoffset = 0;
477 pinfo->vxres = pinfo->xres;
478 pinfo->vyres = pinfo->yres;
479
480 return 0;
481}
482
483
484/*
485 * Parse user speficied options (`video=platinumfb:')
486 */
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100487static int __init platinumfb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489 char *this_opt;
490
491 if (!options || !*options)
492 return 0;
493
494 while ((this_opt = strsep(&options, ",")) != NULL) {
495 if (!strncmp(this_opt, "vmode:", 6)) {
496 int vmode = simple_strtoul(this_opt+6, NULL, 0);
497 if (vmode > 0 && vmode <= VMODE_MAX)
498 default_vmode = vmode;
499 } else if (!strncmp(this_opt, "cmode:", 6)) {
500 int depth = simple_strtoul(this_opt+6, NULL, 0);
501 switch (depth) {
502 case 0:
503 case 8:
504 default_cmode = CMODE_8;
505 break;
506 case 15:
507 case 16:
508 default_cmode = CMODE_16;
509 break;
510 case 24:
511 case 32:
512 default_cmode = CMODE_32;
513 break;
514 }
515 }
516 }
517 return 0;
518}
519
520#ifdef __powerpc__
521#define invalidate_cache(addr) \
522 asm volatile("eieio; dcbf 0,%1" \
523 : "=m" (*(addr)) : "r" (addr) : "memory");
524#else
525#define invalidate_cache(addr)
526#endif
527
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100528static int __devinit platinumfb_probe(struct of_device* odev,
529 const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
531 struct device_node *dp = odev->node;
532 struct fb_info *info;
533 struct fb_info_platinum *pinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 volatile __u8 *fbuffer;
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100535 int bank0, bank1, bank2, bank3, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 printk(KERN_INFO "platinumfb: Found Apple Platinum video hardware\n");
538
539 info = framebuffer_alloc(sizeof(*pinfo), &odev->dev);
540 if (info == NULL)
541 return -ENOMEM;
542 pinfo = info->par;
543
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100544 if (of_address_to_resource(dp, 0, &pinfo->rsrc_reg) ||
545 of_address_to_resource(dp, 1, &pinfo->rsrc_fb)) {
546 printk(KERN_ERR "platinumfb: Can't get resources\n");
547 framebuffer_release(info);
548 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 }
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100550 if (!request_mem_region(pinfo->rsrc_reg.start,
551 pinfo->rsrc_reg.start -
552 pinfo->rsrc_reg.end + 1,
553 "platinumfb registers")) {
554 framebuffer_release(info);
555 return -ENXIO;
556 }
557 if (!request_mem_region(pinfo->rsrc_fb.start,
558 pinfo->rsrc_fb.start
559 - pinfo->rsrc_fb.end + 1,
560 "platinumfb framebuffer")) {
561 release_mem_region(pinfo->rsrc_reg.start,
562 pinfo->rsrc_reg.end -
563 pinfo->rsrc_reg.start + 1);
564 framebuffer_release(info);
565 return -ENXIO;
566 }
567
568 /* frame buffer - map only 4MB */
569 pinfo->frame_buffer_phys = pinfo->rsrc_fb.start;
570 pinfo->frame_buffer = __ioremap(pinfo->rsrc_fb.start, 0x400000,
571 _PAGE_WRITETHRU);
572 pinfo->base_frame_buffer = pinfo->frame_buffer;
573
574 /* registers */
575 pinfo->platinum_regs_phys = pinfo->rsrc_reg.start;
576 pinfo->platinum_regs = ioremap(pinfo->rsrc_reg.start, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 pinfo->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */
579 request_mem_region(pinfo->cmap_regs_phys, 0x1000, "platinumfb cmap");
580 pinfo->cmap_regs = ioremap(pinfo->cmap_regs_phys, 0x1000);
581
582 /* Grok total video ram */
583 out_be32(&pinfo->platinum_regs->reg[16].r, (unsigned)pinfo->frame_buffer_phys);
584 out_be32(&pinfo->platinum_regs->reg[20].r, 0x1011); /* select max vram */
585 out_be32(&pinfo->platinum_regs->reg[24].r, 0); /* switch in vram */
586
587 fbuffer = pinfo->base_frame_buffer;
588 fbuffer[0x100000] = 0x34;
589 fbuffer[0x100008] = 0x0;
590 invalidate_cache(&fbuffer[0x100000]);
591 fbuffer[0x200000] = 0x56;
592 fbuffer[0x200008] = 0x0;
593 invalidate_cache(&fbuffer[0x200000]);
594 fbuffer[0x300000] = 0x78;
595 fbuffer[0x300008] = 0x0;
596 invalidate_cache(&fbuffer[0x300000]);
597 bank0 = 1; /* builtin 1MB vram, always there */
598 bank1 = fbuffer[0x100000] == 0x34;
599 bank2 = fbuffer[0x200000] == 0x56;
600 bank3 = fbuffer[0x300000] == 0x78;
601 pinfo->total_vram = (bank0 + bank1 + bank2 + bank3) * 0x100000;
602 printk(KERN_INFO "platinumfb: Total VRAM = %dMB (%d%d%d%d)\n", (int) (pinfo->total_vram / 1024 / 1024),
603 bank3, bank2, bank1, bank0);
604
605 /*
606 * Try to determine whether we have an old or a new DACula.
607 */
608 out_8(&pinfo->cmap_regs->addr, 0x40);
609 pinfo->dactype = in_8(&pinfo->cmap_regs->d2);
610 switch (pinfo->dactype) {
611 case 0x3c:
612 pinfo->clktype = 1;
613 printk(KERN_INFO "platinumfb: DACula type 0x3c\n");
614 break;
615 case 0x84:
616 pinfo->clktype = 0;
617 printk(KERN_INFO "platinumfb: DACula type 0x84\n");
618 break;
619 default:
620 pinfo->clktype = 0;
621 printk(KERN_INFO "platinumfb: Unknown DACula type: %x\n", pinfo->dactype);
622 break;
623 }
624 dev_set_drvdata(&odev->dev, info);
625
626 rc = platinum_init_fb(info);
627 if (rc != 0) {
628 dev_set_drvdata(&odev->dev, NULL);
629 framebuffer_release(info);
630 }
631
632 return rc;
633}
634
635static int __devexit platinumfb_remove(struct of_device* odev)
636{
637 struct fb_info *info = dev_get_drvdata(&odev->dev);
638 struct fb_info_platinum *pinfo = info->par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 unregister_framebuffer (info);
641
642 /* Unmap frame buffer and registers */
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100643 release_mem_region(pinfo->rsrc_fb.start,
644 pinfo->rsrc_fb.end -
645 pinfo->rsrc_fb.start + 1);
646 release_mem_region(pinfo->rsrc_reg.start,
647 pinfo->rsrc_reg.end -
648 pinfo->rsrc_reg.start + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 iounmap(pinfo->frame_buffer);
650 iounmap(pinfo->platinum_regs);
651 release_mem_region(pinfo->cmap_regs_phys, 0x1000);
652 iounmap(pinfo->cmap_regs);
653
654 framebuffer_release(info);
655
656 return 0;
657}
658
Jeff Mahoney5e655772005-07-06 15:44:41 -0400659static struct of_device_id platinumfb_match[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
661 {
662 .name = "platinum",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 },
664 {},
665};
666
667static struct of_platform_driver platinum_driver =
668{
669 .name = "platinumfb",
670 .match_table = platinumfb_match,
671 .probe = platinumfb_probe,
672 .remove = platinumfb_remove,
673};
674
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100675static int __init platinumfb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
677#ifndef MODULE
678 char *option = NULL;
679
680 if (fb_get_options("platinumfb", &option))
681 return -ENODEV;
682 platinumfb_setup(option);
683#endif
684 of_register_driver(&platinum_driver);
685
686 return 0;
687}
688
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100689static void __exit platinumfb_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 of_unregister_driver(&platinum_driver);
692}
693
694MODULE_LICENSE("GPL");
695MODULE_DESCRIPTION("framebuffer driver for Apple Platinum video");
696module_init(platinumfb_init);
697
698#ifdef MODULE
699module_exit(platinumfb_exit);
700#endif