2 * linux/drivers/video/pm3fb.c -- 3DLabs Permedia3 frame buffer device
4 * Copyright (C) 2001 Romain Dolbeau <romain@dolbeau.org>.
6 * Ported to 2.6 kernel on 1 May 2007 by Krzysztof Helt <krzysztof.h1@wp.pl>
9 * Based on code written by:
10 * Sven Luther, <luther@dpt-info.u-strasbg.fr>
11 * Alan Hourihane, <alanh@fairlite.demon.co.uk>
12 * Russell King, <rmk@arm.linux.org.uk>
13 * Based on linux/drivers/video/skeletonfb.c:
14 * Copyright (C) 1997 Geert Uytterhoeven
15 * Based on linux/driver/video/pm2fb.c:
16 * Copyright (C) 1998-1999 Ilario Nardinocchi (nardinoc@CS.UniBO.IT)
17 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
19 * This file is subject to the terms and conditions of the GNU General Public
20 * License. See the file COPYING in the main directory of this archive for
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/string.h>
30 #include <linux/slab.h>
31 #include <linux/delay.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
36 #include <video/pm3fb.h>
38 #if !defined(CONFIG_PCI)
39 #error "Only generic PCI cards supported."
42 #undef PM3FB_MASTER_DEBUG
43 #ifdef PM3FB_MASTER_DEBUG
44 #define DPRINTK(a,b...) printk(KERN_DEBUG "pm3fb: %s: " a, __FUNCTION__ , ## b)
46 #define DPRINTK(a,b...)
52 static char *mode_option __devinitdata;
55 * This structure defines the hardware state of the graphics card. Normally
56 * you place this in a header file in linux/include/video. This file usually
57 * also includes register information. That allows other driver subsystems
58 * and userland applications the ability to use the same header file to
59 * avoid duplicate work and easy porting of software.
62 unsigned char __iomem *v_regs;/* virtual address of p_regs */
63 u32 video; /* video flags before blanking */
64 u32 base; /* screen base (xoffset+yoffset) in 128 bits unit */
69 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
70 * if we don't use modedb. If we do use modedb see pm3fb_init how to use it
71 * to get a fb_var_screeninfo. Otherwise define a default var as well.
73 static struct fb_fix_screeninfo pm3fb_fix __devinitdata = {
75 .type = FB_TYPE_PACKED_PIXELS,
76 .visual = FB_VISUAL_PSEUDOCOLOR,
80 .accel = FB_ACCEL_NONE,
87 static inline u32 PM3_READ_REG(struct pm3_par *par, s32 off)
89 return fb_readl(par->v_regs + off);
92 static inline void PM3_WRITE_REG(struct pm3_par *par, s32 off, u32 v)
94 fb_writel(v, par->v_regs + off);
97 static inline void PM3_WAIT(struct pm3_par *par, u32 n)
99 while (PM3_READ_REG(par, PM3InFIFOSpace) < n);
102 static inline void PM3_WRITE_DAC_REG(struct pm3_par *par, unsigned r, u8 v)
105 PM3_WRITE_REG(par, PM3RD_IndexHigh, (r >> 8) & 0xff);
106 PM3_WRITE_REG(par, PM3RD_IndexLow, r & 0xff);
108 PM3_WRITE_REG(par, PM3RD_IndexedData, v);
112 static inline void pm3fb_set_color(struct pm3_par *par, unsigned char regno,
113 unsigned char r, unsigned char g, unsigned char b)
116 PM3_WRITE_REG(par, PM3RD_PaletteWriteAddress, regno);
118 PM3_WRITE_REG(par, PM3RD_PaletteData, r);
120 PM3_WRITE_REG(par, PM3RD_PaletteData, g);
122 PM3_WRITE_REG(par, PM3RD_PaletteData, b);
126 static void pm3fb_clear_colormap(struct pm3_par *par,
127 unsigned char r, unsigned char g, unsigned char b)
131 for (i = 0; i < 256 ; i++)
132 pm3fb_set_color(par, i, r, g, b);
136 /* Calculating various clock parameter */
137 static void pm3fb_calculate_clock(unsigned long reqclock,
138 unsigned char *prescale,
139 unsigned char *feedback,
140 unsigned char *postscale)
147 for (f = 1; f < 256; f++) {
148 for (pre = 1; pre < 256; pre++) {
149 for (post = 0; post < 5; post++) {
150 freq = ((2*PM3_REF_CLOCK * f) >> post) / pre;
151 currerr = (reqclock > freq)
154 if (currerr < freqerr) {
165 static inline int pm3fb_depth(const struct fb_var_screeninfo *var)
167 if ( var->bits_per_pixel == 16 )
168 return var->red.length + var->green.length
171 return var->bits_per_pixel;
174 static inline int pm3fb_shift_bpp(unsigned bpp, int v)
184 DPRINTK("Unsupported depth %u\n", bpp);
188 /* write the mode to registers */
189 static void pm3fb_write_mode(struct fb_info *info)
191 struct pm3_par *par = info->par;
192 char tempsync = 0x00, tempmisc = 0x00;
193 const u32 hsstart = info->var.right_margin;
194 const u32 hsend = hsstart + info->var.hsync_len;
195 const u32 hbend = hsend + info->var.left_margin;
196 const u32 xres = (info->var.xres + 31) & ~31;
197 const u32 htotal = xres + hbend;
198 const u32 vsstart = info->var.lower_margin;
199 const u32 vsend = vsstart + info->var.vsync_len;
200 const u32 vbend = vsend + info->var.upper_margin;
201 const u32 vtotal = info->var.yres + vbend;
202 const u32 width = (info->var.xres_virtual + 7) & ~7;
203 const unsigned bpp = info->var.bits_per_pixel;
206 PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xffffffff);
207 PM3_WRITE_REG(par, PM3Aperture0, 0x00000000);
208 PM3_WRITE_REG(par, PM3Aperture1, 0x00000000);
209 PM3_WRITE_REG(par, PM3FIFODis, 0x00000007);
211 PM3_WRITE_REG(par, PM3HTotal,
212 pm3fb_shift_bpp(bpp, htotal - 1));
213 PM3_WRITE_REG(par, PM3HsEnd,
214 pm3fb_shift_bpp(bpp, hsend));
215 PM3_WRITE_REG(par, PM3HsStart,
216 pm3fb_shift_bpp(bpp, hsstart));
217 PM3_WRITE_REG(par, PM3HbEnd,
218 pm3fb_shift_bpp(bpp, hbend));
219 PM3_WRITE_REG(par, PM3HgEnd,
220 pm3fb_shift_bpp(bpp, hbend));
221 PM3_WRITE_REG(par, PM3ScreenStride,
222 pm3fb_shift_bpp(bpp, width));
223 PM3_WRITE_REG(par, PM3VTotal, vtotal - 1);
224 PM3_WRITE_REG(par, PM3VsEnd, vsend - 1);
225 PM3_WRITE_REG(par, PM3VsStart, vsstart - 1);
226 PM3_WRITE_REG(par, PM3VbEnd, vbend);
230 PM3_WRITE_REG(par, PM3ByAperture1Mode,
231 PM3ByApertureMode_PIXELSIZE_8BIT);
232 PM3_WRITE_REG(par, PM3ByAperture2Mode,
233 PM3ByApertureMode_PIXELSIZE_8BIT);
238 PM3_WRITE_REG(par, PM3ByAperture1Mode,
239 PM3ByApertureMode_PIXELSIZE_16BIT);
240 PM3_WRITE_REG(par, PM3ByAperture2Mode,
241 PM3ByApertureMode_PIXELSIZE_16BIT);
243 PM3_WRITE_REG(par, PM3ByAperture1Mode,
244 PM3ByApertureMode_PIXELSIZE_16BIT |
245 PM3ByApertureMode_BYTESWAP_BADC);
246 PM3_WRITE_REG(par, PM3ByAperture2Mode,
247 PM3ByApertureMode_PIXELSIZE_16BIT |
248 PM3ByApertureMode_BYTESWAP_BADC);
249 #endif /* ! __BIG_ENDIAN */
254 PM3_WRITE_REG(par, PM3ByAperture1Mode,
255 PM3ByApertureMode_PIXELSIZE_32BIT);
256 PM3_WRITE_REG(par, PM3ByAperture2Mode,
257 PM3ByApertureMode_PIXELSIZE_32BIT);
259 PM3_WRITE_REG(par, PM3ByAperture1Mode,
260 PM3ByApertureMode_PIXELSIZE_32BIT |
261 PM3ByApertureMode_BYTESWAP_DCBA);
262 PM3_WRITE_REG(par, PM3ByAperture2Mode,
263 PM3ByApertureMode_PIXELSIZE_32BIT |
264 PM3ByApertureMode_BYTESWAP_DCBA);
265 #endif /* ! __BIG_ENDIAN */
269 DPRINTK("Unsupported depth %d\n", bpp);
274 * Oxygen VX1 - it appears that setting PM3VideoControl and
275 * then PM3RD_SyncControl to the same SYNC settings undoes
276 * any net change - they seem to xor together. Only set the
277 * sync options in PM3RD_SyncControl. --rmk
280 unsigned int video = par->video;
282 video &= ~(PM3VideoControl_HSYNC_MASK |
283 PM3VideoControl_VSYNC_MASK);
284 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
285 PM3VideoControl_VSYNC_ACTIVE_HIGH;
286 PM3_WRITE_REG(par, PM3VideoControl, video);
288 PM3_WRITE_REG(par, PM3VClkCtl,
289 (PM3_READ_REG(par, PM3VClkCtl) & 0xFFFFFFFC));
290 PM3_WRITE_REG(par, PM3ScreenBase, par->base);
291 PM3_WRITE_REG(par, PM3ChipConfig,
292 (PM3_READ_REG(par, PM3ChipConfig) & 0xFFFFFFFD));
296 unsigned char uninitialized_var(m); /* ClkPreScale */
297 unsigned char uninitialized_var(n); /* ClkFeedBackScale */
298 unsigned char uninitialized_var(p); /* ClkPostScale */
299 unsigned long pixclock = PICOS2KHZ(info->var.pixclock);
301 (void)pm3fb_calculate_clock(pixclock, &m, &n, &p);
303 DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n",
304 pixclock, (int) m, (int) n, (int) p);
306 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PreScale, m);
307 PM3_WRITE_DAC_REG(par, PM3RD_DClk0FeedbackScale, n);
308 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PostScale, p);
311 PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00);
314 PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00);
316 if ((par->video & PM3VideoControl_HSYNC_MASK) ==
317 PM3VideoControl_HSYNC_ACTIVE_HIGH)
318 tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH;
319 if ((par->video & PM3VideoControl_VSYNC_MASK) ==
320 PM3VideoControl_VSYNC_ACTIVE_HIGH)
321 tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH;
323 PM3_WRITE_DAC_REG(par, PM3RD_SyncControl, tempsync);
324 DPRINTK("PM3RD_SyncControl: %d\n", tempsync);
326 PM3_WRITE_DAC_REG(par, PM3RD_DACControl, 0x00);
328 switch (pm3fb_depth(&info->var)) {
330 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
331 PM3RD_PixelSize_8_BIT_PIXELS);
332 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
333 PM3RD_ColorFormat_CI8_COLOR |
334 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
335 tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
338 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
339 PM3RD_PixelSize_16_BIT_PIXELS);
340 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
341 PM3RD_ColorFormat_4444_COLOR |
342 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
343 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
344 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
345 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
348 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
349 PM3RD_PixelSize_16_BIT_PIXELS);
350 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
351 PM3RD_ColorFormat_5551_FRONT_COLOR |
352 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
353 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
354 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
355 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
358 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
359 PM3RD_PixelSize_16_BIT_PIXELS);
360 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
361 PM3RD_ColorFormat_565_FRONT_COLOR |
362 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
363 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
364 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
365 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
368 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
369 PM3RD_PixelSize_32_BIT_PIXELS);
370 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
371 PM3RD_ColorFormat_8888_COLOR |
372 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
373 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
374 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
377 PM3_WRITE_DAC_REG(par, PM3RD_MiscControl, tempmisc);
381 * hardware independent functions
383 int pm3fb_init(void);
385 static int pm3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
388 unsigned bpp = var->red.length + var->green.length
389 + var->blue.length + var->transp.length;
391 if ( bpp != var->bits_per_pixel ) {
392 /* set predefined mode for bits_per_pixel settings */
394 switch(var->bits_per_pixel) {
396 var->red.length = var->green.length = var->blue.length = 8;
397 var->red.offset = var->green.offset = var->blue.offset = 0;
398 var->transp.offset = 0;
399 var->transp.length = 0;
402 var->red.length = var->blue.length = 5;
403 var->green.length = 6;
404 var->transp.length = 0;
407 var->red.length = var->green.length = var->blue.length = 8;
408 var->transp.length = 8;
411 DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
415 /* it is assumed BGRA order */
416 if (var->bits_per_pixel > 8 )
418 var->blue.offset = 0;
419 var->green.offset = var->blue.length;
420 var->red.offset = var->green.offset + var->green.length;
421 var->transp.offset = var->red.offset + var->red.length;
423 var->height = var->width = -1;
425 if (var->xres != var->xres_virtual) {
426 DPRINTK("virtual x resolution != physical x resolution not supported\n");
430 if (var->yres > var->yres_virtual) {
431 DPRINTK("virtual y resolution < physical y resolution not possible\n");
436 DPRINTK("xoffset not supported\n");
440 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
441 DPRINTK("interlace not supported\n");
445 var->xres = (var->xres + 31) & ~31; /* could sometimes be 8 */
446 lpitch = var->xres * ((var->bits_per_pixel + 7)>>3);
448 if (var->xres < 200 || var->xres > 2048) {
449 DPRINTK("width not supported: %u\n", var->xres);
453 if (var->yres < 200 || var->yres > 4095) {
454 DPRINTK("height not supported: %u\n", var->yres);
458 if (lpitch * var->yres_virtual > info->fix.smem_len) {
459 DPRINTK("no memory for screen (%ux%ux%u)\n",
460 var->xres, var->yres_virtual, var->bits_per_pixel);
464 if (PICOS2KHZ(var->pixclock) > PM3_MAX_PIXCLOCK) {
465 DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock));
469 var->accel_flags = 0; /* Can't mmap if this is on */
471 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
472 var->xres, var->yres, var->bits_per_pixel);
476 static int pm3fb_set_par(struct fb_info *info)
478 struct pm3_par *par = info->par;
479 const u32 xres = (info->var.xres + 31) & ~31;
480 const unsigned bpp = info->var.bits_per_pixel;
482 par->base = pm3fb_shift_bpp(bpp,(info->var.yoffset * xres)
483 + info->var.xoffset);
486 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
487 par->video |= PM3VideoControl_HSYNC_ACTIVE_HIGH;
489 par->video |= PM3VideoControl_HSYNC_ACTIVE_LOW;
491 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
492 par->video |= PM3VideoControl_VSYNC_ACTIVE_HIGH;
494 par->video |= PM3VideoControl_VSYNC_ACTIVE_LOW;
496 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
497 par->video |= PM3VideoControl_LINE_DOUBLE_ON;
499 par->video |= PM3VideoControl_LINE_DOUBLE_OFF;
501 if (info->var.activate == FB_ACTIVATE_NOW)
502 par->video |= PM3VideoControl_ENABLE;
504 par->video |= PM3VideoControl_DISABLE;
505 DPRINTK("PM3Video disabled\n");
509 par->video |= PM3VideoControl_PIXELSIZE_8BIT;
512 par->video |= PM3VideoControl_PIXELSIZE_16BIT;
515 par->video |= PM3VideoControl_PIXELSIZE_32BIT;
518 DPRINTK("Unsupported depth\n");
523 (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
524 info->fix.line_length = ((info->var.xres_virtual + 7) & ~7)
527 /* pm3fb_clear_memory(info, 0);*/
528 pm3fb_clear_colormap(par, 0, 0, 0);
529 PM3_WRITE_DAC_REG(par, PM3RD_CursorMode,
530 PM3RD_CursorMode_CURSOR_DISABLE);
531 pm3fb_write_mode(info);
535 static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
536 unsigned blue, unsigned transp,
537 struct fb_info *info)
539 struct pm3_par *par = info->par;
541 if (regno >= 256) /* no. of hw registers */
544 /* grayscale works only partially under directcolor */
545 if (info->var.grayscale) {
546 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
547 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
551 * var->{color}.offset contains start of bitfield
552 * var->{color}.length contains length of bitfield
553 * {hardwarespecific} contains width of DAC
554 * pseudo_palette[X] is programmed to (X << red.offset) |
555 * (X << green.offset) |
557 * RAMDAC[X] is programmed to (red, green, blue)
558 * color depth = SUM(var->{color}.length)
561 * var->{color}.offset is 0
562 * var->{color}.length contains width of DAC or the number of unique
563 * colors available (color depth)
564 * pseudo_palette is not used
565 * RAMDAC[X] is programmed to (red, green, blue)
566 * color depth = var->{color}.length
570 * This is the point where the color is converted to something that
571 * is acceptable by the hardware.
573 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
574 red = CNVT_TOHW(red, info->var.red.length);
575 green = CNVT_TOHW(green, info->var.green.length);
576 blue = CNVT_TOHW(blue, info->var.blue.length);
577 transp = CNVT_TOHW(transp, info->var.transp.length);
580 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
581 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
587 v = (red << info->var.red.offset) |
588 (green << info->var.green.offset) |
589 (blue << info->var.blue.offset) |
590 (transp << info->var.transp.offset);
592 switch (info->var.bits_per_pixel) {
597 ((u32*)(info->pseudo_palette))[regno] = v;
602 else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
603 pm3fb_set_color(par, regno, red, green, blue);
608 static int pm3fb_pan_display(struct fb_var_screeninfo *var,
609 struct fb_info *info)
611 struct pm3_par *par = info->par;
612 const u32 xres = (var->xres + 31) & ~31;
614 par->base = pm3fb_shift_bpp(var->bits_per_pixel,
615 (var->yoffset * xres)
618 PM3_WRITE_REG(par, PM3ScreenBase, par->base);
622 static int pm3fb_blank(int blank_mode, struct fb_info *info)
624 struct pm3_par *par = info->par;
625 u32 video = par->video;
628 * Oxygen VX1 - it appears that setting PM3VideoControl and
629 * then PM3RD_SyncControl to the same SYNC settings undoes
630 * any net change - they seem to xor together. Only set the
631 * sync options in PM3RD_SyncControl. --rmk
633 video &= ~(PM3VideoControl_HSYNC_MASK |
634 PM3VideoControl_VSYNC_MASK);
635 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
636 PM3VideoControl_VSYNC_ACTIVE_HIGH;
638 switch (blank_mode) {
639 case FB_BLANK_UNBLANK:
640 video |= PM3VideoControl_ENABLE;
642 case FB_BLANK_NORMAL:
643 video &= ~(PM3VideoControl_ENABLE);
645 case FB_BLANK_HSYNC_SUSPEND:
646 video &= ~(PM3VideoControl_HSYNC_MASK |
647 PM3VideoControl_BLANK_ACTIVE_LOW);
649 case FB_BLANK_VSYNC_SUSPEND:
650 video &= ~(PM3VideoControl_VSYNC_MASK |
651 PM3VideoControl_BLANK_ACTIVE_LOW);
653 case FB_BLANK_POWERDOWN:
654 video &= ~(PM3VideoControl_HSYNC_MASK |
655 PM3VideoControl_VSYNC_MASK |
656 PM3VideoControl_BLANK_ACTIVE_LOW);
659 DPRINTK("Unsupported blanking %d\n", blank_mode);
664 PM3_WRITE_REG(par,PM3VideoControl, video);
669 * Frame buffer operations
672 static struct fb_ops pm3fb_ops = {
673 .owner = THIS_MODULE,
674 .fb_check_var = pm3fb_check_var,
675 .fb_set_par = pm3fb_set_par,
676 .fb_setcolreg = pm3fb_setcolreg,
677 .fb_pan_display = pm3fb_pan_display,
678 .fb_fillrect = cfb_fillrect,
679 .fb_copyarea = cfb_copyarea,
680 .fb_imageblit = cfb_imageblit,
681 .fb_blank = pm3fb_blank,
684 /* ------------------------------------------------------------------------- */
690 /* mmio register are already mapped when this function is called */
691 /* the pm3fb_fix.smem_start is also set */
692 static unsigned long pm3fb_size_memory(struct pm3_par *par)
694 unsigned long memsize = 0, tempBypass, i, temp1, temp2;
695 unsigned char __iomem *screen_mem;
697 pm3fb_fix.smem_len = 64 * 1024l * 1024; /* request full aperture size */
698 /* Linear frame buffer - request region and map it. */
699 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
701 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
705 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
707 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
708 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
712 /* TODO: card-specific stuff, *before* accessing *any* FB memory */
713 /* For Appian Jeronimo 2000 board second head */
715 tempBypass = PM3_READ_REG(par, PM3MemBypassWriteMask);
717 DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass);
720 PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xFFFFFFFF);
722 /* pm3 split up memory, replicates, and do a lot of nasty stuff IMHO ;-) */
723 for (i = 0; i < 32; i++) {
724 fb_writel(i * 0x00345678,
725 (screen_mem + (i * 1048576)));
727 temp1 = fb_readl((screen_mem + (i * 1048576)));
729 /* Let's check for wrapover, write will fail at 16MB boundary */
730 if (temp1 == (i * 0x00345678))
736 DPRINTK("First detect pass already got %ld MB\n", memsize + 1);
738 if (memsize + 1 == i) {
739 for (i = 0; i < 32; i++) {
740 /* Clear first 32MB ; 0 is 0, no need to byteswap */
741 writel(0x0000000, (screen_mem + (i * 1048576)));
745 for (i = 32; i < 64; i++) {
746 fb_writel(i * 0x00345678,
747 (screen_mem + (i * 1048576)));
750 fb_readl((screen_mem + (i * 1048576)));
752 fb_readl((screen_mem + ((i - 32) * 1048576)));
753 /* different value, different RAM... */
754 if ((temp1 == (i * 0x00345678)) && (temp2 == 0))
760 DPRINTK("Second detect pass got %ld MB\n", memsize + 1);
763 PM3_WRITE_REG(par, PM3MemBypassWriteMask, tempBypass);
766 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
767 memsize = 1048576 * (memsize + 1);
769 DPRINTK("Returning 0x%08lx bytes\n", memsize);
774 static int __devinit pm3fb_probe(struct pci_dev *dev,
775 const struct pci_device_id *ent)
777 struct fb_info *info;
779 struct device* device = &dev->dev; /* for pci drivers */
780 int err, retval = -ENXIO;
782 err = pci_enable_device(dev);
784 printk(KERN_WARNING "pm3fb: Can't enable PCI dev: %d\n", err);
788 * Dynamically allocate info and par
790 info = framebuffer_alloc(sizeof(struct pm3_par), device);
797 * Here we set the screen_base to the virtual memory address
798 * for the framebuffer.
800 pm3fb_fix.mmio_start = pci_resource_start(dev, 0);
801 pm3fb_fix.mmio_len = PM3_REGS_SIZE;
803 /* Registers - request region and map it. */
804 if (!request_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len,
806 printk(KERN_WARNING "pm3fb: Can't reserve regbase.\n");
807 goto err_exit_neither;
810 ioremap_nocache(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
812 printk(KERN_WARNING "pm3fb: Can't remap %s register area.\n",
814 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
815 goto err_exit_neither;
818 #if defined(__BIG_ENDIAN)
819 pm3fb_fix.mmio_start += PM3_REGS_SIZE;
820 DPRINTK("Adjusting register base for big-endian.\n");
822 /* Linear frame buffer - request region and map it. */
823 pm3fb_fix.smem_start = pci_resource_start(dev, 1);
824 pm3fb_fix.smem_len = pm3fb_size_memory(par);
825 if (!pm3fb_fix.smem_len)
827 printk(KERN_WARNING "pm3fb: Can't find memory on board.\n");
830 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
832 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
836 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
837 if (!info->screen_base) {
838 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
839 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
842 info->screen_size = pm3fb_fix.smem_len;
844 info->fbops = &pm3fb_ops;
846 par->video = PM3_READ_REG(par, PM3VideoControl);
848 info->fix = pm3fb_fix;
849 info->pseudo_palette = par->palette;
850 info->flags = FBINFO_DEFAULT;/* | FBINFO_HWACCEL_YPAN;*/
853 * This should give a reasonable default video mode. The following is
854 * done when we can set a video mode.
857 mode_option = "640x480@60";
859 retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
861 if (!retval || retval == 4) {
866 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
872 * For drivers that can...
874 pm3fb_check_var(&info->var, info);
876 if (register_framebuffer(info) < 0) {
880 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
882 pci_set_drvdata(dev, info);
886 fb_dealloc_cmap(&info->cmap);
888 iounmap(info->screen_base);
889 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
891 iounmap(par->v_regs);
892 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
894 framebuffer_release(info);
901 static void __devexit pm3fb_remove(struct pci_dev *dev)
903 struct fb_info *info = pci_get_drvdata(dev);
906 struct fb_fix_screeninfo *fix = &info->fix;
907 struct pm3_par *par = info->par;
909 unregister_framebuffer(info);
910 fb_dealloc_cmap(&info->cmap);
912 iounmap(info->screen_base);
913 release_mem_region(fix->smem_start, fix->smem_len);
914 iounmap(par->v_regs);
915 release_mem_region(fix->mmio_start, fix->mmio_len);
917 pci_set_drvdata(dev, NULL);
918 framebuffer_release(info);
922 static struct pci_device_id pm3fb_id_table[] = {
923 { PCI_VENDOR_ID_3DLABS, 0x0a,
924 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
928 /* For PCI drivers */
929 static struct pci_driver pm3fb_driver = {
931 .id_table = pm3fb_id_table,
932 .probe = pm3fb_probe,
933 .remove = __devexit_p(pm3fb_remove),
936 MODULE_DEVICE_TABLE(pci, pm3fb_id_table);
944 * Only necessary if your driver takes special options,
945 * otherwise we fall back on the generic fb_setup().
947 static int __init pm3fb_setup(char *options)
949 /* Parse user speficied options (`video=pm3fb:') */
954 int __init pm3fb_init(void)
957 * For kernel boot options (in 'video=pm3fb:<options>' format)
962 if (fb_get_options("pm3fb", &option))
967 return pci_register_driver(&pm3fb_driver);
970 static void __exit pm3fb_exit(void)
972 pci_unregister_driver(&pm3fb_driver);
975 module_init(pm3fb_init);
976 module_exit(pm3fb_exit);
978 MODULE_LICENSE("GPL");