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