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