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