blob: ca4082ae5a18d34313a3a71c7ef2b34b977a484e [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;
72};
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
100int platinumfb_init(void);
101int platinumfb_setup(char*);
102
103static struct fb_ops platinumfb_ops = {
104 .owner = THIS_MODULE,
105 .fb_check_var = platinumfb_check_var,
106 .fb_set_par = platinumfb_set_par,
107 .fb_setcolreg = platinumfb_setcolreg,
108 .fb_blank = platinumfb_blank,
109 .fb_fillrect = cfb_fillrect,
110 .fb_copyarea = cfb_copyarea,
111 .fb_imageblit = cfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
114/*
115 * Checks a var structure
116 */
117static int platinumfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
118{
119 return platinum_var_to_par(var, info->par, 1);
120}
121
122/*
123 * Applies current var to display
124 */
125static int platinumfb_set_par (struct fb_info *info)
126{
127 struct fb_info_platinum *pinfo = info->par;
128 struct platinum_regvals *init;
129 int err, offset = 0x20;
130
131 if((err = platinum_var_to_par(&info->var, pinfo, 0))) {
132 printk (KERN_ERR "platinumfb_set_par: error calling"
133 " platinum_var_to_par: %d.\n", err);
134 return err;
135 }
136
137 platinum_set_hardware(pinfo);
138
139 init = platinum_reg_init[pinfo->vmode-1];
140
141 if (pinfo->vmode == 13 && pinfo->cmode > 0)
142 offset = 0x10;
143 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;
147 info->fix.line_length = vmode_attrs[pinfo->vmode-1].hres * (1<<pinfo->cmode) + offset;
148 printk("line_length: %x\n", info->fix.line_length);
149 return 0;
150}
151
152static 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 = ld_le32(&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
182static 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
221static inline int platinum_vram_reqd(int video_mode, int color_mode)
222{
223 return vmode_attrs[video_mode-1].vres *
224 (vmode_attrs[video_mode-1].hres * (1<<color_mode) + 0x20) +0x1000;
225}
226
227#define STORE_D2(a, d) { \
228 out_8(&cmap_regs->addr, (a+32)); \
229 out_8(&cmap_regs->d2, (d)); \
230}
231
232static void set_platinum_clock(struct fb_info_platinum *pinfo)
233{
234 volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs;
235 struct platinum_regvals *init;
236
237 init = platinum_reg_init[pinfo->vmode-1];
238
239 STORE_D2(6, 0xc6);
240 out_8(&cmap_regs->addr,3+32);
241
242 if (in_8(&cmap_regs->d2) == 2) {
243 STORE_D2(7, init->clock_params[pinfo->clktype][0]);
244 STORE_D2(8, init->clock_params[pinfo->clktype][1]);
245 STORE_D2(3, 3);
246 } else {
247 STORE_D2(4, init->clock_params[pinfo->clktype][0]);
248 STORE_D2(5, init->clock_params[pinfo->clktype][1]);
249 STORE_D2(3, 2);
250 }
251
252 __delay(5000);
253 STORE_D2(9, 0xa6);
254}
255
256
257/* Now how about actually saying, Make it so! */
258/* Some things in here probably don't need to be done each time. */
259static void platinum_set_hardware(struct fb_info_platinum *pinfo)
260{
261 volatile struct platinum_regs __iomem *platinum_regs = pinfo->platinum_regs;
262 volatile struct cmap_regs __iomem *cmap_regs = pinfo->cmap_regs;
263 struct platinum_regvals *init;
264 int i;
265 int vmode, cmode;
266
267 vmode = pinfo->vmode;
268 cmode = pinfo->cmode;
269
270 init = platinum_reg_init[vmode - 1];
271
272 /* Initialize display timing registers */
273 out_be32(&platinum_regs->reg[24].r, 7); /* turn display off */
274
275 for (i = 0; i < 26; ++i)
276 out_be32(&platinum_regs->reg[i+32].r, init->regs[i]);
277
278 out_be32(&platinum_regs->reg[26+32].r, (pinfo->total_vram == 0x100000 ?
279 init->offset[cmode] + 4 - cmode :
280 init->offset[cmode]));
281 out_be32(&platinum_regs->reg[16].r, (unsigned) pinfo->frame_buffer_phys+init->fb_offset+0x10);
282 out_be32(&platinum_regs->reg[18].r, init->pitch[cmode]);
283 out_be32(&platinum_regs->reg[19].r, (pinfo->total_vram == 0x100000 ?
284 init->mode[cmode+1] :
285 init->mode[cmode]));
286 out_be32(&platinum_regs->reg[20].r, (pinfo->total_vram == 0x100000 ? 0x11 : 0x1011));
287 out_be32(&platinum_regs->reg[21].r, 0x100);
288 out_be32(&platinum_regs->reg[22].r, 1);
289 out_be32(&platinum_regs->reg[23].r, 1);
290 out_be32(&platinum_regs->reg[26].r, 0xc00);
291 out_be32(&platinum_regs->reg[27].r, 0x235);
292 /* out_be32(&platinum_regs->reg[27].r, 0x2aa); */
293
294 STORE_D2(0, (pinfo->total_vram == 0x100000 ?
295 init->dacula_ctrl[cmode] & 0xf :
296 init->dacula_ctrl[cmode]));
297 STORE_D2(1, 4);
298 STORE_D2(2, 0);
299
300 set_platinum_clock(pinfo);
301
302 out_be32(&platinum_regs->reg[24].r, 0); /* turn display on */
303}
304
305/*
306 * Set misc info vars for this driver
307 */
308static void __devinit platinum_init_info(struct fb_info *info, struct fb_info_platinum *pinfo)
309{
310 /* Fill fb_info */
311 info->fbops = &platinumfb_ops;
312 info->pseudo_palette = pinfo->pseudo_palette;
313 info->flags = FBINFO_DEFAULT;
314 info->screen_base = pinfo->frame_buffer + 0x20;
315
316 fb_alloc_cmap(&info->cmap, 256, 0);
317
318 /* Fill fix common fields */
319 strcpy(info->fix.id, "platinum");
320 info->fix.mmio_start = pinfo->platinum_regs_phys;
321 info->fix.mmio_len = 0x1000;
322 info->fix.type = FB_TYPE_PACKED_PIXELS;
323 info->fix.smem_start = pinfo->frame_buffer_phys + 0x20; /* will be updated later */
324 info->fix.smem_len = pinfo->total_vram - 0x20;
325 info->fix.ywrapstep = 0;
326 info->fix.xpanstep = 0;
327 info->fix.ypanstep = 0;
328 info->fix.type_aux = 0;
329 info->fix.accel = FB_ACCEL_NONE;
330}
331
332
333static int __devinit platinum_init_fb(struct fb_info *info)
334{
335 struct fb_info_platinum *pinfo = info->par;
336 struct fb_var_screeninfo var;
337 int sense, rc;
338
339 sense = read_platinum_sense(pinfo);
340 printk(KERN_INFO "platinumfb: Monitor sense value = 0x%x, ", sense);
341
342 if (default_vmode == VMODE_NVRAM) {
343 default_vmode = nvram_read_byte(NV_VMODE);
344 if (default_vmode <= 0 || default_vmode > VMODE_MAX ||
345 !platinum_reg_init[default_vmode-1])
346 default_vmode = VMODE_CHOOSE;
347 }
348 if (default_vmode == VMODE_CHOOSE) {
349 default_vmode = mac_map_monitor_sense(sense);
350 }
351 if (default_vmode <= 0 || default_vmode > VMODE_MAX)
352 default_vmode = VMODE_640_480_60;
353 if (default_cmode == CMODE_NVRAM)
354 default_cmode = nvram_read_byte(NV_CMODE);
355 if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
356 default_cmode = CMODE_8;
357 /*
358 * Reduce the pixel size if we don't have enough VRAM.
359 */
360 while(default_cmode > CMODE_8 &&
361 platinum_vram_reqd(default_vmode, default_cmode) > pinfo->total_vram)
362 default_cmode--;
363
364 printk("platinumfb: Using video mode %d and color mode %d.\n", default_vmode, default_cmode);
365
366 /* Setup default var */
367 if (mac_vmode_to_var(default_vmode, default_cmode, &var) < 0) {
368 /* This shouldn't happen! */
369 printk("mac_vmode_to_var(%d, %d,) failed\n", default_vmode, default_cmode);
370try_again:
371 default_vmode = VMODE_640_480_60;
372 default_cmode = CMODE_8;
373 if (mac_vmode_to_var(default_vmode, default_cmode, &var) < 0) {
374 printk(KERN_ERR "platinumfb: mac_vmode_to_var() failed\n");
375 return -ENXIO;
376 }
377 }
378
379 /* Initialize info structure */
380 platinum_init_info(info, pinfo);
381
382 /* Apply default var */
383 info->var = var;
384 var.activate = FB_ACTIVATE_NOW;
385 rc = fb_set_var(info, &var);
386 if (rc && (default_vmode != VMODE_640_480_60 || default_cmode != CMODE_8))
387 goto try_again;
388
389 /* Register with fbdev layer */
390 rc = register_framebuffer(info);
391 if (rc < 0)
392 return rc;
393
394 printk(KERN_INFO "fb%d: Apple Platinum frame buffer device\n", info->node);
395
396 return 0;
397}
398
399/*
400 * Get the monitor sense value.
401 * Note that this can be called before calibrate_delay,
402 * so we can't use udelay.
403 */
404static int read_platinum_sense(struct fb_info_platinum *info)
405{
406 volatile struct platinum_regs __iomem *platinum_regs = info->platinum_regs;
407 int sense;
408
409 out_be32(&platinum_regs->reg[23].r, 7); /* turn off drivers */
410 __delay(2000);
411 sense = (~in_be32(&platinum_regs->reg[23].r) & 7) << 8;
412
413 /* drive each sense line low in turn and collect the other 2 */
414 out_be32(&platinum_regs->reg[23].r, 3); /* drive A low */
415 __delay(2000);
416 sense |= (~in_be32(&platinum_regs->reg[23].r) & 3) << 4;
417 out_be32(&platinum_regs->reg[23].r, 5); /* drive B low */
418 __delay(2000);
419 sense |= (~in_be32(&platinum_regs->reg[23].r) & 4) << 1;
420 sense |= (~in_be32(&platinum_regs->reg[23].r) & 1) << 2;
421 out_be32(&platinum_regs->reg[23].r, 6); /* drive C low */
422 __delay(2000);
423 sense |= (~in_be32(&platinum_regs->reg[23].r) & 6) >> 1;
424
425 out_be32(&platinum_regs->reg[23].r, 7); /* turn off drivers */
426
427 return sense;
428}
429
430/*
431 * This routine takes a user-supplied var, and picks the best vmode/cmode from it.
432 * It also updates the var structure to the actual mode data obtained
433 */
434static int platinum_var_to_par(struct fb_var_screeninfo *var,
435 struct fb_info_platinum *pinfo,
436 int check_only)
437{
438 int vmode, cmode;
439
440 if (mac_var_to_vmode(var, &vmode, &cmode) != 0) {
441 printk(KERN_ERR "platinum_var_to_par: mac_var_to_vmode unsuccessful.\n");
442 printk(KERN_ERR "platinum_var_to_par: var->xres = %d\n", var->xres);
443 printk(KERN_ERR "platinum_var_to_par: var->yres = %d\n", var->yres);
444 printk(KERN_ERR "platinum_var_to_par: var->xres_virtual = %d\n", var->xres_virtual);
445 printk(KERN_ERR "platinum_var_to_par: var->yres_virtual = %d\n", var->yres_virtual);
446 printk(KERN_ERR "platinum_var_to_par: var->bits_per_pixel = %d\n", var->bits_per_pixel);
447 printk(KERN_ERR "platinum_var_to_par: var->pixclock = %d\n", var->pixclock);
448 printk(KERN_ERR "platinum_var_to_par: var->vmode = %d\n", var->vmode);
449 return -EINVAL;
450 }
451
452 if (!platinum_reg_init[vmode-1]) {
453 printk(KERN_ERR "platinum_var_to_par, vmode %d not valid.\n", vmode);
454 return -EINVAL;
455 }
456
457 if (platinum_vram_reqd(vmode, cmode) > pinfo->total_vram) {
458 printk(KERN_ERR "platinum_var_to_par, not enough ram for vmode %d, cmode %d.\n", vmode, cmode);
459 return -EINVAL;
460 }
461
462 if (mac_vmode_to_var(vmode, cmode, var))
463 return -EINVAL;
464
465 if (check_only)
466 return 0;
467
468 pinfo->vmode = vmode;
469 pinfo->cmode = cmode;
470 pinfo->xres = vmode_attrs[vmode-1].hres;
471 pinfo->yres = vmode_attrs[vmode-1].vres;
472 pinfo->xoffset = 0;
473 pinfo->yoffset = 0;
474 pinfo->vxres = pinfo->xres;
475 pinfo->vyres = pinfo->yres;
476
477 return 0;
478}
479
480
481/*
482 * Parse user speficied options (`video=platinumfb:')
483 */
484int __init platinumfb_setup(char *options)
485{
486 char *this_opt;
487
488 if (!options || !*options)
489 return 0;
490
491 while ((this_opt = strsep(&options, ",")) != NULL) {
492 if (!strncmp(this_opt, "vmode:", 6)) {
493 int vmode = simple_strtoul(this_opt+6, NULL, 0);
494 if (vmode > 0 && vmode <= VMODE_MAX)
495 default_vmode = vmode;
496 } else if (!strncmp(this_opt, "cmode:", 6)) {
497 int depth = simple_strtoul(this_opt+6, NULL, 0);
498 switch (depth) {
499 case 0:
500 case 8:
501 default_cmode = CMODE_8;
502 break;
503 case 15:
504 case 16:
505 default_cmode = CMODE_16;
506 break;
507 case 24:
508 case 32:
509 default_cmode = CMODE_32;
510 break;
511 }
512 }
513 }
514 return 0;
515}
516
517#ifdef __powerpc__
518#define invalidate_cache(addr) \
519 asm volatile("eieio; dcbf 0,%1" \
520 : "=m" (*(addr)) : "r" (addr) : "memory");
521#else
522#define invalidate_cache(addr)
523#endif
524
Jeff Mahoney5e655772005-07-06 15:44:41 -0400525static int __devinit platinumfb_probe(struct of_device* odev, const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
527 struct device_node *dp = odev->node;
528 struct fb_info *info;
529 struct fb_info_platinum *pinfo;
530 unsigned long addr, size;
531 volatile __u8 *fbuffer;
532 int i, bank0, bank1, bank2, bank3, rc;
533
534 if (dp->n_addrs != 2) {
535 printk(KERN_ERR "expecting 2 address for platinum (got %d)", dp->n_addrs);
536 return -ENXIO;
537 }
538 printk(KERN_INFO "platinumfb: Found Apple Platinum video hardware\n");
539
540 info = framebuffer_alloc(sizeof(*pinfo), &odev->dev);
541 if (info == NULL)
542 return -ENOMEM;
543 pinfo = info->par;
544
545 /* Map in frame buffer and registers */
546 for (i = 0; i < dp->n_addrs; ++i) {
547 addr = dp->addrs[i].address;
548 size = dp->addrs[i].size;
549 /* Let's assume we can request either all or nothing */
550 if (!request_mem_region(addr, size, "platinumfb")) {
551 framebuffer_release(info);
552 return -ENXIO;
553 }
554 if (size >= 0x400000) {
555 /* frame buffer - map only 4MB */
556 pinfo->frame_buffer_phys = addr;
557 pinfo->frame_buffer = __ioremap(addr, 0x400000, _PAGE_WRITETHRU);
558 pinfo->base_frame_buffer = pinfo->frame_buffer;
559 } else {
560 /* registers */
561 pinfo->platinum_regs_phys = addr;
562 pinfo->platinum_regs = ioremap(addr, size);
563 }
564 }
565
566 pinfo->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */
567 request_mem_region(pinfo->cmap_regs_phys, 0x1000, "platinumfb cmap");
568 pinfo->cmap_regs = ioremap(pinfo->cmap_regs_phys, 0x1000);
569
570 /* Grok total video ram */
571 out_be32(&pinfo->platinum_regs->reg[16].r, (unsigned)pinfo->frame_buffer_phys);
572 out_be32(&pinfo->platinum_regs->reg[20].r, 0x1011); /* select max vram */
573 out_be32(&pinfo->platinum_regs->reg[24].r, 0); /* switch in vram */
574
575 fbuffer = pinfo->base_frame_buffer;
576 fbuffer[0x100000] = 0x34;
577 fbuffer[0x100008] = 0x0;
578 invalidate_cache(&fbuffer[0x100000]);
579 fbuffer[0x200000] = 0x56;
580 fbuffer[0x200008] = 0x0;
581 invalidate_cache(&fbuffer[0x200000]);
582 fbuffer[0x300000] = 0x78;
583 fbuffer[0x300008] = 0x0;
584 invalidate_cache(&fbuffer[0x300000]);
585 bank0 = 1; /* builtin 1MB vram, always there */
586 bank1 = fbuffer[0x100000] == 0x34;
587 bank2 = fbuffer[0x200000] == 0x56;
588 bank3 = fbuffer[0x300000] == 0x78;
589 pinfo->total_vram = (bank0 + bank1 + bank2 + bank3) * 0x100000;
590 printk(KERN_INFO "platinumfb: Total VRAM = %dMB (%d%d%d%d)\n", (int) (pinfo->total_vram / 1024 / 1024),
591 bank3, bank2, bank1, bank0);
592
593 /*
594 * Try to determine whether we have an old or a new DACula.
595 */
596 out_8(&pinfo->cmap_regs->addr, 0x40);
597 pinfo->dactype = in_8(&pinfo->cmap_regs->d2);
598 switch (pinfo->dactype) {
599 case 0x3c:
600 pinfo->clktype = 1;
601 printk(KERN_INFO "platinumfb: DACula type 0x3c\n");
602 break;
603 case 0x84:
604 pinfo->clktype = 0;
605 printk(KERN_INFO "platinumfb: DACula type 0x84\n");
606 break;
607 default:
608 pinfo->clktype = 0;
609 printk(KERN_INFO "platinumfb: Unknown DACula type: %x\n", pinfo->dactype);
610 break;
611 }
612 dev_set_drvdata(&odev->dev, info);
613
614 rc = platinum_init_fb(info);
615 if (rc != 0) {
616 dev_set_drvdata(&odev->dev, NULL);
617 framebuffer_release(info);
618 }
619
620 return rc;
621}
622
623static int __devexit platinumfb_remove(struct of_device* odev)
624{
625 struct fb_info *info = dev_get_drvdata(&odev->dev);
626 struct fb_info_platinum *pinfo = info->par;
627 struct device_node *dp = odev->node;
628 unsigned long addr, size;
629 int i;
630
631 unregister_framebuffer (info);
632
633 /* Unmap frame buffer and registers */
634 for (i = 0; i < dp->n_addrs; ++i) {
635 addr = dp->addrs[i].address;
636 size = dp->addrs[i].size;
637 release_mem_region(addr, size);
638 }
639 iounmap(pinfo->frame_buffer);
640 iounmap(pinfo->platinum_regs);
641 release_mem_region(pinfo->cmap_regs_phys, 0x1000);
642 iounmap(pinfo->cmap_regs);
643
644 framebuffer_release(info);
645
646 return 0;
647}
648
Jeff Mahoney5e655772005-07-06 15:44:41 -0400649static struct of_device_id platinumfb_match[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
651 {
652 .name = "platinum",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 },
654 {},
655};
656
657static struct of_platform_driver platinum_driver =
658{
659 .name = "platinumfb",
660 .match_table = platinumfb_match,
661 .probe = platinumfb_probe,
662 .remove = platinumfb_remove,
663};
664
665int __init platinumfb_init(void)
666{
667#ifndef MODULE
668 char *option = NULL;
669
670 if (fb_get_options("platinumfb", &option))
671 return -ENODEV;
672 platinumfb_setup(option);
673#endif
674 of_register_driver(&platinum_driver);
675
676 return 0;
677}
678
679void __exit platinumfb_exit(void)
680{
681 of_unregister_driver(&platinum_driver);
682}
683
684MODULE_LICENSE("GPL");
685MODULE_DESCRIPTION("framebuffer driver for Apple Platinum video");
686module_init(platinumfb_init);
687
688#ifdef MODULE
689module_exit(platinumfb_exit);
690#endif