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_3DLABS_PERMEDIA3,
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);
189 static int pm3fb_sync(struct fb_info *info)
191 struct pm3_par *par = info->par;
194 PM3_WRITE_REG(par, PM3FilterMode, PM3FilterModeSync);
195 PM3_WRITE_REG(par, PM3Sync, 0);
198 while ((PM3_READ_REG(par, PM3OutFIFOWords)) == 0);
200 } while ((PM3_READ_REG(par, PM3OutputFifo)) != PM3Sync_Tag);
205 static void pm3fb_init_engine(struct fb_info *info)
207 struct pm3_par *par = info->par;
208 const u32 width = (info->var.xres_virtual + 7) & ~7;
211 PM3_WRITE_REG(par, PM3FilterMode, PM3FilterModeSync);
212 PM3_WRITE_REG(par, PM3StatisticMode, 0x0);
213 PM3_WRITE_REG(par, PM3DeltaMode, 0x0);
214 PM3_WRITE_REG(par, PM3RasterizerMode, 0x0);
215 PM3_WRITE_REG(par, PM3ScissorMode, 0x0);
216 PM3_WRITE_REG(par, PM3LineStippleMode, 0x0);
217 PM3_WRITE_REG(par, PM3AreaStippleMode, 0x0);
218 PM3_WRITE_REG(par, PM3GIDMode, 0x0);
219 PM3_WRITE_REG(par, PM3DepthMode, 0x0);
220 PM3_WRITE_REG(par, PM3StencilMode, 0x0);
221 PM3_WRITE_REG(par, PM3StencilData, 0x0);
222 PM3_WRITE_REG(par, PM3ColorDDAMode, 0x0);
223 PM3_WRITE_REG(par, PM3TextureCoordMode, 0x0);
224 PM3_WRITE_REG(par, PM3TextureIndexMode0, 0x0);
225 PM3_WRITE_REG(par, PM3TextureIndexMode1, 0x0);
226 PM3_WRITE_REG(par, PM3TextureReadMode, 0x0);
227 PM3_WRITE_REG(par, PM3LUTMode, 0x0);
228 PM3_WRITE_REG(par, PM3TextureFilterMode, 0x0);
229 PM3_WRITE_REG(par, PM3TextureCompositeMode, 0x0);
230 PM3_WRITE_REG(par, PM3TextureApplicationMode, 0x0);
231 PM3_WRITE_REG(par, PM3TextureCompositeColorMode1, 0x0);
232 PM3_WRITE_REG(par, PM3TextureCompositeAlphaMode1, 0x0);
233 PM3_WRITE_REG(par, PM3TextureCompositeColorMode0, 0x0);
234 PM3_WRITE_REG(par, PM3TextureCompositeAlphaMode0, 0x0);
235 PM3_WRITE_REG(par, PM3FogMode, 0x0);
236 PM3_WRITE_REG(par, PM3ChromaTestMode, 0x0);
237 PM3_WRITE_REG(par, PM3AlphaTestMode, 0x0);
238 PM3_WRITE_REG(par, PM3AntialiasMode, 0x0);
239 PM3_WRITE_REG(par, PM3YUVMode, 0x0);
240 PM3_WRITE_REG(par, PM3AlphaBlendColorMode, 0x0);
241 PM3_WRITE_REG(par, PM3AlphaBlendAlphaMode, 0x0);
242 PM3_WRITE_REG(par, PM3DitherMode, 0x0);
243 PM3_WRITE_REG(par, PM3LogicalOpMode, 0x0);
244 PM3_WRITE_REG(par, PM3RouterMode, 0x0);
245 PM3_WRITE_REG(par, PM3Window, 0x0);
247 PM3_WRITE_REG(par, PM3Config2D, 0x0);
249 PM3_WRITE_REG(par, PM3SpanColorMask, 0xffffffff);
251 PM3_WRITE_REG(par, PM3XBias, 0x0);
252 PM3_WRITE_REG(par, PM3YBias, 0x0);
253 PM3_WRITE_REG(par, PM3DeltaControl, 0x0);
255 PM3_WRITE_REG(par, PM3BitMaskPattern, 0xffffffff);
257 PM3_WRITE_REG(par, PM3FBDestReadEnables,
258 PM3FBDestReadEnables_E(0xff) |
259 PM3FBDestReadEnables_R(0xff) |
260 PM3FBDestReadEnables_ReferenceAlpha(0xff));
261 PM3_WRITE_REG(par, PM3FBDestReadBufferAddr0, 0x0);
262 PM3_WRITE_REG(par, PM3FBDestReadBufferOffset0, 0x0);
263 PM3_WRITE_REG(par, PM3FBDestReadBufferWidth0,
264 PM3FBDestReadBufferWidth_Width(width));
266 PM3_WRITE_REG(par, PM3FBDestReadMode,
267 PM3FBDestReadMode_ReadEnable |
268 PM3FBDestReadMode_Enable0);
269 PM3_WRITE_REG(par, PM3FBSourceReadBufferAddr, 0x0);
270 PM3_WRITE_REG(par, PM3FBSourceReadBufferOffset, 0x0);
271 PM3_WRITE_REG(par, PM3FBSourceReadBufferWidth,
272 PM3FBSourceReadBufferWidth_Width(width));
273 PM3_WRITE_REG(par, PM3FBSourceReadMode,
274 PM3FBSourceReadMode_Blocking |
275 PM3FBSourceReadMode_ReadEnable);
279 unsigned long rm = 1;
280 switch (info->var.bits_per_pixel) {
282 PM3_WRITE_REG(par, PM3PixelSize,
283 PM3PixelSize_GLOBAL_8BIT);
286 PM3_WRITE_REG(par, PM3PixelSize,
287 PM3PixelSize_GLOBAL_16BIT);
290 PM3_WRITE_REG(par, PM3PixelSize,
291 PM3PixelSize_GLOBAL_32BIT);
294 DPRINTK(1, "Unsupported depth %d\n",
295 info->var.bits_per_pixel);
298 PM3_WRITE_REG(par, PM3RasterizerMode, rm);
302 PM3_WRITE_REG(par, PM3FBSoftwareWriteMask, 0xffffffff);
303 PM3_WRITE_REG(par, PM3FBHardwareWriteMask, 0xffffffff);
304 PM3_WRITE_REG(par, PM3FBWriteMode,
305 PM3FBWriteMode_WriteEnable |
306 PM3FBWriteMode_OpaqueSpan |
307 PM3FBWriteMode_Enable0);
308 PM3_WRITE_REG(par, PM3FBWriteBufferAddr0, 0x0);
309 PM3_WRITE_REG(par, PM3FBWriteBufferOffset0, 0x0);
310 PM3_WRITE_REG(par, PM3FBWriteBufferWidth0,
311 PM3FBWriteBufferWidth_Width(width));
313 PM3_WRITE_REG(par, PM3SizeOfFramebuffer, 0x0);
315 /* size in lines of FB */
316 unsigned long sofb = info->screen_size /
317 info->fix.line_length;
319 PM3_WRITE_REG(par, PM3SizeOfFramebuffer, 4095);
321 PM3_WRITE_REG(par, PM3SizeOfFramebuffer, sofb);
323 switch (info->var.bits_per_pixel) {
325 PM3_WRITE_REG(par, PM3DitherMode,
326 (1 << 10) | (2 << 3));
329 PM3_WRITE_REG(par, PM3DitherMode,
330 (1 << 10) | (1 << 3));
333 PM3_WRITE_REG(par, PM3DitherMode,
334 (1 << 10) | (0 << 3));
337 DPRINTK(1, "Unsupported depth %d\n",
338 info->current_par->depth);
343 PM3_WRITE_REG(par, PM3dXDom, 0x0);
344 PM3_WRITE_REG(par, PM3dXSub, 0x0);
345 PM3_WRITE_REG(par, PM3dY, (1 << 16));
346 PM3_WRITE_REG(par, PM3StartXDom, 0x0);
347 PM3_WRITE_REG(par, PM3StartXSub, 0x0);
348 PM3_WRITE_REG(par, PM3StartY, 0x0);
349 PM3_WRITE_REG(par, PM3Count, 0x0);
351 /* Disable LocalBuffer. better safe than sorry */
352 PM3_WRITE_REG(par, PM3LBDestReadMode, 0x0);
353 PM3_WRITE_REG(par, PM3LBDestReadEnables, 0x0);
354 PM3_WRITE_REG(par, PM3LBSourceReadMode, 0x0);
355 PM3_WRITE_REG(par, PM3LBWriteMode, 0x0);
360 static void pm3fb_fillrect (struct fb_info *info,
361 const struct fb_fillrect *region)
363 struct pm3_par *par = info->par;
364 struct fb_fillrect modded;
366 u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
367 ((u32*)info->pseudo_palette)[region->color] : region->color;
369 if (info->state != FBINFO_STATE_RUNNING)
371 if ((info->flags & FBINFO_HWACCEL_DISABLED) ||
372 region->rop != ROP_COPY ) {
373 cfb_fillrect(info, region);
377 vxres = info->var.xres_virtual;
378 vyres = info->var.yres_virtual;
380 memcpy(&modded, region, sizeof(struct fb_fillrect));
382 if(!modded.width || !modded.height ||
383 modded.dx >= vxres || modded.dy >= vyres)
386 if(modded.dx + modded.width > vxres)
387 modded.width = vxres - modded.dx;
388 if(modded.dy + modded.height > vyres)
389 modded.height = vyres - modded.dy;
391 if(info->var.bits_per_pixel == 8)
393 if(info->var.bits_per_pixel <= 16)
394 color |= color << 16;
398 PM3_WRITE_REG(par, PM3Config2D,
399 PM3Config2D_UseConstantSource |
400 PM3Config2D_ForegroundROPEnable |
401 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
402 PM3Config2D_FBWriteEnable);
404 PM3_WRITE_REG(par, PM3ForegroundColor, color);
406 PM3_WRITE_REG(par, PM3RectanglePosition,
407 (PM3RectanglePosition_XOffset(modded.dx)) |
408 (PM3RectanglePosition_YOffset(modded.dy)));
410 PM3_WRITE_REG(par, PM3Render2D,
411 PM3Render2D_XPositive |
412 PM3Render2D_YPositive |
413 PM3Render2D_Operation_Normal |
414 PM3Render2D_SpanOperation |
415 (PM3Render2D_Width(modded.width)) |
416 (PM3Render2D_Height(modded.height)));
418 /* end of acceleration functions */
420 /* write the mode to registers */
421 static void pm3fb_write_mode(struct fb_info *info)
423 struct pm3_par *par = info->par;
424 char tempsync = 0x00, tempmisc = 0x00;
425 const u32 hsstart = info->var.right_margin;
426 const u32 hsend = hsstart + info->var.hsync_len;
427 const u32 hbend = hsend + info->var.left_margin;
428 const u32 xres = (info->var.xres + 31) & ~31;
429 const u32 htotal = xres + hbend;
430 const u32 vsstart = info->var.lower_margin;
431 const u32 vsend = vsstart + info->var.vsync_len;
432 const u32 vbend = vsend + info->var.upper_margin;
433 const u32 vtotal = info->var.yres + vbend;
434 const u32 width = (info->var.xres_virtual + 7) & ~7;
435 const unsigned bpp = info->var.bits_per_pixel;
438 PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xffffffff);
439 PM3_WRITE_REG(par, PM3Aperture0, 0x00000000);
440 PM3_WRITE_REG(par, PM3Aperture1, 0x00000000);
441 PM3_WRITE_REG(par, PM3FIFODis, 0x00000007);
443 PM3_WRITE_REG(par, PM3HTotal,
444 pm3fb_shift_bpp(bpp, htotal - 1));
445 PM3_WRITE_REG(par, PM3HsEnd,
446 pm3fb_shift_bpp(bpp, hsend));
447 PM3_WRITE_REG(par, PM3HsStart,
448 pm3fb_shift_bpp(bpp, hsstart));
449 PM3_WRITE_REG(par, PM3HbEnd,
450 pm3fb_shift_bpp(bpp, hbend));
451 PM3_WRITE_REG(par, PM3HgEnd,
452 pm3fb_shift_bpp(bpp, hbend));
453 PM3_WRITE_REG(par, PM3ScreenStride,
454 pm3fb_shift_bpp(bpp, width));
455 PM3_WRITE_REG(par, PM3VTotal, vtotal - 1);
456 PM3_WRITE_REG(par, PM3VsEnd, vsend - 1);
457 PM3_WRITE_REG(par, PM3VsStart, vsstart - 1);
458 PM3_WRITE_REG(par, PM3VbEnd, vbend);
462 PM3_WRITE_REG(par, PM3ByAperture1Mode,
463 PM3ByApertureMode_PIXELSIZE_8BIT);
464 PM3_WRITE_REG(par, PM3ByAperture2Mode,
465 PM3ByApertureMode_PIXELSIZE_8BIT);
470 PM3_WRITE_REG(par, PM3ByAperture1Mode,
471 PM3ByApertureMode_PIXELSIZE_16BIT);
472 PM3_WRITE_REG(par, PM3ByAperture2Mode,
473 PM3ByApertureMode_PIXELSIZE_16BIT);
475 PM3_WRITE_REG(par, PM3ByAperture1Mode,
476 PM3ByApertureMode_PIXELSIZE_16BIT |
477 PM3ByApertureMode_BYTESWAP_BADC);
478 PM3_WRITE_REG(par, PM3ByAperture2Mode,
479 PM3ByApertureMode_PIXELSIZE_16BIT |
480 PM3ByApertureMode_BYTESWAP_BADC);
481 #endif /* ! __BIG_ENDIAN */
486 PM3_WRITE_REG(par, PM3ByAperture1Mode,
487 PM3ByApertureMode_PIXELSIZE_32BIT);
488 PM3_WRITE_REG(par, PM3ByAperture2Mode,
489 PM3ByApertureMode_PIXELSIZE_32BIT);
491 PM3_WRITE_REG(par, PM3ByAperture1Mode,
492 PM3ByApertureMode_PIXELSIZE_32BIT |
493 PM3ByApertureMode_BYTESWAP_DCBA);
494 PM3_WRITE_REG(par, PM3ByAperture2Mode,
495 PM3ByApertureMode_PIXELSIZE_32BIT |
496 PM3ByApertureMode_BYTESWAP_DCBA);
497 #endif /* ! __BIG_ENDIAN */
501 DPRINTK("Unsupported depth %d\n", bpp);
506 * Oxygen VX1 - it appears that setting PM3VideoControl and
507 * then PM3RD_SyncControl to the same SYNC settings undoes
508 * any net change - they seem to xor together. Only set the
509 * sync options in PM3RD_SyncControl. --rmk
512 unsigned int video = par->video;
514 video &= ~(PM3VideoControl_HSYNC_MASK |
515 PM3VideoControl_VSYNC_MASK);
516 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
517 PM3VideoControl_VSYNC_ACTIVE_HIGH;
518 PM3_WRITE_REG(par, PM3VideoControl, video);
520 PM3_WRITE_REG(par, PM3VClkCtl,
521 (PM3_READ_REG(par, PM3VClkCtl) & 0xFFFFFFFC));
522 PM3_WRITE_REG(par, PM3ScreenBase, par->base);
523 PM3_WRITE_REG(par, PM3ChipConfig,
524 (PM3_READ_REG(par, PM3ChipConfig) & 0xFFFFFFFD));
528 unsigned char uninitialized_var(m); /* ClkPreScale */
529 unsigned char uninitialized_var(n); /* ClkFeedBackScale */
530 unsigned char uninitialized_var(p); /* ClkPostScale */
531 unsigned long pixclock = PICOS2KHZ(info->var.pixclock);
533 (void)pm3fb_calculate_clock(pixclock, &m, &n, &p);
535 DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n",
536 pixclock, (int) m, (int) n, (int) p);
538 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PreScale, m);
539 PM3_WRITE_DAC_REG(par, PM3RD_DClk0FeedbackScale, n);
540 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PostScale, p);
543 PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00);
546 PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00);
548 if ((par->video & PM3VideoControl_HSYNC_MASK) ==
549 PM3VideoControl_HSYNC_ACTIVE_HIGH)
550 tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH;
551 if ((par->video & PM3VideoControl_VSYNC_MASK) ==
552 PM3VideoControl_VSYNC_ACTIVE_HIGH)
553 tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH;
555 PM3_WRITE_DAC_REG(par, PM3RD_SyncControl, tempsync);
556 DPRINTK("PM3RD_SyncControl: %d\n", tempsync);
558 PM3_WRITE_DAC_REG(par, PM3RD_DACControl, 0x00);
560 switch (pm3fb_depth(&info->var)) {
562 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
563 PM3RD_PixelSize_8_BIT_PIXELS);
564 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
565 PM3RD_ColorFormat_CI8_COLOR |
566 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
567 tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
570 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
571 PM3RD_PixelSize_16_BIT_PIXELS);
572 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
573 PM3RD_ColorFormat_4444_COLOR |
574 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
575 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
576 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
577 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
580 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
581 PM3RD_PixelSize_16_BIT_PIXELS);
582 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
583 PM3RD_ColorFormat_5551_FRONT_COLOR |
584 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
585 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
586 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
587 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
590 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
591 PM3RD_PixelSize_16_BIT_PIXELS);
592 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
593 PM3RD_ColorFormat_565_FRONT_COLOR |
594 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
595 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
596 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
597 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
600 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
601 PM3RD_PixelSize_32_BIT_PIXELS);
602 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
603 PM3RD_ColorFormat_8888_COLOR |
604 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
605 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
606 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
609 PM3_WRITE_DAC_REG(par, PM3RD_MiscControl, tempmisc);
613 * hardware independent functions
615 static int pm3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
618 unsigned bpp = var->red.length + var->green.length
619 + var->blue.length + var->transp.length;
621 if ( bpp != var->bits_per_pixel ) {
622 /* set predefined mode for bits_per_pixel settings */
624 switch(var->bits_per_pixel) {
626 var->red.length = var->green.length = var->blue.length = 8;
627 var->red.offset = var->green.offset = var->blue.offset = 0;
628 var->transp.offset = 0;
629 var->transp.length = 0;
632 var->red.length = var->blue.length = 5;
633 var->green.length = 6;
634 var->transp.length = 0;
637 var->red.length = var->green.length = var->blue.length = 8;
638 var->transp.length = 8;
641 DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
645 /* it is assumed BGRA order */
646 if (var->bits_per_pixel > 8 )
648 var->blue.offset = 0;
649 var->green.offset = var->blue.length;
650 var->red.offset = var->green.offset + var->green.length;
651 var->transp.offset = var->red.offset + var->red.length;
653 var->height = var->width = -1;
655 if (var->xres != var->xres_virtual) {
656 DPRINTK("virtual x resolution != physical x resolution not supported\n");
660 if (var->yres > var->yres_virtual) {
661 DPRINTK("virtual y resolution < physical y resolution not possible\n");
666 DPRINTK("xoffset not supported\n");
670 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
671 DPRINTK("interlace not supported\n");
675 var->xres = (var->xres + 31) & ~31; /* could sometimes be 8 */
676 lpitch = var->xres * ((var->bits_per_pixel + 7)>>3);
678 if (var->xres < 200 || var->xres > 2048) {
679 DPRINTK("width not supported: %u\n", var->xres);
683 if (var->yres < 200 || var->yres > 4095) {
684 DPRINTK("height not supported: %u\n", var->yres);
688 if (lpitch * var->yres_virtual > info->fix.smem_len) {
689 DPRINTK("no memory for screen (%ux%ux%u)\n",
690 var->xres, var->yres_virtual, var->bits_per_pixel);
694 if (PICOS2KHZ(var->pixclock) > PM3_MAX_PIXCLOCK) {
695 DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock));
699 var->accel_flags = 0; /* Can't mmap if this is on */
701 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
702 var->xres, var->yres, var->bits_per_pixel);
706 static int pm3fb_set_par(struct fb_info *info)
708 struct pm3_par *par = info->par;
709 const u32 xres = (info->var.xres + 31) & ~31;
710 const unsigned bpp = info->var.bits_per_pixel;
712 par->base = pm3fb_shift_bpp(bpp,(info->var.yoffset * xres)
713 + info->var.xoffset);
716 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
717 par->video |= PM3VideoControl_HSYNC_ACTIVE_HIGH;
719 par->video |= PM3VideoControl_HSYNC_ACTIVE_LOW;
721 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
722 par->video |= PM3VideoControl_VSYNC_ACTIVE_HIGH;
724 par->video |= PM3VideoControl_VSYNC_ACTIVE_LOW;
726 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
727 par->video |= PM3VideoControl_LINE_DOUBLE_ON;
729 par->video |= PM3VideoControl_LINE_DOUBLE_OFF;
731 if ((info->var.activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)
732 par->video |= PM3VideoControl_ENABLE;
734 par->video |= PM3VideoControl_DISABLE;
735 DPRINTK("PM3Video disabled\n");
739 par->video |= PM3VideoControl_PIXELSIZE_8BIT;
742 par->video |= PM3VideoControl_PIXELSIZE_16BIT;
745 par->video |= PM3VideoControl_PIXELSIZE_32BIT;
748 DPRINTK("Unsupported depth\n");
753 (bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
754 info->fix.line_length = ((info->var.xres_virtual + 7) & ~7)
757 /* pm3fb_clear_memory(info, 0);*/
758 pm3fb_clear_colormap(par, 0, 0, 0);
759 PM3_WRITE_DAC_REG(par, PM3RD_CursorMode,
760 PM3RD_CursorMode_CURSOR_DISABLE);
761 pm3fb_init_engine(info);
762 pm3fb_write_mode(info);
766 static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
767 unsigned blue, unsigned transp,
768 struct fb_info *info)
770 struct pm3_par *par = info->par;
772 if (regno >= 256) /* no. of hw registers */
775 /* grayscale works only partially under directcolor */
776 if (info->var.grayscale) {
777 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
778 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
782 * var->{color}.offset contains start of bitfield
783 * var->{color}.length contains length of bitfield
784 * {hardwarespecific} contains width of DAC
785 * pseudo_palette[X] is programmed to (X << red.offset) |
786 * (X << green.offset) |
788 * RAMDAC[X] is programmed to (red, green, blue)
789 * color depth = SUM(var->{color}.length)
792 * var->{color}.offset is 0
793 * var->{color}.length contains width of DAC or the number of unique
794 * colors available (color depth)
795 * pseudo_palette is not used
796 * RAMDAC[X] is programmed to (red, green, blue)
797 * color depth = var->{color}.length
801 * This is the point where the color is converted to something that
802 * is acceptable by the hardware.
804 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
805 red = CNVT_TOHW(red, info->var.red.length);
806 green = CNVT_TOHW(green, info->var.green.length);
807 blue = CNVT_TOHW(blue, info->var.blue.length);
808 transp = CNVT_TOHW(transp, info->var.transp.length);
811 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
812 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
818 v = (red << info->var.red.offset) |
819 (green << info->var.green.offset) |
820 (blue << info->var.blue.offset) |
821 (transp << info->var.transp.offset);
823 switch (info->var.bits_per_pixel) {
828 ((u32*)(info->pseudo_palette))[regno] = v;
833 else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
834 pm3fb_set_color(par, regno, red, green, blue);
839 static int pm3fb_pan_display(struct fb_var_screeninfo *var,
840 struct fb_info *info)
842 struct pm3_par *par = info->par;
843 const u32 xres = (var->xres + 31) & ~31;
845 par->base = pm3fb_shift_bpp(var->bits_per_pixel,
846 (var->yoffset * xres)
849 PM3_WRITE_REG(par, PM3ScreenBase, par->base);
853 static int pm3fb_blank(int blank_mode, struct fb_info *info)
855 struct pm3_par *par = info->par;
856 u32 video = par->video;
859 * Oxygen VX1 - it appears that setting PM3VideoControl and
860 * then PM3RD_SyncControl to the same SYNC settings undoes
861 * any net change - they seem to xor together. Only set the
862 * sync options in PM3RD_SyncControl. --rmk
864 video &= ~(PM3VideoControl_HSYNC_MASK |
865 PM3VideoControl_VSYNC_MASK);
866 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
867 PM3VideoControl_VSYNC_ACTIVE_HIGH;
869 switch (blank_mode) {
870 case FB_BLANK_UNBLANK:
871 video |= PM3VideoControl_ENABLE;
873 case FB_BLANK_NORMAL:
874 video &= ~(PM3VideoControl_ENABLE);
876 case FB_BLANK_HSYNC_SUSPEND:
877 video &= ~(PM3VideoControl_HSYNC_MASK |
878 PM3VideoControl_BLANK_ACTIVE_LOW);
880 case FB_BLANK_VSYNC_SUSPEND:
881 video &= ~(PM3VideoControl_VSYNC_MASK |
882 PM3VideoControl_BLANK_ACTIVE_LOW);
884 case FB_BLANK_POWERDOWN:
885 video &= ~(PM3VideoControl_HSYNC_MASK |
886 PM3VideoControl_VSYNC_MASK |
887 PM3VideoControl_BLANK_ACTIVE_LOW);
890 DPRINTK("Unsupported blanking %d\n", blank_mode);
895 PM3_WRITE_REG(par,PM3VideoControl, video);
900 * Frame buffer operations
903 static struct fb_ops pm3fb_ops = {
904 .owner = THIS_MODULE,
905 .fb_check_var = pm3fb_check_var,
906 .fb_set_par = pm3fb_set_par,
907 .fb_setcolreg = pm3fb_setcolreg,
908 .fb_pan_display = pm3fb_pan_display,
909 .fb_fillrect = pm3fb_fillrect,
910 .fb_copyarea = cfb_copyarea,
911 .fb_imageblit = cfb_imageblit,
912 .fb_blank = pm3fb_blank,
913 .fb_sync = pm3fb_sync,
916 /* ------------------------------------------------------------------------- */
922 /* mmio register are already mapped when this function is called */
923 /* the pm3fb_fix.smem_start is also set */
924 static unsigned long pm3fb_size_memory(struct pm3_par *par)
926 unsigned long memsize = 0, tempBypass, i, temp1, temp2;
927 unsigned char __iomem *screen_mem;
929 pm3fb_fix.smem_len = 64 * 1024l * 1024; /* request full aperture size */
930 /* Linear frame buffer - request region and map it. */
931 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
933 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
937 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
939 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
940 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
944 /* TODO: card-specific stuff, *before* accessing *any* FB memory */
945 /* For Appian Jeronimo 2000 board second head */
947 tempBypass = PM3_READ_REG(par, PM3MemBypassWriteMask);
949 DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass);
952 PM3_WRITE_REG(par, PM3MemBypassWriteMask, 0xFFFFFFFF);
954 /* pm3 split up memory, replicates, and do a lot of nasty stuff IMHO ;-) */
955 for (i = 0; i < 32; i++) {
956 fb_writel(i * 0x00345678,
957 (screen_mem + (i * 1048576)));
959 temp1 = fb_readl((screen_mem + (i * 1048576)));
961 /* Let's check for wrapover, write will fail at 16MB boundary */
962 if (temp1 == (i * 0x00345678))
968 DPRINTK("First detect pass already got %ld MB\n", memsize + 1);
970 if (memsize + 1 == i) {
971 for (i = 0; i < 32; i++) {
972 /* Clear first 32MB ; 0 is 0, no need to byteswap */
973 writel(0x0000000, (screen_mem + (i * 1048576)));
977 for (i = 32; i < 64; i++) {
978 fb_writel(i * 0x00345678,
979 (screen_mem + (i * 1048576)));
982 fb_readl((screen_mem + (i * 1048576)));
984 fb_readl((screen_mem + ((i - 32) * 1048576)));
985 /* different value, different RAM... */
986 if ((temp1 == (i * 0x00345678)) && (temp2 == 0))
992 DPRINTK("Second detect pass got %ld MB\n", memsize + 1);
995 PM3_WRITE_REG(par, PM3MemBypassWriteMask, tempBypass);
998 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
999 memsize = 1048576 * (memsize + 1);
1001 DPRINTK("Returning 0x%08lx bytes\n", memsize);
1006 static int __devinit pm3fb_probe(struct pci_dev *dev,
1007 const struct pci_device_id *ent)
1009 struct fb_info *info;
1010 struct pm3_par *par;
1011 struct device* device = &dev->dev; /* for pci drivers */
1012 int err, retval = -ENXIO;
1014 err = pci_enable_device(dev);
1016 printk(KERN_WARNING "pm3fb: Can't enable PCI dev: %d\n", err);
1020 * Dynamically allocate info and par
1022 info = framebuffer_alloc(sizeof(struct pm3_par), device);
1029 * Here we set the screen_base to the virtual memory address
1030 * for the framebuffer.
1032 pm3fb_fix.mmio_start = pci_resource_start(dev, 0);
1033 pm3fb_fix.mmio_len = PM3_REGS_SIZE;
1035 /* Registers - request region and map it. */
1036 if (!request_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len,
1038 printk(KERN_WARNING "pm3fb: Can't reserve regbase.\n");
1039 goto err_exit_neither;
1042 ioremap_nocache(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
1044 printk(KERN_WARNING "pm3fb: Can't remap %s register area.\n",
1046 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
1047 goto err_exit_neither;
1050 #if defined(__BIG_ENDIAN)
1051 pm3fb_fix.mmio_start += PM3_REGS_SIZE;
1052 DPRINTK("Adjusting register base for big-endian.\n");
1054 /* Linear frame buffer - request region and map it. */
1055 pm3fb_fix.smem_start = pci_resource_start(dev, 1);
1056 pm3fb_fix.smem_len = pm3fb_size_memory(par);
1057 if (!pm3fb_fix.smem_len)
1059 printk(KERN_WARNING "pm3fb: Can't find memory on board.\n");
1062 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
1064 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
1068 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1069 if (!info->screen_base) {
1070 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
1071 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1074 info->screen_size = pm3fb_fix.smem_len;
1076 info->fbops = &pm3fb_ops;
1078 par->video = PM3_READ_REG(par, PM3VideoControl);
1080 info->fix = pm3fb_fix;
1081 info->pseudo_palette = par->palette;
1082 info->flags = FBINFO_DEFAULT |
1083 FBINFO_HWACCEL_FILLRECT;/* | FBINFO_HWACCEL_YPAN;*/
1086 * This should give a reasonable default video mode. The following is
1087 * done when we can set a video mode.
1090 mode_option = "640x480@60";
1092 retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
1094 if (!retval || retval == 4) {
1099 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
1105 * For drivers that can...
1107 pm3fb_check_var(&info->var, info);
1109 if (register_framebuffer(info) < 0) {
1113 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
1115 pci_set_drvdata(dev, info);
1119 fb_dealloc_cmap(&info->cmap);
1121 iounmap(info->screen_base);
1122 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
1124 iounmap(par->v_regs);
1125 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
1127 framebuffer_release(info);
1134 static void __devexit pm3fb_remove(struct pci_dev *dev)
1136 struct fb_info *info = pci_get_drvdata(dev);
1139 struct fb_fix_screeninfo *fix = &info->fix;
1140 struct pm3_par *par = info->par;
1142 unregister_framebuffer(info);
1143 fb_dealloc_cmap(&info->cmap);
1145 iounmap(info->screen_base);
1146 release_mem_region(fix->smem_start, fix->smem_len);
1147 iounmap(par->v_regs);
1148 release_mem_region(fix->mmio_start, fix->mmio_len);
1150 pci_set_drvdata(dev, NULL);
1151 framebuffer_release(info);
1155 static struct pci_device_id pm3fb_id_table[] = {
1156 { PCI_VENDOR_ID_3DLABS, 0x0a,
1157 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1161 /* For PCI drivers */
1162 static struct pci_driver pm3fb_driver = {
1164 .id_table = pm3fb_id_table,
1165 .probe = pm3fb_probe,
1166 .remove = __devexit_p(pm3fb_remove),
1169 MODULE_DEVICE_TABLE(pci, pm3fb_id_table);
1171 static int __init pm3fb_init(void)
1174 if (fb_get_options("pm3fb", NULL))
1177 return pci_register_driver(&pm3fb_driver);
1180 static void __exit pm3fb_exit(void)
1182 pci_unregister_driver(&pm3fb_driver);
1185 module_init(pm3fb_init);
1186 module_exit(pm3fb_exit);
1188 MODULE_LICENSE("GPL");