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/aperture.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/errno.h>
29 #include <linux/string.h>
31 #include <linux/slab.h>
32 #include <linux/delay.h>
34 #include <linux/init.h>
35 #include <linux/pci.h>
37 #include <video/pm3fb.h>
39 #if !defined(CONFIG_PCI)
40 #error "Only generic PCI cards supported."
43 #undef PM3FB_MASTER_DEBUG
44 #ifdef PM3FB_MASTER_DEBUG
45 #define DPRINTK(a, b...) \
46 printk(KERN_DEBUG "pm3fb: %s: " a, __func__ , ## b)
48 #define DPRINTK(a, b...) no_printk(a, ##b)
51 #define PM3_PIXMAP_SIZE (2048 * 4)
56 static int hwcursor
= 1;
57 static char *mode_option
;
62 * This structure defines the hardware state of the graphics card. Normally
63 * you place this in a header file in linux/include/video. This file usually
64 * also includes register information. That allows other driver subsystems
65 * and userland applications the ability to use the same header file to
66 * avoid duplicate work and easy porting of software.
69 unsigned char __iomem
*v_regs
;/* virtual address of p_regs */
70 u32 video
; /* video flags before blanking */
71 u32 base
; /* screen base in 128 bits unit */
77 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
78 * if we don't use modedb. If we do use modedb see pm3fb_init how to use it
79 * to get a fb_var_screeninfo. Otherwise define a default var as well.
81 static struct fb_fix_screeninfo pm3fb_fix
= {
83 .type
= FB_TYPE_PACKED_PIXELS
,
84 .visual
= FB_VISUAL_PSEUDOCOLOR
,
88 .accel
= FB_ACCEL_3DLABS_PERMEDIA3
,
95 static inline u32
PM3_READ_REG(struct pm3_par
*par
, s32 off
)
97 return fb_readl(par
->v_regs
+ off
);
100 static inline void PM3_WRITE_REG(struct pm3_par
*par
, s32 off
, u32 v
)
102 fb_writel(v
, par
->v_regs
+ off
);
105 static inline void PM3_WAIT(struct pm3_par
*par
, u32 n
)
107 while (PM3_READ_REG(par
, PM3InFIFOSpace
) < n
)
111 static inline void PM3_WRITE_DAC_REG(struct pm3_par
*par
, unsigned r
, u8 v
)
114 PM3_WRITE_REG(par
, PM3RD_IndexHigh
, (r
>> 8) & 0xff);
115 PM3_WRITE_REG(par
, PM3RD_IndexLow
, r
& 0xff);
117 PM3_WRITE_REG(par
, PM3RD_IndexedData
, v
);
121 static inline void pm3fb_set_color(struct pm3_par
*par
, unsigned char regno
,
122 unsigned char r
, unsigned char g
, unsigned char b
)
125 PM3_WRITE_REG(par
, PM3RD_PaletteWriteAddress
, regno
);
127 PM3_WRITE_REG(par
, PM3RD_PaletteData
, r
);
129 PM3_WRITE_REG(par
, PM3RD_PaletteData
, g
);
131 PM3_WRITE_REG(par
, PM3RD_PaletteData
, b
);
135 static void pm3fb_clear_colormap(struct pm3_par
*par
,
136 unsigned char r
, unsigned char g
, unsigned char b
)
140 for (i
= 0; i
< 256 ; i
++)
141 pm3fb_set_color(par
, i
, r
, g
, b
);
145 /* Calculating various clock parameters */
146 static void pm3fb_calculate_clock(unsigned long reqclock
,
147 unsigned char *prescale
,
148 unsigned char *feedback
,
149 unsigned char *postscale
)
156 for (f
= 1; f
< 256; f
++) {
157 for (pre
= 1; pre
< 256; pre
++) {
158 for (post
= 0; post
< 5; post
++) {
159 freq
= ((2*PM3_REF_CLOCK
* f
) >> post
) / pre
;
160 currerr
= (reqclock
> freq
)
163 if (currerr
< freqerr
) {
174 static inline int pm3fb_depth(const struct fb_var_screeninfo
*var
)
176 if (var
->bits_per_pixel
== 16)
177 return var
->red
.length
+ var
->green
.length
180 return var
->bits_per_pixel
;
183 static inline int pm3fb_shift_bpp(unsigned bpp
, int v
)
193 DPRINTK("Unsupported depth %u\n", bpp
);
198 static int pm3fb_sync(struct fb_info
*info
)
200 struct pm3_par
*par
= info
->par
;
203 PM3_WRITE_REG(par
, PM3FilterMode
, PM3FilterModeSync
);
204 PM3_WRITE_REG(par
, PM3Sync
, 0);
207 while ((PM3_READ_REG(par
, PM3OutFIFOWords
)) == 0)
209 } while ((PM3_READ_REG(par
, PM3OutputFifo
)) != PM3Sync_Tag
);
214 static void pm3fb_init_engine(struct fb_info
*info
)
216 struct pm3_par
*par
= info
->par
;
217 const u32 width
= (info
->var
.xres_virtual
+ 7) & ~7;
220 PM3_WRITE_REG(par
, PM3FilterMode
, PM3FilterModeSync
);
221 PM3_WRITE_REG(par
, PM3StatisticMode
, 0x0);
222 PM3_WRITE_REG(par
, PM3DeltaMode
, 0x0);
223 PM3_WRITE_REG(par
, PM3RasterizerMode
, 0x0);
224 PM3_WRITE_REG(par
, PM3ScissorMode
, 0x0);
225 PM3_WRITE_REG(par
, PM3LineStippleMode
, 0x0);
226 PM3_WRITE_REG(par
, PM3AreaStippleMode
, 0x0);
227 PM3_WRITE_REG(par
, PM3GIDMode
, 0x0);
228 PM3_WRITE_REG(par
, PM3DepthMode
, 0x0);
229 PM3_WRITE_REG(par
, PM3StencilMode
, 0x0);
230 PM3_WRITE_REG(par
, PM3StencilData
, 0x0);
231 PM3_WRITE_REG(par
, PM3ColorDDAMode
, 0x0);
232 PM3_WRITE_REG(par
, PM3TextureCoordMode
, 0x0);
233 PM3_WRITE_REG(par
, PM3TextureIndexMode0
, 0x0);
234 PM3_WRITE_REG(par
, PM3TextureIndexMode1
, 0x0);
235 PM3_WRITE_REG(par
, PM3TextureReadMode
, 0x0);
236 PM3_WRITE_REG(par
, PM3LUTMode
, 0x0);
237 PM3_WRITE_REG(par
, PM3TextureFilterMode
, 0x0);
238 PM3_WRITE_REG(par
, PM3TextureCompositeMode
, 0x0);
239 PM3_WRITE_REG(par
, PM3TextureApplicationMode
, 0x0);
240 PM3_WRITE_REG(par
, PM3TextureCompositeColorMode1
, 0x0);
241 PM3_WRITE_REG(par
, PM3TextureCompositeAlphaMode1
, 0x0);
242 PM3_WRITE_REG(par
, PM3TextureCompositeColorMode0
, 0x0);
243 PM3_WRITE_REG(par
, PM3TextureCompositeAlphaMode0
, 0x0);
244 PM3_WRITE_REG(par
, PM3FogMode
, 0x0);
245 PM3_WRITE_REG(par
, PM3ChromaTestMode
, 0x0);
246 PM3_WRITE_REG(par
, PM3AlphaTestMode
, 0x0);
247 PM3_WRITE_REG(par
, PM3AntialiasMode
, 0x0);
248 PM3_WRITE_REG(par
, PM3YUVMode
, 0x0);
249 PM3_WRITE_REG(par
, PM3AlphaBlendColorMode
, 0x0);
250 PM3_WRITE_REG(par
, PM3AlphaBlendAlphaMode
, 0x0);
251 PM3_WRITE_REG(par
, PM3DitherMode
, 0x0);
252 PM3_WRITE_REG(par
, PM3LogicalOpMode
, 0x0);
253 PM3_WRITE_REG(par
, PM3RouterMode
, 0x0);
254 PM3_WRITE_REG(par
, PM3Window
, 0x0);
256 PM3_WRITE_REG(par
, PM3Config2D
, 0x0);
258 PM3_WRITE_REG(par
, PM3SpanColorMask
, 0xffffffff);
260 PM3_WRITE_REG(par
, PM3XBias
, 0x0);
261 PM3_WRITE_REG(par
, PM3YBias
, 0x0);
262 PM3_WRITE_REG(par
, PM3DeltaControl
, 0x0);
264 PM3_WRITE_REG(par
, PM3BitMaskPattern
, 0xffffffff);
266 PM3_WRITE_REG(par
, PM3FBDestReadEnables
,
267 PM3FBDestReadEnables_E(0xff) |
268 PM3FBDestReadEnables_R(0xff) |
269 PM3FBDestReadEnables_ReferenceAlpha(0xff));
270 PM3_WRITE_REG(par
, PM3FBDestReadBufferAddr0
, 0x0);
271 PM3_WRITE_REG(par
, PM3FBDestReadBufferOffset0
, 0x0);
272 PM3_WRITE_REG(par
, PM3FBDestReadBufferWidth0
,
273 PM3FBDestReadBufferWidth_Width(width
));
275 PM3_WRITE_REG(par
, PM3FBDestReadMode
,
276 PM3FBDestReadMode_ReadEnable
|
277 PM3FBDestReadMode_Enable0
);
278 PM3_WRITE_REG(par
, PM3FBSourceReadBufferAddr
, 0x0);
279 PM3_WRITE_REG(par
, PM3FBSourceReadBufferOffset
, 0x0);
280 PM3_WRITE_REG(par
, PM3FBSourceReadBufferWidth
,
281 PM3FBSourceReadBufferWidth_Width(width
));
282 PM3_WRITE_REG(par
, PM3FBSourceReadMode
,
283 PM3FBSourceReadMode_Blocking
|
284 PM3FBSourceReadMode_ReadEnable
);
288 /* invert bits in bitmask */
289 unsigned long rm
= 1 | (3 << 7);
290 switch (info
->var
.bits_per_pixel
) {
292 PM3_WRITE_REG(par
, PM3PixelSize
,
293 PM3PixelSize_GLOBAL_8BIT
);
299 PM3_WRITE_REG(par
, PM3PixelSize
,
300 PM3PixelSize_GLOBAL_16BIT
);
306 PM3_WRITE_REG(par
, PM3PixelSize
,
307 PM3PixelSize_GLOBAL_32BIT
);
310 DPRINTK("Unsupported depth %d\n",
311 info
->var
.bits_per_pixel
);
314 PM3_WRITE_REG(par
, PM3RasterizerMode
, rm
);
318 PM3_WRITE_REG(par
, PM3FBSoftwareWriteMask
, 0xffffffff);
319 PM3_WRITE_REG(par
, PM3FBHardwareWriteMask
, 0xffffffff);
320 PM3_WRITE_REG(par
, PM3FBWriteMode
,
321 PM3FBWriteMode_WriteEnable
|
322 PM3FBWriteMode_OpaqueSpan
|
323 PM3FBWriteMode_Enable0
);
324 PM3_WRITE_REG(par
, PM3FBWriteBufferAddr0
, 0x0);
325 PM3_WRITE_REG(par
, PM3FBWriteBufferOffset0
, 0x0);
326 PM3_WRITE_REG(par
, PM3FBWriteBufferWidth0
,
327 PM3FBWriteBufferWidth_Width(width
));
329 PM3_WRITE_REG(par
, PM3SizeOfFramebuffer
, 0x0);
331 /* size in lines of FB */
332 unsigned long sofb
= info
->screen_size
/
333 info
->fix
.line_length
;
335 PM3_WRITE_REG(par
, PM3SizeOfFramebuffer
, 4095);
337 PM3_WRITE_REG(par
, PM3SizeOfFramebuffer
, sofb
);
339 switch (info
->var
.bits_per_pixel
) {
341 PM3_WRITE_REG(par
, PM3DitherMode
,
342 (1 << 10) | (2 << 3));
345 PM3_WRITE_REG(par
, PM3DitherMode
,
346 (1 << 10) | (1 << 3));
349 PM3_WRITE_REG(par
, PM3DitherMode
,
350 (1 << 10) | (0 << 3));
353 DPRINTK("Unsupported depth %d\n",
354 info
->var
.bits_per_pixel
);
359 PM3_WRITE_REG(par
, PM3dXDom
, 0x0);
360 PM3_WRITE_REG(par
, PM3dXSub
, 0x0);
361 PM3_WRITE_REG(par
, PM3dY
, 1 << 16);
362 PM3_WRITE_REG(par
, PM3StartXDom
, 0x0);
363 PM3_WRITE_REG(par
, PM3StartXSub
, 0x0);
364 PM3_WRITE_REG(par
, PM3StartY
, 0x0);
365 PM3_WRITE_REG(par
, PM3Count
, 0x0);
367 /* Disable LocalBuffer. better safe than sorry */
368 PM3_WRITE_REG(par
, PM3LBDestReadMode
, 0x0);
369 PM3_WRITE_REG(par
, PM3LBDestReadEnables
, 0x0);
370 PM3_WRITE_REG(par
, PM3LBSourceReadMode
, 0x0);
371 PM3_WRITE_REG(par
, PM3LBWriteMode
, 0x0);
376 static void pm3fb_fillrect(struct fb_info
*info
,
377 const struct fb_fillrect
*region
)
379 struct pm3_par
*par
= info
->par
;
380 struct fb_fillrect modded
;
383 u32 color
= (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) ?
384 ((u32
*)info
->pseudo_palette
)[region
->color
] : region
->color
;
386 if (info
->state
!= FBINFO_STATE_RUNNING
)
388 if (info
->flags
& FBINFO_HWACCEL_DISABLED
) {
389 cfb_fillrect(info
, region
);
392 if (region
->rop
== ROP_COPY
)
393 rop
= PM3Config2D_ForegroundROP(0x3); /* GXcopy */
395 rop
= PM3Config2D_ForegroundROP(0x6) | /* GXxor */
396 PM3Config2D_FBDestReadEnable
;
398 vxres
= info
->var
.xres_virtual
;
399 vyres
= info
->var
.yres_virtual
;
401 memcpy(&modded
, region
, sizeof(struct fb_fillrect
));
403 if (!modded
.width
|| !modded
.height
||
404 modded
.dx
>= vxres
|| modded
.dy
>= vyres
)
407 if (modded
.dx
+ modded
.width
> vxres
)
408 modded
.width
= vxres
- modded
.dx
;
409 if (modded
.dy
+ modded
.height
> vyres
)
410 modded
.height
= vyres
- modded
.dy
;
412 if (info
->var
.bits_per_pixel
== 8)
414 if (info
->var
.bits_per_pixel
<= 16)
415 color
|= color
<< 16;
418 /* ROP Ox3 is GXcopy */
419 PM3_WRITE_REG(par
, PM3Config2D
,
420 PM3Config2D_UseConstantSource
|
421 PM3Config2D_ForegroundROPEnable
|
423 PM3Config2D_FBWriteEnable
);
425 PM3_WRITE_REG(par
, PM3ForegroundColor
, color
);
427 PM3_WRITE_REG(par
, PM3RectanglePosition
,
428 PM3RectanglePosition_XOffset(modded
.dx
) |
429 PM3RectanglePosition_YOffset(modded
.dy
));
431 PM3_WRITE_REG(par
, PM3Render2D
,
432 PM3Render2D_XPositive
|
433 PM3Render2D_YPositive
|
434 PM3Render2D_Operation_Normal
|
435 PM3Render2D_SpanOperation
|
436 PM3Render2D_Width(modded
.width
) |
437 PM3Render2D_Height(modded
.height
));
440 static void pm3fb_copyarea(struct fb_info
*info
,
441 const struct fb_copyarea
*area
)
443 struct pm3_par
*par
= info
->par
;
444 struct fb_copyarea modded
;
446 int x_align
, o_x
, o_y
;
448 if (info
->state
!= FBINFO_STATE_RUNNING
)
450 if (info
->flags
& FBINFO_HWACCEL_DISABLED
) {
451 cfb_copyarea(info
, area
);
455 memcpy(&modded
, area
, sizeof(struct fb_copyarea
));
457 vxres
= info
->var
.xres_virtual
;
458 vyres
= info
->var
.yres_virtual
;
460 if (!modded
.width
|| !modded
.height
||
461 modded
.sx
>= vxres
|| modded
.sy
>= vyres
||
462 modded
.dx
>= vxres
|| modded
.dy
>= vyres
)
465 if (modded
.sx
+ modded
.width
> vxres
)
466 modded
.width
= vxres
- modded
.sx
;
467 if (modded
.dx
+ modded
.width
> vxres
)
468 modded
.width
= vxres
- modded
.dx
;
469 if (modded
.sy
+ modded
.height
> vyres
)
470 modded
.height
= vyres
- modded
.sy
;
471 if (modded
.dy
+ modded
.height
> vyres
)
472 modded
.height
= vyres
- modded
.dy
;
474 o_x
= modded
.sx
- modded
.dx
; /*(sx > dx ) ? (sx - dx) : (dx - sx); */
475 o_y
= modded
.sy
- modded
.dy
; /*(sy > dy ) ? (sy - dy) : (dy - sy); */
477 x_align
= (modded
.sx
& 0x1f);
481 PM3_WRITE_REG(par
, PM3Config2D
,
482 PM3Config2D_UserScissorEnable
|
483 PM3Config2D_ForegroundROPEnable
|
484 PM3Config2D_Blocking
|
485 PM3Config2D_ForegroundROP(0x3) | /* Ox3 is GXcopy */
486 PM3Config2D_FBWriteEnable
);
488 PM3_WRITE_REG(par
, PM3ScissorMinXY
,
489 ((modded
.dy
& 0x0fff) << 16) | (modded
.dx
& 0x0fff));
490 PM3_WRITE_REG(par
, PM3ScissorMaxXY
,
491 (((modded
.dy
+ modded
.height
) & 0x0fff) << 16) |
492 ((modded
.dx
+ modded
.width
) & 0x0fff));
494 PM3_WRITE_REG(par
, PM3FBSourceReadBufferOffset
,
495 PM3FBSourceReadBufferOffset_XOffset(o_x
) |
496 PM3FBSourceReadBufferOffset_YOffset(o_y
));
498 PM3_WRITE_REG(par
, PM3RectanglePosition
,
499 PM3RectanglePosition_XOffset(modded
.dx
- x_align
) |
500 PM3RectanglePosition_YOffset(modded
.dy
));
502 PM3_WRITE_REG(par
, PM3Render2D
,
503 ((modded
.sx
> modded
.dx
) ? PM3Render2D_XPositive
: 0) |
504 ((modded
.sy
> modded
.dy
) ? PM3Render2D_YPositive
: 0) |
505 PM3Render2D_Operation_Normal
|
506 PM3Render2D_SpanOperation
|
507 PM3Render2D_FBSourceReadEnable
|
508 PM3Render2D_Width(modded
.width
+ x_align
) |
509 PM3Render2D_Height(modded
.height
));
512 static void pm3fb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
514 struct pm3_par
*par
= info
->par
;
515 u32 height
= image
->height
;
517 const u32
*src
= (const u32
*)image
->data
;
519 if (info
->state
!= FBINFO_STATE_RUNNING
)
521 if (info
->flags
& FBINFO_HWACCEL_DISABLED
) {
522 cfb_imageblit(info
, image
);
525 switch (info
->fix
.visual
) {
526 case FB_VISUAL_PSEUDOCOLOR
:
527 fgx
= image
->fg_color
;
528 bgx
= image
->bg_color
;
530 case FB_VISUAL_TRUECOLOR
:
532 fgx
= par
->palette
[image
->fg_color
];
533 bgx
= par
->palette
[image
->bg_color
];
536 if (image
->depth
!= 1) {
537 cfb_imageblit(info
, image
);
541 if (info
->var
.bits_per_pixel
== 8) {
545 if (info
->var
.bits_per_pixel
<= 16) {
552 PM3_WRITE_REG(par
, PM3ForegroundColor
, fgx
);
553 PM3_WRITE_REG(par
, PM3BackgroundColor
, bgx
);
555 /* ROP Ox3 is GXcopy */
556 PM3_WRITE_REG(par
, PM3Config2D
,
557 PM3Config2D_UserScissorEnable
|
558 PM3Config2D_UseConstantSource
|
559 PM3Config2D_ForegroundROPEnable
|
560 PM3Config2D_ForegroundROP(0x3) |
561 PM3Config2D_OpaqueSpan
|
562 PM3Config2D_FBWriteEnable
);
563 PM3_WRITE_REG(par
, PM3ScissorMinXY
,
564 ((image
->dy
& 0x0fff) << 16) | (image
->dx
& 0x0fff));
565 PM3_WRITE_REG(par
, PM3ScissorMaxXY
,
566 (((image
->dy
+ image
->height
) & 0x0fff) << 16) |
567 ((image
->dx
+ image
->width
) & 0x0fff));
568 PM3_WRITE_REG(par
, PM3RectanglePosition
,
569 PM3RectanglePosition_XOffset(image
->dx
) |
570 PM3RectanglePosition_YOffset(image
->dy
));
571 PM3_WRITE_REG(par
, PM3Render2D
,
572 PM3Render2D_XPositive
|
573 PM3Render2D_YPositive
|
574 PM3Render2D_Operation_SyncOnBitMask
|
575 PM3Render2D_SpanOperation
|
576 PM3Render2D_Width(image
->width
) |
577 PM3Render2D_Height(image
->height
));
581 int width
= ((image
->width
+ 7) >> 3)
582 + info
->pixmap
.scan_align
- 1;
585 while (width
>= PM3_FIFO_SIZE
) {
586 int i
= PM3_FIFO_SIZE
- 1;
588 PM3_WAIT(par
, PM3_FIFO_SIZE
);
590 PM3_WRITE_REG(par
, PM3BitMaskPattern
, *src
);
593 width
-= PM3_FIFO_SIZE
- 1;
596 PM3_WAIT(par
, width
+ 1);
598 PM3_WRITE_REG(par
, PM3BitMaskPattern
, *src
);
603 /* end of acceleration functions */
606 * Hardware Cursor support.
608 static const u8 cursor_bits_lookup
[16] = {
609 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,
610 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55
613 static int pm3fb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
615 struct pm3_par
*par
= info
->par
;
619 return -EINVAL
; /* just to force soft_cursor() call */
621 /* Too large of a cursor or wrong bpp :-( */
622 if (cursor
->image
.width
> 64 ||
623 cursor
->image
.height
> 64 ||
624 cursor
->image
.depth
> 1)
627 mode
= PM3RD_CursorMode_TYPE_X
;
629 mode
|= PM3RD_CursorMode_CURSOR_ENABLE
;
631 PM3_WRITE_DAC_REG(par
, PM3RD_CursorMode
, mode
);
634 * If the cursor is not be changed this means either we want the
635 * current cursor state (if enable is set) or we want to query what
636 * we can do with the cursor (if enable is not set)
641 if (cursor
->set
& FB_CUR_SETPOS
) {
642 int x
= cursor
->image
.dx
- info
->var
.xoffset
;
643 int y
= cursor
->image
.dy
- info
->var
.yoffset
;
645 PM3_WRITE_DAC_REG(par
, PM3RD_CursorXLow
, x
& 0xff);
646 PM3_WRITE_DAC_REG(par
, PM3RD_CursorXHigh
, (x
>> 8) & 0xf);
647 PM3_WRITE_DAC_REG(par
, PM3RD_CursorYLow
, y
& 0xff);
648 PM3_WRITE_DAC_REG(par
, PM3RD_CursorYHigh
, (y
>> 8) & 0xf);
651 if (cursor
->set
& FB_CUR_SETHOT
) {
652 PM3_WRITE_DAC_REG(par
, PM3RD_CursorHotSpotX
,
653 cursor
->hot
.x
& 0x3f);
654 PM3_WRITE_DAC_REG(par
, PM3RD_CursorHotSpotY
,
655 cursor
->hot
.y
& 0x3f);
658 if (cursor
->set
& FB_CUR_SETCMAP
) {
659 u32 fg_idx
= cursor
->image
.fg_color
;
660 u32 bg_idx
= cursor
->image
.bg_color
;
661 struct fb_cmap cmap
= info
->cmap
;
663 /* the X11 driver says one should use these color registers */
664 PM3_WRITE_DAC_REG(par
, PM3RD_CursorPalette(39),
665 cmap
.red
[fg_idx
] >> 8 );
666 PM3_WRITE_DAC_REG(par
, PM3RD_CursorPalette(40),
667 cmap
.green
[fg_idx
] >> 8 );
668 PM3_WRITE_DAC_REG(par
, PM3RD_CursorPalette(41),
669 cmap
.blue
[fg_idx
] >> 8 );
671 PM3_WRITE_DAC_REG(par
, PM3RD_CursorPalette(42),
672 cmap
.red
[bg_idx
] >> 8 );
673 PM3_WRITE_DAC_REG(par
, PM3RD_CursorPalette(43),
674 cmap
.green
[bg_idx
] >> 8 );
675 PM3_WRITE_DAC_REG(par
, PM3RD_CursorPalette(44),
676 cmap
.blue
[bg_idx
] >> 8 );
679 if (cursor
->set
& (FB_CUR_SETSHAPE
| FB_CUR_SETIMAGE
)) {
680 u8
*bitmap
= (u8
*)cursor
->image
.data
;
681 u8
*mask
= (u8
*)cursor
->mask
;
683 int pos
= PM3RD_CursorPattern(0);
685 for (i
= 0; i
< cursor
->image
.height
; i
++) {
686 int j
= (cursor
->image
.width
+ 7) >> 3;
690 u8 data
= *bitmap
^ *mask
;
692 if (cursor
->rop
== ROP_COPY
)
693 data
= *mask
& *bitmap
;
694 /* Upper 4 bits of bitmap data */
695 PM3_WRITE_DAC_REG(par
, pos
++,
696 cursor_bits_lookup
[data
>> 4] |
697 (cursor_bits_lookup
[*mask
>> 4] << 1));
698 /* Lower 4 bits of bitmap */
699 PM3_WRITE_DAC_REG(par
, pos
++,
700 cursor_bits_lookup
[data
& 0xf] |
701 (cursor_bits_lookup
[*mask
& 0xf] << 1));
706 PM3_WRITE_DAC_REG(par
, pos
++, 0);
707 PM3_WRITE_DAC_REG(par
, pos
++, 0);
710 while (pos
< PM3RD_CursorPattern(1024))
711 PM3_WRITE_DAC_REG(par
, pos
++, 0);
716 /* write the mode to registers */
717 static void pm3fb_write_mode(struct fb_info
*info
)
719 struct pm3_par
*par
= info
->par
;
720 char tempsync
= 0x00;
721 char tempmisc
= 0x00;
722 const u32 hsstart
= info
->var
.right_margin
;
723 const u32 hsend
= hsstart
+ info
->var
.hsync_len
;
724 const u32 hbend
= hsend
+ info
->var
.left_margin
;
725 const u32 xres
= (info
->var
.xres
+ 31) & ~31;
726 const u32 htotal
= xres
+ hbend
;
727 const u32 vsstart
= info
->var
.lower_margin
;
728 const u32 vsend
= vsstart
+ info
->var
.vsync_len
;
729 const u32 vbend
= vsend
+ info
->var
.upper_margin
;
730 const u32 vtotal
= info
->var
.yres
+ vbend
;
731 const u32 width
= (info
->var
.xres_virtual
+ 7) & ~7;
732 const unsigned bpp
= info
->var
.bits_per_pixel
;
735 PM3_WRITE_REG(par
, PM3MemBypassWriteMask
, 0xffffffff);
736 PM3_WRITE_REG(par
, PM3Aperture0
, 0x00000000);
737 PM3_WRITE_REG(par
, PM3Aperture1
, 0x00000000);
738 PM3_WRITE_REG(par
, PM3FIFODis
, 0x00000007);
740 PM3_WRITE_REG(par
, PM3HTotal
,
741 pm3fb_shift_bpp(bpp
, htotal
- 1));
742 PM3_WRITE_REG(par
, PM3HsEnd
,
743 pm3fb_shift_bpp(bpp
, hsend
));
744 PM3_WRITE_REG(par
, PM3HsStart
,
745 pm3fb_shift_bpp(bpp
, hsstart
));
746 PM3_WRITE_REG(par
, PM3HbEnd
,
747 pm3fb_shift_bpp(bpp
, hbend
));
748 PM3_WRITE_REG(par
, PM3HgEnd
,
749 pm3fb_shift_bpp(bpp
, hbend
));
750 PM3_WRITE_REG(par
, PM3ScreenStride
,
751 pm3fb_shift_bpp(bpp
, width
));
752 PM3_WRITE_REG(par
, PM3VTotal
, vtotal
- 1);
753 PM3_WRITE_REG(par
, PM3VsEnd
, vsend
- 1);
754 PM3_WRITE_REG(par
, PM3VsStart
, vsstart
- 1);
755 PM3_WRITE_REG(par
, PM3VbEnd
, vbend
);
759 PM3_WRITE_REG(par
, PM3ByAperture1Mode
,
760 PM3ByApertureMode_PIXELSIZE_8BIT
);
761 PM3_WRITE_REG(par
, PM3ByAperture2Mode
,
762 PM3ByApertureMode_PIXELSIZE_8BIT
);
767 PM3_WRITE_REG(par
, PM3ByAperture1Mode
,
768 PM3ByApertureMode_PIXELSIZE_16BIT
);
769 PM3_WRITE_REG(par
, PM3ByAperture2Mode
,
770 PM3ByApertureMode_PIXELSIZE_16BIT
);
772 PM3_WRITE_REG(par
, PM3ByAperture1Mode
,
773 PM3ByApertureMode_PIXELSIZE_16BIT
|
774 PM3ByApertureMode_BYTESWAP_BADC
);
775 PM3_WRITE_REG(par
, PM3ByAperture2Mode
,
776 PM3ByApertureMode_PIXELSIZE_16BIT
|
777 PM3ByApertureMode_BYTESWAP_BADC
);
778 #endif /* ! __BIG_ENDIAN */
783 PM3_WRITE_REG(par
, PM3ByAperture1Mode
,
784 PM3ByApertureMode_PIXELSIZE_32BIT
);
785 PM3_WRITE_REG(par
, PM3ByAperture2Mode
,
786 PM3ByApertureMode_PIXELSIZE_32BIT
);
788 PM3_WRITE_REG(par
, PM3ByAperture1Mode
,
789 PM3ByApertureMode_PIXELSIZE_32BIT
|
790 PM3ByApertureMode_BYTESWAP_DCBA
);
791 PM3_WRITE_REG(par
, PM3ByAperture2Mode
,
792 PM3ByApertureMode_PIXELSIZE_32BIT
|
793 PM3ByApertureMode_BYTESWAP_DCBA
);
794 #endif /* ! __BIG_ENDIAN */
798 DPRINTK("Unsupported depth %d\n", bpp
);
803 * Oxygen VX1 - it appears that setting PM3VideoControl and
804 * then PM3RD_SyncControl to the same SYNC settings undoes
805 * any net change - they seem to xor together. Only set the
806 * sync options in PM3RD_SyncControl. --rmk
809 unsigned int video
= par
->video
;
811 video
&= ~(PM3VideoControl_HSYNC_MASK
|
812 PM3VideoControl_VSYNC_MASK
);
813 video
|= PM3VideoControl_HSYNC_ACTIVE_HIGH
|
814 PM3VideoControl_VSYNC_ACTIVE_HIGH
;
815 PM3_WRITE_REG(par
, PM3VideoControl
, video
);
817 PM3_WRITE_REG(par
, PM3VClkCtl
,
818 (PM3_READ_REG(par
, PM3VClkCtl
) & 0xFFFFFFFC));
819 PM3_WRITE_REG(par
, PM3ScreenBase
, par
->base
);
820 PM3_WRITE_REG(par
, PM3ChipConfig
,
821 (PM3_READ_REG(par
, PM3ChipConfig
) & 0xFFFFFFFD));
825 unsigned char m
; /* ClkPreScale */
826 unsigned char n
; /* ClkFeedBackScale */
827 unsigned char p
; /* ClkPostScale */
828 unsigned long pixclock
= PICOS2KHZ(info
->var
.pixclock
);
830 (void)pm3fb_calculate_clock(pixclock
, &m
, &n
, &p
);
832 DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n",
833 pixclock
, (int) m
, (int) n
, (int) p
);
835 PM3_WRITE_DAC_REG(par
, PM3RD_DClk0PreScale
, m
);
836 PM3_WRITE_DAC_REG(par
, PM3RD_DClk0FeedbackScale
, n
);
837 PM3_WRITE_DAC_REG(par
, PM3RD_DClk0PostScale
, p
);
840 PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00);
843 PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00);
845 if ((par
->video
& PM3VideoControl_HSYNC_MASK
) ==
846 PM3VideoControl_HSYNC_ACTIVE_HIGH
)
847 tempsync
|= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH
;
848 if ((par
->video
& PM3VideoControl_VSYNC_MASK
) ==
849 PM3VideoControl_VSYNC_ACTIVE_HIGH
)
850 tempsync
|= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH
;
852 PM3_WRITE_DAC_REG(par
, PM3RD_SyncControl
, tempsync
);
853 DPRINTK("PM3RD_SyncControl: %d\n", tempsync
);
855 PM3_WRITE_DAC_REG(par
, PM3RD_DACControl
, 0x00);
857 switch (pm3fb_depth(&info
->var
)) {
859 PM3_WRITE_DAC_REG(par
, PM3RD_PixelSize
,
860 PM3RD_PixelSize_8_BIT_PIXELS
);
861 PM3_WRITE_DAC_REG(par
, PM3RD_ColorFormat
,
862 PM3RD_ColorFormat_CI8_COLOR
|
863 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW
);
864 tempmisc
|= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE
;
867 PM3_WRITE_DAC_REG(par
, PM3RD_PixelSize
,
868 PM3RD_PixelSize_16_BIT_PIXELS
);
869 PM3_WRITE_DAC_REG(par
, PM3RD_ColorFormat
,
870 PM3RD_ColorFormat_4444_COLOR
|
871 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW
|
872 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE
);
873 tempmisc
|= PM3RD_MiscControl_DIRECTCOLOR_ENABLE
|
874 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE
;
877 PM3_WRITE_DAC_REG(par
, PM3RD_PixelSize
,
878 PM3RD_PixelSize_16_BIT_PIXELS
);
879 PM3_WRITE_DAC_REG(par
, PM3RD_ColorFormat
,
880 PM3RD_ColorFormat_5551_FRONT_COLOR
|
881 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW
|
882 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE
);
883 tempmisc
|= PM3RD_MiscControl_DIRECTCOLOR_ENABLE
|
884 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE
;
887 PM3_WRITE_DAC_REG(par
, PM3RD_PixelSize
,
888 PM3RD_PixelSize_16_BIT_PIXELS
);
889 PM3_WRITE_DAC_REG(par
, PM3RD_ColorFormat
,
890 PM3RD_ColorFormat_565_FRONT_COLOR
|
891 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW
|
892 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE
);
893 tempmisc
|= PM3RD_MiscControl_DIRECTCOLOR_ENABLE
|
894 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE
;
897 PM3_WRITE_DAC_REG(par
, PM3RD_PixelSize
,
898 PM3RD_PixelSize_32_BIT_PIXELS
);
899 PM3_WRITE_DAC_REG(par
, PM3RD_ColorFormat
,
900 PM3RD_ColorFormat_8888_COLOR
|
901 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW
);
902 tempmisc
|= PM3RD_MiscControl_DIRECTCOLOR_ENABLE
|
903 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE
;
906 PM3_WRITE_DAC_REG(par
, PM3RD_MiscControl
, tempmisc
);
910 * hardware independent functions
912 static int pm3fb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
915 unsigned bpp
= var
->red
.length
+ var
->green
.length
916 + var
->blue
.length
+ var
->transp
.length
;
918 if (bpp
!= var
->bits_per_pixel
) {
919 /* set predefined mode for bits_per_pixel settings */
921 switch (var
->bits_per_pixel
) {
924 var
->green
.length
= 8;
925 var
->blue
.length
= 8;
927 var
->green
.offset
= 0;
928 var
->blue
.offset
= 0;
929 var
->transp
.offset
= 0;
930 var
->transp
.length
= 0;
934 var
->blue
.length
= 5;
935 var
->green
.length
= 6;
936 var
->transp
.length
= 0;
940 var
->green
.length
= 8;
941 var
->blue
.length
= 8;
942 var
->transp
.length
= 8;
945 DPRINTK("depth not supported: %u\n",
946 var
->bits_per_pixel
);
950 /* it is assumed BGRA order */
951 if (var
->bits_per_pixel
> 8 ) {
952 var
->blue
.offset
= 0;
953 var
->green
.offset
= var
->blue
.length
;
954 var
->red
.offset
= var
->green
.offset
+ var
->green
.length
;
955 var
->transp
.offset
= var
->red
.offset
+ var
->red
.length
;
960 if (var
->xres
!= var
->xres_virtual
) {
961 DPRINTK("virtual x resolution != "
962 "physical x resolution not supported\n");
966 if (var
->yres
> var
->yres_virtual
) {
967 DPRINTK("virtual y resolution < "
968 "physical y resolution not possible\n");
973 DPRINTK("xoffset not supported\n");
977 if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
978 DPRINTK("interlace not supported\n");
982 var
->xres
= (var
->xres
+ 31) & ~31; /* could sometimes be 8 */
983 lpitch
= var
->xres
* ((var
->bits_per_pixel
+ 7) >> 3);
985 if (var
->xres
< 200 || var
->xres
> 2048) {
986 DPRINTK("width not supported: %u\n", var
->xres
);
990 if (var
->yres
< 200 || var
->yres
> 4095) {
991 DPRINTK("height not supported: %u\n", var
->yres
);
995 if (lpitch
* var
->yres_virtual
> info
->fix
.smem_len
) {
996 DPRINTK("no memory for screen (%ux%ux%u)\n",
997 var
->xres
, var
->yres_virtual
, var
->bits_per_pixel
);
1001 if (PICOS2KHZ(var
->pixclock
) > PM3_MAX_PIXCLOCK
) {
1002 DPRINTK("pixclock too high (%ldKHz)\n",
1003 PICOS2KHZ(var
->pixclock
));
1007 var
->accel_flags
= 0; /* Can't mmap if this is on */
1009 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
1010 var
->xres
, var
->yres
, var
->bits_per_pixel
);
1014 static int pm3fb_set_par(struct fb_info
*info
)
1016 struct pm3_par
*par
= info
->par
;
1017 const u32 xres
= (info
->var
.xres
+ 31) & ~31;
1018 const unsigned bpp
= info
->var
.bits_per_pixel
;
1020 par
->base
= pm3fb_shift_bpp(bpp
, (info
->var
.yoffset
* xres
)
1021 + info
->var
.xoffset
);
1024 if (info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
)
1025 par
->video
|= PM3VideoControl_HSYNC_ACTIVE_HIGH
;
1027 par
->video
|= PM3VideoControl_HSYNC_ACTIVE_LOW
;
1029 if (info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
)
1030 par
->video
|= PM3VideoControl_VSYNC_ACTIVE_HIGH
;
1032 par
->video
|= PM3VideoControl_VSYNC_ACTIVE_LOW
;
1034 if ((info
->var
.vmode
& FB_VMODE_MASK
) == FB_VMODE_DOUBLE
)
1035 par
->video
|= PM3VideoControl_LINE_DOUBLE_ON
;
1037 if ((info
->var
.activate
& FB_ACTIVATE_MASK
) == FB_ACTIVATE_NOW
)
1038 par
->video
|= PM3VideoControl_ENABLE
;
1040 DPRINTK("PM3Video disabled\n");
1044 par
->video
|= PM3VideoControl_PIXELSIZE_8BIT
;
1047 par
->video
|= PM3VideoControl_PIXELSIZE_16BIT
;
1050 par
->video
|= PM3VideoControl_PIXELSIZE_32BIT
;
1053 DPRINTK("Unsupported depth\n");
1058 (bpp
== 8) ? FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
1059 info
->fix
.line_length
= ((info
->var
.xres_virtual
+ 7) >> 3) * bpp
;
1061 /* pm3fb_clear_memory(info, 0);*/
1062 pm3fb_clear_colormap(par
, 0, 0, 0);
1063 PM3_WRITE_DAC_REG(par
, PM3RD_CursorMode
, 0);
1064 pm3fb_init_engine(info
);
1065 pm3fb_write_mode(info
);
1069 static int pm3fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1070 unsigned blue
, unsigned transp
,
1071 struct fb_info
*info
)
1073 struct pm3_par
*par
= info
->par
;
1075 if (regno
>= 256) /* no. of hw registers */
1078 /* grayscale works only partially under directcolor */
1079 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
1080 if (info
->var
.grayscale
)
1081 red
= green
= blue
= (red
* 77 + green
* 151 + blue
* 28) >> 8;
1084 * var->{color}.offset contains start of bitfield
1085 * var->{color}.length contains length of bitfield
1086 * {hardwarespecific} contains width of DAC
1087 * pseudo_palette[X] is programmed to (X << red.offset) |
1088 * (X << green.offset) |
1089 * (X << blue.offset)
1090 * RAMDAC[X] is programmed to (red, green, blue)
1091 * color depth = SUM(var->{color}.length)
1094 * var->{color}.offset is 0
1095 * var->{color}.length contains width of DAC or the number
1096 * of unique colors available (color depth)
1097 * pseudo_palette is not used
1098 * RAMDAC[X] is programmed to (red, green, blue)
1099 * color depth = var->{color}.length
1103 * This is the point where the color is converted to something that
1104 * is acceptable by the hardware.
1106 #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16)
1107 red
= CNVT_TOHW(red
, info
->var
.red
.length
);
1108 green
= CNVT_TOHW(green
, info
->var
.green
.length
);
1109 blue
= CNVT_TOHW(blue
, info
->var
.blue
.length
);
1110 transp
= CNVT_TOHW(transp
, info
->var
.transp
.length
);
1113 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
||
1114 info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
1120 v
= (red
<< info
->var
.red
.offset
) |
1121 (green
<< info
->var
.green
.offset
) |
1122 (blue
<< info
->var
.blue
.offset
) |
1123 (transp
<< info
->var
.transp
.offset
);
1125 switch (info
->var
.bits_per_pixel
) {
1130 ((u32
*)(info
->pseudo_palette
))[regno
] = v
;
1134 } else if (info
->fix
.visual
== FB_VISUAL_PSEUDOCOLOR
)
1135 pm3fb_set_color(par
, regno
, red
, green
, blue
);
1140 static int pm3fb_pan_display(struct fb_var_screeninfo
*var
,
1141 struct fb_info
*info
)
1143 struct pm3_par
*par
= info
->par
;
1144 const u32 xres
= (info
->var
.xres
+ 31) & ~31;
1146 par
->base
= pm3fb_shift_bpp(info
->var
.bits_per_pixel
,
1147 (var
->yoffset
* xres
)
1150 PM3_WRITE_REG(par
, PM3ScreenBase
, par
->base
);
1154 static int pm3fb_blank(int blank_mode
, struct fb_info
*info
)
1156 struct pm3_par
*par
= info
->par
;
1157 u32 video
= par
->video
;
1160 * Oxygen VX1 - it appears that setting PM3VideoControl and
1161 * then PM3RD_SyncControl to the same SYNC settings undoes
1162 * any net change - they seem to xor together. Only set the
1163 * sync options in PM3RD_SyncControl. --rmk
1165 video
&= ~(PM3VideoControl_HSYNC_MASK
|
1166 PM3VideoControl_VSYNC_MASK
);
1167 video
|= PM3VideoControl_HSYNC_ACTIVE_HIGH
|
1168 PM3VideoControl_VSYNC_ACTIVE_HIGH
;
1170 switch (blank_mode
) {
1171 case FB_BLANK_UNBLANK
:
1172 video
|= PM3VideoControl_ENABLE
;
1174 case FB_BLANK_NORMAL
:
1175 video
&= ~PM3VideoControl_ENABLE
;
1177 case FB_BLANK_HSYNC_SUSPEND
:
1178 video
&= ~(PM3VideoControl_HSYNC_MASK
|
1179 PM3VideoControl_BLANK_ACTIVE_LOW
);
1181 case FB_BLANK_VSYNC_SUSPEND
:
1182 video
&= ~(PM3VideoControl_VSYNC_MASK
|
1183 PM3VideoControl_BLANK_ACTIVE_LOW
);
1185 case FB_BLANK_POWERDOWN
:
1186 video
&= ~(PM3VideoControl_HSYNC_MASK
|
1187 PM3VideoControl_VSYNC_MASK
|
1188 PM3VideoControl_BLANK_ACTIVE_LOW
);
1191 DPRINTK("Unsupported blanking %d\n", blank_mode
);
1196 PM3_WRITE_REG(par
, PM3VideoControl
, video
);
1201 * Frame buffer operations
1204 static const struct fb_ops pm3fb_ops
= {
1205 .owner
= THIS_MODULE
,
1206 __FB_DEFAULT_IOMEM_OPS_RDWR
,
1207 .fb_check_var
= pm3fb_check_var
,
1208 .fb_set_par
= pm3fb_set_par
,
1209 .fb_setcolreg
= pm3fb_setcolreg
,
1210 .fb_pan_display
= pm3fb_pan_display
,
1211 .fb_fillrect
= pm3fb_fillrect
,
1212 .fb_copyarea
= pm3fb_copyarea
,
1213 .fb_imageblit
= pm3fb_imageblit
,
1214 .fb_blank
= pm3fb_blank
,
1215 .fb_sync
= pm3fb_sync
,
1216 .fb_cursor
= pm3fb_cursor
,
1217 __FB_DEFAULT_IOMEM_OPS_MMAP
,
1220 /* ------------------------------------------------------------------------- */
1226 /* mmio register are already mapped when this function is called */
1227 /* the pm3fb_fix.smem_start is also set */
1228 static unsigned long pm3fb_size_memory(struct pm3_par
*par
)
1230 unsigned long memsize
= 0;
1231 unsigned long tempBypass
, i
, temp1
, temp2
;
1232 unsigned char __iomem
*screen_mem
;
1234 pm3fb_fix
.smem_len
= 64 * 1024l * 1024; /* request full aperture size */
1235 /* Linear frame buffer - request region and map it. */
1236 if (!request_mem_region(pm3fb_fix
.smem_start
, pm3fb_fix
.smem_len
,
1238 printk(KERN_WARNING
"pm3fb: Can't reserve smem.\n");
1242 ioremap(pm3fb_fix
.smem_start
, pm3fb_fix
.smem_len
);
1244 printk(KERN_WARNING
"pm3fb: Can't ioremap smem area.\n");
1245 release_mem_region(pm3fb_fix
.smem_start
, pm3fb_fix
.smem_len
);
1249 /* TODO: card-specific stuff, *before* accessing *any* FB memory */
1250 /* For Appian Jeronimo 2000 board second head */
1252 tempBypass
= PM3_READ_REG(par
, PM3MemBypassWriteMask
);
1254 DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass
);
1257 PM3_WRITE_REG(par
, PM3MemBypassWriteMask
, 0xFFFFFFFF);
1259 /* pm3 split up memory, replicates, and do a lot of
1260 * nasty stuff IMHO ;-)
1262 for (i
= 0; i
< 32; i
++) {
1263 fb_writel(i
* 0x00345678,
1264 (screen_mem
+ (i
* 1048576)));
1266 temp1
= fb_readl((screen_mem
+ (i
* 1048576)));
1268 /* Let's check for wrapover, write will fail at 16MB boundary */
1269 if (temp1
== (i
* 0x00345678))
1275 DPRINTK("First detect pass already got %ld MB\n", memsize
+ 1);
1277 if (memsize
+ 1 == i
) {
1278 for (i
= 0; i
< 32; i
++) {
1279 /* Clear first 32MB ; 0 is 0, no need to byteswap */
1280 writel(0x0000000, (screen_mem
+ (i
* 1048576)));
1284 for (i
= 32; i
< 64; i
++) {
1285 fb_writel(i
* 0x00345678,
1286 (screen_mem
+ (i
* 1048576)));
1289 fb_readl((screen_mem
+ (i
* 1048576)));
1291 fb_readl((screen_mem
+ ((i
- 32) * 1048576)));
1292 /* different value, different RAM... */
1293 if ((temp1
== (i
* 0x00345678)) && (temp2
== 0))
1299 DPRINTK("Second detect pass got %ld MB\n", memsize
+ 1);
1302 PM3_WRITE_REG(par
, PM3MemBypassWriteMask
, tempBypass
);
1304 iounmap(screen_mem
);
1305 release_mem_region(pm3fb_fix
.smem_start
, pm3fb_fix
.smem_len
);
1306 memsize
= 1048576 * (memsize
+ 1);
1308 DPRINTK("Returning 0x%08lx bytes\n", memsize
);
1313 static int pm3fb_probe(struct pci_dev
*dev
, const struct pci_device_id
*ent
)
1315 struct fb_info
*info
;
1316 struct pm3_par
*par
;
1317 struct device
*device
= &dev
->dev
; /* for pci drivers */
1319 int retval
= -ENXIO
;
1321 err
= aperture_remove_conflicting_pci_devices(dev
, "pm3fb");
1325 err
= pci_enable_device(dev
);
1327 printk(KERN_WARNING
"pm3fb: Can't enable PCI dev: %d\n", err
);
1331 * Dynamically allocate info and par
1333 info
= framebuffer_alloc(sizeof(struct pm3_par
), device
);
1340 * Here we set the screen_base to the virtual memory address
1341 * for the framebuffer.
1343 pm3fb_fix
.mmio_start
= pci_resource_start(dev
, 0);
1344 pm3fb_fix
.mmio_len
= PM3_REGS_SIZE
;
1345 #if defined(__BIG_ENDIAN)
1346 pm3fb_fix
.mmio_start
+= PM3_REGS_SIZE
;
1347 DPRINTK("Adjusting register base for big-endian.\n");
1350 /* Registers - request region and map it. */
1351 if (!request_mem_region(pm3fb_fix
.mmio_start
, pm3fb_fix
.mmio_len
,
1353 printk(KERN_WARNING
"pm3fb: Can't reserve regbase.\n");
1354 goto err_exit_neither
;
1357 ioremap(pm3fb_fix
.mmio_start
, pm3fb_fix
.mmio_len
);
1359 printk(KERN_WARNING
"pm3fb: Can't remap %s register area.\n",
1361 release_mem_region(pm3fb_fix
.mmio_start
, pm3fb_fix
.mmio_len
);
1362 goto err_exit_neither
;
1365 /* Linear frame buffer - request region and map it. */
1366 pm3fb_fix
.smem_start
= pci_resource_start(dev
, 1);
1367 pm3fb_fix
.smem_len
= pm3fb_size_memory(par
);
1368 if (!pm3fb_fix
.smem_len
) {
1369 printk(KERN_WARNING
"pm3fb: Can't find memory on board.\n");
1372 if (!request_mem_region(pm3fb_fix
.smem_start
, pm3fb_fix
.smem_len
,
1374 printk(KERN_WARNING
"pm3fb: Can't reserve smem.\n");
1377 info
->screen_base
= ioremap_wc(pm3fb_fix
.smem_start
,
1378 pm3fb_fix
.smem_len
);
1379 if (!info
->screen_base
) {
1380 printk(KERN_WARNING
"pm3fb: Can't ioremap smem area.\n");
1381 release_mem_region(pm3fb_fix
.smem_start
, pm3fb_fix
.smem_len
);
1384 info
->screen_size
= pm3fb_fix
.smem_len
;
1387 par
->wc_cookie
= arch_phys_wc_add(pm3fb_fix
.smem_start
,
1388 pm3fb_fix
.smem_len
);
1389 info
->fbops
= &pm3fb_ops
;
1391 par
->video
= PM3_READ_REG(par
, PM3VideoControl
);
1393 info
->fix
= pm3fb_fix
;
1394 info
->pseudo_palette
= par
->palette
;
1395 info
->flags
= FBINFO_HWACCEL_XPAN
|
1396 FBINFO_HWACCEL_YPAN
|
1397 FBINFO_HWACCEL_COPYAREA
|
1398 FBINFO_HWACCEL_IMAGEBLIT
|
1399 FBINFO_HWACCEL_FILLRECT
;
1402 printk(KERN_DEBUG
"disabling acceleration\n");
1403 info
->flags
|= FBINFO_HWACCEL_DISABLED
;
1405 info
->pixmap
.addr
= kmalloc(PM3_PIXMAP_SIZE
, GFP_KERNEL
);
1406 if (!info
->pixmap
.addr
) {
1408 goto err_exit_pixmap
;
1410 info
->pixmap
.size
= PM3_PIXMAP_SIZE
;
1411 info
->pixmap
.buf_align
= 4;
1412 info
->pixmap
.scan_align
= 4;
1413 info
->pixmap
.access_align
= 32;
1414 info
->pixmap
.flags
= FB_PIXMAP_SYSTEM
;
1417 * This should give a reasonable default video mode. The following is
1418 * done when we can set a video mode.
1421 mode_option
= "640x480@60";
1423 retval
= fb_find_mode(&info
->var
, info
, mode_option
, NULL
, 0, NULL
, 8);
1425 if (!retval
|| retval
== 4) {
1430 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
1436 * For drivers that can...
1438 pm3fb_check_var(&info
->var
, info
);
1440 if (register_framebuffer(info
) < 0) {
1444 fb_info(info
, "%s frame buffer device\n", info
->fix
.id
);
1445 pci_set_drvdata(dev
, info
);
1449 fb_dealloc_cmap(&info
->cmap
);
1451 kfree(info
->pixmap
.addr
);
1453 iounmap(info
->screen_base
);
1454 release_mem_region(pm3fb_fix
.smem_start
, pm3fb_fix
.smem_len
);
1456 iounmap(par
->v_regs
);
1457 release_mem_region(pm3fb_fix
.mmio_start
, pm3fb_fix
.mmio_len
);
1459 framebuffer_release(info
);
1466 static void pm3fb_remove(struct pci_dev
*dev
)
1468 struct fb_info
*info
= pci_get_drvdata(dev
);
1471 struct fb_fix_screeninfo
*fix
= &info
->fix
;
1472 struct pm3_par
*par
= info
->par
;
1474 unregister_framebuffer(info
);
1475 fb_dealloc_cmap(&info
->cmap
);
1477 arch_phys_wc_del(par
->wc_cookie
);
1478 iounmap(info
->screen_base
);
1479 release_mem_region(fix
->smem_start
, fix
->smem_len
);
1480 iounmap(par
->v_regs
);
1481 release_mem_region(fix
->mmio_start
, fix
->mmio_len
);
1483 kfree(info
->pixmap
.addr
);
1484 framebuffer_release(info
);
1488 static const struct pci_device_id pm3fb_id_table
[] = {
1489 { PCI_VENDOR_ID_3DLABS
, 0x0a,
1490 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
1494 /* For PCI drivers */
1495 static struct pci_driver pm3fb_driver
= {
1497 .id_table
= pm3fb_id_table
,
1498 .probe
= pm3fb_probe
,
1499 .remove
= pm3fb_remove
,
1502 MODULE_DEVICE_TABLE(pci
, pm3fb_id_table
);
1510 * Only necessary if your driver takes special options,
1511 * otherwise we fall back on the generic fb_setup().
1513 static int __init
pm3fb_setup(char *options
)
1517 /* Parse user specified options (`video=pm3fb:') */
1518 if (!options
|| !*options
)
1521 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1524 else if (!strncmp(this_opt
, "noaccel", 7))
1526 else if (!strncmp(this_opt
, "hwcursor=", 9))
1527 hwcursor
= simple_strtoul(this_opt
+ 9, NULL
, 0);
1528 else if (!strncmp(this_opt
, "nomtrr", 6))
1531 mode_option
= this_opt
;
1537 static int __init
pm3fb_init(void)
1540 * For kernel boot options (in 'video=pm3fb:<options>' format)
1543 char *option
= NULL
;
1546 if (fb_modesetting_disabled("pm3fb"))
1550 if (fb_get_options("pm3fb", &option
))
1552 pm3fb_setup(option
);
1555 return pci_register_driver(&pm3fb_driver
);
1559 static void __exit
pm3fb_exit(void)
1561 pci_unregister_driver(&pm3fb_driver
);
1564 module_exit(pm3fb_exit
);
1566 module_init(pm3fb_init
);
1568 module_param(mode_option
, charp
, 0);
1569 MODULE_PARM_DESC(mode_option
, "Initial video mode e.g. '648x480-8@60'");
1570 module_param(noaccel
, bool, 0);
1571 MODULE_PARM_DESC(noaccel
, "Disable acceleration");
1572 module_param(hwcursor
, int, 0644);
1573 MODULE_PARM_DESC(hwcursor
, "Enable hardware cursor "
1574 "(1=enable, 0=disable, default=1)");
1575 module_param(nomtrr
, bool, 0);
1576 MODULE_PARM_DESC(nomtrr
, "Disable MTRR support (0 or 1=disabled) (default=0)");
1578 MODULE_DESCRIPTION("Permedia3 framebuffer device driver");
1579 MODULE_LICENSE("GPL");