2 * Permedia2 framebuffer driver.
5 * Copyright (c) 2003 Jim Hague (jim.hague@acm.org)
8 * Copyright (c) 1998-2000 Ilario Nardinocchi (nardinoc@CS.UniBO.IT)
9 * Copyright (c) 1999 Jakub Jelinek (jakub@redhat.com)
11 * and additional input from James Simmon's port of Hannu Mallat's tdfx
14 * I have a Creative Graphics Blaster Exxtreme card - pm2fb on x86. I
15 * have no access to other pm2fb implementations. Sparc (and thus
16 * hopefully other big-endian) devices now work, thanks to a lot of
17 * testing work by Ron Murray. I have no access to CVision hardware,
18 * and therefore for now I am omitting the CVision code.
20 * Multiple boards support has been on the TODO list for ages.
21 * Don't expect this to change.
23 * This file is subject to the terms and conditions of the GNU General Public
24 * License. See the file COPYING in the main directory of this archive for
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/moduleparam.h>
33 #include <linux/kernel.h>
34 #include <linux/errno.h>
35 #include <linux/string.h>
37 #include <linux/tty.h>
38 #include <linux/slab.h>
39 #include <linux/delay.h>
41 #include <linux/init.h>
42 #include <linux/pci.h>
44 #include <video/permedia2.h>
45 #include <video/cvisionppc.h>
47 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
48 #error "The endianness of the target host has not been defined."
51 #if !defined(CONFIG_PCI)
52 #error "Only generic PCI cards supported."
55 #undef PM2FB_MASTER_DEBUG
56 #ifdef PM2FB_MASTER_DEBUG
57 #define DPRINTK(a,b...) printk(KERN_DEBUG "pm2fb: %s: " a, __FUNCTION__ , ## b)
59 #define DPRINTK(a,b...)
65 static char *mode __devinitdata
= NULL
;
68 * The XFree GLINT driver will (I think to implement hardware cursor
69 * support on TVP4010 and similar where there is no RAMDAC - see
70 * comment in set_video) always request +ve sync regardless of what
71 * the mode requires. This screws me because I have a Sun
72 * fixed-frequency monitor which absolutely has to have -ve sync. So
73 * these flags allow the user to specify that requests for +ve sync
74 * should be silently turned in -ve sync.
80 * The hardware state of the graphics card that isn't part of the
85 pm2type_t type
; /* Board type */
86 u32 fb_size
; /* framebuffer memory size */
87 unsigned char __iomem
*v_fb
; /* virtual address of frame buffer */
88 unsigned char __iomem
*v_regs
;/* virtual address of p_regs */
89 u32 memclock
; /* memclock */
90 u32 video
; /* video flags before blanking */
91 u32 mem_config
; /* MemConfig reg at probe */
92 u32 mem_control
; /* MemControl reg at probe */
93 u32 boot_address
; /* BootAddress reg at probe */
98 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
99 * if we don't use modedb.
101 static struct fb_fix_screeninfo pm2fb_fix __devinitdata
= {
103 .type
= FB_TYPE_PACKED_PIXELS
,
104 .visual
= FB_VISUAL_PSEUDOCOLOR
,
108 .accel
= FB_ACCEL_NONE
,
112 * Default video mode. In case the modedb doesn't work.
114 static struct fb_var_screeninfo pm2fb_var __devinitdata
= {
115 /* "640x480, 8 bpp @ 60 Hz */
124 .activate
= FB_ACTIVATE_NOW
,
135 .vmode
= FB_VMODE_NONINTERLACED
142 static inline u32
RD32(unsigned char __iomem
*base
, s32 off
)
144 return fb_readl(base
+ off
);
147 static inline void WR32(unsigned char __iomem
*base
, s32 off
, u32 v
)
149 fb_writel(v
, base
+ off
);
152 static inline u32
pm2_RD(struct pm2fb_par
* p
, s32 off
)
154 return RD32(p
->v_regs
, off
);
157 static inline void pm2_WR(struct pm2fb_par
* p
, s32 off
, u32 v
)
159 WR32(p
->v_regs
, off
, v
);
162 static inline u32
pm2_RDAC_RD(struct pm2fb_par
* p
, s32 idx
)
164 int index
= PM2R_RD_INDEXED_DATA
;
166 case PM2_TYPE_PERMEDIA2
:
167 pm2_WR(p
, PM2R_RD_PALETTE_WRITE_ADDRESS
, idx
);
169 case PM2_TYPE_PERMEDIA2V
:
170 pm2_WR(p
, PM2VR_RD_INDEX_LOW
, idx
& 0xff);
171 index
= PM2VR_RD_INDEXED_DATA
;
175 return pm2_RD(p
, index
);
178 static inline void pm2_RDAC_WR(struct pm2fb_par
* p
, s32 idx
, u32 v
)
180 int index
= PM2R_RD_INDEXED_DATA
;
182 case PM2_TYPE_PERMEDIA2
:
183 pm2_WR(p
, PM2R_RD_PALETTE_WRITE_ADDRESS
, idx
);
185 case PM2_TYPE_PERMEDIA2V
:
186 pm2_WR(p
, PM2VR_RD_INDEX_LOW
, idx
& 0xff);
187 index
= PM2VR_RD_INDEXED_DATA
;
194 static inline void pm2v_RDAC_WR(struct pm2fb_par
* p
, s32 idx
, u32 v
)
196 pm2_WR(p
, PM2VR_RD_INDEX_LOW
, idx
& 0xff);
198 pm2_WR(p
, PM2VR_RD_INDEXED_DATA
, v
);
201 #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
202 #define WAIT_FIFO(p,a)
204 static inline void WAIT_FIFO(struct pm2fb_par
* p
, u32 a
)
206 while( pm2_RD(p
, PM2R_IN_FIFO_SPACE
) < a
);
212 * partial products for the supported horizontal resolutions.
214 #define PACKPP(p0,p1,p2) (((p2) << 6) | ((p1) << 3) | (p0))
215 static const struct {
219 { 32, PACKPP(1, 0, 0) }, { 64, PACKPP(1, 1, 0) },
220 { 96, PACKPP(1, 1, 1) }, { 128, PACKPP(2, 1, 1) },
221 { 160, PACKPP(2, 2, 1) }, { 192, PACKPP(2, 2, 2) },
222 { 224, PACKPP(3, 2, 1) }, { 256, PACKPP(3, 2, 2) },
223 { 288, PACKPP(3, 3, 1) }, { 320, PACKPP(3, 3, 2) },
224 { 384, PACKPP(3, 3, 3) }, { 416, PACKPP(4, 3, 1) },
225 { 448, PACKPP(4, 3, 2) }, { 512, PACKPP(4, 3, 3) },
226 { 544, PACKPP(4, 4, 1) }, { 576, PACKPP(4, 4, 2) },
227 { 640, PACKPP(4, 4, 3) }, { 768, PACKPP(4, 4, 4) },
228 { 800, PACKPP(5, 4, 1) }, { 832, PACKPP(5, 4, 2) },
229 { 896, PACKPP(5, 4, 3) }, { 1024, PACKPP(5, 4, 4) },
230 { 1056, PACKPP(5, 5, 1) }, { 1088, PACKPP(5, 5, 2) },
231 { 1152, PACKPP(5, 5, 3) }, { 1280, PACKPP(5, 5, 4) },
232 { 1536, PACKPP(5, 5, 5) }, { 1568, PACKPP(6, 5, 1) },
233 { 1600, PACKPP(6, 5, 2) }, { 1664, PACKPP(6, 5, 3) },
234 { 1792, PACKPP(6, 5, 4) }, { 2048, PACKPP(6, 5, 5) },
237 static u32
partprod(u32 xres
)
241 for (i
= 0; pp_table
[i
].width
&& pp_table
[i
].width
!= xres
; i
++)
243 if ( pp_table
[i
].width
== 0 )
244 DPRINTK("invalid width %u\n", xres
);
245 return pp_table
[i
].pp
;
248 static u32
to3264(u32 timing
, int bpp
, int is64
)
258 timing
= (timing
* 3) >> (2 + is64
);
268 static void pm2_mnp(u32 clk
, unsigned char* mm
, unsigned char* nn
,
279 for (n
= 2; n
< 15; n
++) {
280 for (m
= 2; m
; m
++) {
281 f
= PM2_REFERENCE_CLOCK
* m
/ n
;
282 if (f
>= 150000 && f
<= 300000) {
283 for ( p
= 0; p
< 5; p
++, f
>>= 1) {
284 curr
= ( clk
> f
) ? clk
- f
: f
- clk
;
285 if ( curr
< delta
) {
297 static void pm2v_mnp(u32 clk
, unsigned char* mm
, unsigned char* nn
,
307 for (n
= 1; n
; n
++) {
308 for ( m
= 1; m
; m
++) {
309 for ( p
= 0; p
< 2; p
++) {
310 f
= PM2_REFERENCE_CLOCK
* n
/ (m
* (1 << (p
+ 1)));
311 if ( clk
> f
- delta
&& clk
< f
+ delta
) {
312 delta
= ( clk
> f
) ? clk
- f
: f
- clk
;
322 static void clear_palette(struct pm2fb_par
* p
) {
326 pm2_WR(p
, PM2R_RD_PALETTE_WRITE_ADDRESS
, 0);
330 pm2_WR(p
, PM2R_RD_PALETTE_DATA
, 0);
331 pm2_WR(p
, PM2R_RD_PALETTE_DATA
, 0);
332 pm2_WR(p
, PM2R_RD_PALETTE_DATA
, 0);
336 static void reset_card(struct pm2fb_par
* p
)
338 if (p
->type
== PM2_TYPE_PERMEDIA2V
)
339 pm2_WR(p
, PM2VR_RD_INDEX_HIGH
, 0);
340 pm2_WR(p
, PM2R_RESET_STATUS
, 0);
342 while (pm2_RD(p
, PM2R_RESET_STATUS
) & PM2F_BEING_RESET
)
345 #ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
346 DPRINTK("FIFO disconnect enabled\n");
347 pm2_WR(p
, PM2R_FIFO_DISCON
, 1);
351 /* Restore stashed memory config information from probe */
353 pm2_WR(p
, PM2R_MEM_CONTROL
, p
->mem_control
);
354 pm2_WR(p
, PM2R_BOOT_ADDRESS
, p
->boot_address
);
356 pm2_WR(p
, PM2R_MEM_CONFIG
, p
->mem_config
);
359 static void reset_config(struct pm2fb_par
* p
)
362 pm2_WR(p
, PM2R_CHIP_CONFIG
, pm2_RD(p
, PM2R_CHIP_CONFIG
)&
363 ~(PM2F_VGA_ENABLE
|PM2F_VGA_FIXED
));
364 pm2_WR(p
, PM2R_BYPASS_WRITE_MASK
, ~(0L));
365 pm2_WR(p
, PM2R_FRAMEBUFFER_WRITE_MASK
, ~(0L));
366 pm2_WR(p
, PM2R_FIFO_CONTROL
, 0);
367 pm2_WR(p
, PM2R_APERTURE_ONE
, 0);
368 pm2_WR(p
, PM2R_APERTURE_TWO
, 0);
369 pm2_WR(p
, PM2R_RASTERIZER_MODE
, 0);
370 pm2_WR(p
, PM2R_DELTA_MODE
, PM2F_DELTA_ORDER_RGB
);
371 pm2_WR(p
, PM2R_LB_READ_FORMAT
, 0);
372 pm2_WR(p
, PM2R_LB_WRITE_FORMAT
, 0);
373 pm2_WR(p
, PM2R_LB_READ_MODE
, 0);
374 pm2_WR(p
, PM2R_LB_SOURCE_OFFSET
, 0);
375 pm2_WR(p
, PM2R_FB_SOURCE_OFFSET
, 0);
376 pm2_WR(p
, PM2R_FB_PIXEL_OFFSET
, 0);
377 pm2_WR(p
, PM2R_FB_WINDOW_BASE
, 0);
378 pm2_WR(p
, PM2R_LB_WINDOW_BASE
, 0);
379 pm2_WR(p
, PM2R_FB_SOFT_WRITE_MASK
, ~(0L));
380 pm2_WR(p
, PM2R_FB_HARD_WRITE_MASK
, ~(0L));
381 pm2_WR(p
, PM2R_FB_READ_PIXEL
, 0);
382 pm2_WR(p
, PM2R_DITHER_MODE
, 0);
383 pm2_WR(p
, PM2R_AREA_STIPPLE_MODE
, 0);
384 pm2_WR(p
, PM2R_DEPTH_MODE
, 0);
385 pm2_WR(p
, PM2R_STENCIL_MODE
, 0);
386 pm2_WR(p
, PM2R_TEXTURE_ADDRESS_MODE
, 0);
387 pm2_WR(p
, PM2R_TEXTURE_READ_MODE
, 0);
388 pm2_WR(p
, PM2R_TEXEL_LUT_MODE
, 0);
389 pm2_WR(p
, PM2R_YUV_MODE
, 0);
390 pm2_WR(p
, PM2R_COLOR_DDA_MODE
, 0);
391 pm2_WR(p
, PM2R_TEXTURE_COLOR_MODE
, 0);
392 pm2_WR(p
, PM2R_FOG_MODE
, 0);
393 pm2_WR(p
, PM2R_ALPHA_BLEND_MODE
, 0);
394 pm2_WR(p
, PM2R_LOGICAL_OP_MODE
, 0);
395 pm2_WR(p
, PM2R_STATISTICS_MODE
, 0);
396 pm2_WR(p
, PM2R_SCISSOR_MODE
, 0);
397 pm2_WR(p
, PM2R_FILTER_MODE
, PM2F_SYNCHRONIZATION
);
399 case PM2_TYPE_PERMEDIA2
:
400 pm2_RDAC_WR(p
, PM2I_RD_MODE_CONTROL
, 0); /* no overlay */
401 pm2_RDAC_WR(p
, PM2I_RD_CURSOR_CONTROL
, 0);
402 pm2_RDAC_WR(p
, PM2I_RD_MISC_CONTROL
, PM2F_RD_PALETTE_WIDTH_8
);
404 case PM2_TYPE_PERMEDIA2V
:
405 pm2v_RDAC_WR(p
, PM2VI_RD_MISC_CONTROL
, 1); /* 8bit */
408 pm2_RDAC_WR(p
, PM2I_RD_COLOR_KEY_CONTROL
, 0);
409 pm2_RDAC_WR(p
, PM2I_RD_OVERLAY_KEY
, 0);
410 pm2_RDAC_WR(p
, PM2I_RD_RED_KEY
, 0);
411 pm2_RDAC_WR(p
, PM2I_RD_GREEN_KEY
, 0);
412 pm2_RDAC_WR(p
, PM2I_RD_BLUE_KEY
, 0);
415 static void set_aperture(struct pm2fb_par
* p
, u32 depth
)
418 * The hardware is little-endian. When used in big-endian
419 * hosts, the on-chip aperture settings are used where
420 * possible to translate from host to card byte order.
423 #ifdef __LITTLE_ENDIAN
424 pm2_WR(p
, PM2R_APERTURE_ONE
, PM2F_APERTURE_STANDARD
);
427 case 24: /* RGB->BGR */
429 * We can't use the aperture to translate host to
430 * card byte order here, so we switch to BGR mode
431 * in pm2fb_set_par().
434 pm2_WR(p
, PM2R_APERTURE_ONE
, PM2F_APERTURE_STANDARD
);
436 case 16: /* HL->LH */
437 pm2_WR(p
, PM2R_APERTURE_ONE
, PM2F_APERTURE_HALFWORDSWAP
);
439 case 32: /* RGBA->ABGR */
440 pm2_WR(p
, PM2R_APERTURE_ONE
, PM2F_APERTURE_BYTESWAP
);
445 // We don't use aperture two, so this may be superflous
446 pm2_WR(p
, PM2R_APERTURE_TWO
, PM2F_APERTURE_STANDARD
);
449 static void set_color(struct pm2fb_par
* p
, unsigned char regno
,
450 unsigned char r
, unsigned char g
, unsigned char b
)
453 pm2_WR(p
, PM2R_RD_PALETTE_WRITE_ADDRESS
, regno
);
455 pm2_WR(p
, PM2R_RD_PALETTE_DATA
, r
);
457 pm2_WR(p
, PM2R_RD_PALETTE_DATA
, g
);
459 pm2_WR(p
, PM2R_RD_PALETTE_DATA
, b
);
462 static void set_memclock(struct pm2fb_par
* par
, u32 clk
)
465 unsigned char m
, n
, p
;
467 pm2_mnp(clk
, &m
, &n
, &p
);
469 pm2_RDAC_WR(par
, PM2I_RD_MEMORY_CLOCK_3
, 6);
471 pm2_RDAC_WR(par
, PM2I_RD_MEMORY_CLOCK_1
, m
);
472 pm2_RDAC_WR(par
, PM2I_RD_MEMORY_CLOCK_2
, n
);
474 pm2_RDAC_WR(par
, PM2I_RD_MEMORY_CLOCK_3
, 8|p
);
476 pm2_RDAC_RD(par
, PM2I_RD_MEMORY_CLOCK_STATUS
);
479 i
&& !(pm2_RD(par
, PM2R_RD_INDEXED_DATA
) & PM2F_PLL_LOCKED
);
484 static void set_pixclock(struct pm2fb_par
* par
, u32 clk
)
487 unsigned char m
, n
, p
;
490 case PM2_TYPE_PERMEDIA2
:
491 pm2_mnp(clk
, &m
, &n
, &p
);
493 pm2_RDAC_WR(par
, PM2I_RD_PIXEL_CLOCK_A3
, 0);
495 pm2_RDAC_WR(par
, PM2I_RD_PIXEL_CLOCK_A1
, m
);
496 pm2_RDAC_WR(par
, PM2I_RD_PIXEL_CLOCK_A2
, n
);
498 pm2_RDAC_WR(par
, PM2I_RD_PIXEL_CLOCK_A3
, 8|p
);
500 pm2_RDAC_RD(par
, PM2I_RD_PIXEL_CLOCK_STATUS
);
503 i
&& !(pm2_RD(par
, PM2R_RD_INDEXED_DATA
) & PM2F_PLL_LOCKED
);
507 case PM2_TYPE_PERMEDIA2V
:
508 pm2v_mnp(clk
/2, &m
, &n
, &p
);
510 pm2_WR(par
, PM2VR_RD_INDEX_HIGH
, PM2VI_RD_CLK0_PRESCALE
>> 8);
511 pm2v_RDAC_WR(par
, PM2VI_RD_CLK0_PRESCALE
, m
);
512 pm2v_RDAC_WR(par
, PM2VI_RD_CLK0_FEEDBACK
, n
);
513 pm2v_RDAC_WR(par
, PM2VI_RD_CLK0_POSTSCALE
, p
);
514 pm2_WR(par
, PM2VR_RD_INDEX_HIGH
, 0);
519 static void set_video(struct pm2fb_par
* p
, u32 video
) {
525 DPRINTK("video = 0x%x\n", video
);
528 * The hardware cursor needs +vsync to recognise vert retrace.
529 * We may not be using the hardware cursor, but the X Glint
530 * driver may well. So always set +hsync/+vsync and then set
531 * the RAMDAC to invert the sync if necessary.
533 vsync
&= ~(PM2F_HSYNC_MASK
|PM2F_VSYNC_MASK
);
534 vsync
|= PM2F_HSYNC_ACT_HIGH
|PM2F_VSYNC_ACT_HIGH
;
537 pm2_WR(p
, PM2R_VIDEO_CONTROL
, vsync
);
540 case PM2_TYPE_PERMEDIA2
:
541 tmp
= PM2F_RD_PALETTE_WIDTH_8
;
542 if ((video
& PM2F_HSYNC_MASK
) == PM2F_HSYNC_ACT_LOW
)
543 tmp
|= 4; /* invert hsync */
544 if ((video
& PM2F_VSYNC_MASK
) == PM2F_VSYNC_ACT_LOW
)
545 tmp
|= 8; /* invert vsync */
546 pm2_RDAC_WR(p
, PM2I_RD_MISC_CONTROL
, tmp
);
548 case PM2_TYPE_PERMEDIA2V
:
550 if ((video
& PM2F_HSYNC_MASK
) == PM2F_HSYNC_ACT_LOW
)
551 tmp
|= 1; /* invert hsync */
552 if ((video
& PM2F_VSYNC_MASK
) == PM2F_VSYNC_ACT_LOW
)
553 tmp
|= 4; /* invert vsync */
554 pm2v_RDAC_WR(p
, PM2VI_RD_SYNC_CONTROL
, tmp
);
555 pm2v_RDAC_WR(p
, PM2VI_RD_MISC_CONTROL
, 1);
565 * pm2fb_check_var - Optional function. Validates a var passed in.
566 * @var: frame buffer variable screen structure
567 * @info: frame buffer structure that represents a single frame buffer
569 * Checks to see if the hardware supports the state requested by
572 * Returns negative errno on error, or zero on success.
574 static int pm2fb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
578 if (var
->bits_per_pixel
!= 8 && var
->bits_per_pixel
!= 16 &&
579 var
->bits_per_pixel
!= 24 && var
->bits_per_pixel
!= 32) {
580 DPRINTK("depth not supported: %u\n", var
->bits_per_pixel
);
584 if (var
->xres
!= var
->xres_virtual
) {
585 DPRINTK("virtual x resolution != physical x resolution not supported\n");
589 if (var
->yres
> var
->yres_virtual
) {
590 DPRINTK("virtual y resolution < physical y resolution not possible\n");
595 DPRINTK("xoffset not supported\n");
599 if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
600 DPRINTK("interlace not supported\n");
604 var
->xres
= (var
->xres
+ 15) & ~15; /* could sometimes be 8 */
605 lpitch
= var
->xres
* ((var
->bits_per_pixel
+ 7)>>3);
607 if (var
->xres
< 320 || var
->xres
> 1600) {
608 DPRINTK("width not supported: %u\n", var
->xres
);
612 if (var
->yres
< 200 || var
->yres
> 1200) {
613 DPRINTK("height not supported: %u\n", var
->yres
);
617 if (lpitch
* var
->yres_virtual
> info
->fix
.smem_len
) {
618 DPRINTK("no memory for screen (%ux%ux%u)\n",
619 var
->xres
, var
->yres_virtual
, var
->bits_per_pixel
);
623 if (PICOS2KHZ(var
->pixclock
) > PM2_MAX_PIXCLOCK
) {
624 DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var
->pixclock
));
628 switch(var
->bits_per_pixel
) {
630 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
633 var
->red
.offset
= 11;
635 var
->green
.offset
= 5;
636 var
->green
.length
= 6;
637 var
->blue
.offset
= 0;
638 var
->blue
.length
= 5;
641 var
->transp
.offset
= 24;
642 var
->transp
.length
= 8;
643 var
->red
.offset
= 16;
644 var
->green
.offset
= 8;
645 var
->blue
.offset
= 0;
646 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
651 var
->blue
.offset
= 16;
653 var
->red
.offset
= 16;
654 var
->blue
.offset
= 0;
656 var
->green
.offset
= 8;
657 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
660 var
->height
= var
->width
= -1;
662 var
->accel_flags
= 0; /* Can't mmap if this is on */
664 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
665 var
->xres
, var
->yres
, var
->bits_per_pixel
);
670 * pm2fb_set_par - Alters the hardware state.
671 * @info: frame buffer structure that represents a single frame buffer
673 * Using the fb_var_screeninfo in fb_info we set the resolution of the
674 * this particular framebuffer.
676 static int pm2fb_set_par(struct fb_info
*info
)
678 struct pm2fb_par
*par
= info
->par
;
680 u32 width
, height
, depth
;
681 u32 hsstart
, hsend
, hbend
, htotal
;
682 u32 vsstart
, vsend
, vbend
, vtotal
;
686 u32 clrmode
= PM2F_RD_COLOR_MODE_RGB
| PM2F_RD_GUI_ACTIVE
;
697 set_memclock(par
, par
->memclock
);
699 width
= (info
->var
.xres_virtual
+ 7) & ~7;
700 height
= info
->var
.yres_virtual
;
701 depth
= (info
->var
.bits_per_pixel
+ 7) & ~7;
702 depth
= (depth
> 32) ? 32 : depth
;
703 data64
= depth
> 8 || par
->type
== PM2_TYPE_PERMEDIA2V
;
705 xres
= (info
->var
.xres
+ 31) & ~31;
706 pixclock
= PICOS2KHZ(info
->var
.pixclock
);
707 if (pixclock
> PM2_MAX_PIXCLOCK
) {
708 DPRINTK("pixclock too high (%uKHz)\n", pixclock
);
712 hsstart
= to3264(info
->var
.right_margin
, depth
, data64
);
713 hsend
= hsstart
+ to3264(info
->var
.hsync_len
, depth
, data64
);
714 hbend
= hsend
+ to3264(info
->var
.left_margin
, depth
, data64
);
715 htotal
= to3264(xres
, depth
, data64
) + hbend
- 1;
716 vsstart
= (info
->var
.lower_margin
)
717 ? info
->var
.lower_margin
- 1
719 vsend
= info
->var
.lower_margin
+ info
->var
.vsync_len
- 1;
720 vbend
= info
->var
.lower_margin
+ info
->var
.vsync_len
+ info
->var
.upper_margin
;
721 vtotal
= info
->var
.yres
+ vbend
- 1;
722 stride
= to3264(width
, depth
, 1);
723 base
= to3264(info
->var
.yoffset
* xres
+ info
->var
.xoffset
, depth
, 1);
725 video
|= PM2F_DATA_64_ENABLE
;
727 if (info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
) {
729 DPRINTK("ignoring +hsync, using -hsync.\n");
730 video
|= PM2F_HSYNC_ACT_LOW
;
732 video
|= PM2F_HSYNC_ACT_HIGH
;
735 video
|= PM2F_HSYNC_ACT_LOW
;
736 if (info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
) {
738 DPRINTK("ignoring +vsync, using -vsync.\n");
739 video
|= PM2F_VSYNC_ACT_LOW
;
741 video
|= PM2F_VSYNC_ACT_HIGH
;
744 video
|= PM2F_VSYNC_ACT_LOW
;
745 if ((info
->var
.vmode
& FB_VMODE_MASK
)==FB_VMODE_INTERLACED
) {
746 DPRINTK("interlaced not supported\n");
749 if ((info
->var
.vmode
& FB_VMODE_MASK
)==FB_VMODE_DOUBLE
)
750 video
|= PM2F_LINE_DOUBLE
;
751 if ((info
->var
.activate
& FB_ACTIVATE_MASK
)==FB_ACTIVATE_NOW
)
752 video
|= PM2F_VIDEO_ENABLE
;
756 (depth
== 8) ? FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
757 info
->fix
.line_length
= info
->var
.xres
* depth
/ 8;
758 info
->cmap
.len
= 256;
761 * Settings calculated. Now write them out.
763 if (par
->type
== PM2_TYPE_PERMEDIA2V
) {
765 pm2_WR(par
, PM2VR_RD_INDEX_HIGH
, 0);
768 set_aperture(par
, depth
);
772 pm2_RDAC_WR(par
, PM2I_RD_COLOR_KEY_CONTROL
,
773 ( depth
== 8 ) ? 0 : PM2F_COLOR_KEY_TEST_OFF
);
776 pm2_WR(par
, PM2R_FB_READ_PIXEL
, 0);
780 pm2_WR(par
, PM2R_FB_READ_PIXEL
, 1);
781 clrmode
|= PM2F_RD_TRUECOLOR
| PM2F_RD_PIXELFORMAT_RGB565
;
782 txtmap
= PM2F_TEXTEL_SIZE_16
;
787 pm2_WR(par
, PM2R_FB_READ_PIXEL
, 2);
788 clrmode
|= PM2F_RD_TRUECOLOR
| PM2F_RD_PIXELFORMAT_RGBA8888
;
789 txtmap
= PM2F_TEXTEL_SIZE_32
;
794 pm2_WR(par
, PM2R_FB_READ_PIXEL
, 4);
795 clrmode
|= PM2F_RD_TRUECOLOR
| PM2F_RD_PIXELFORMAT_RGB888
;
796 txtmap
= PM2F_TEXTEL_SIZE_24
;
801 pm2_WR(par
, PM2R_FB_WRITE_MODE
, PM2F_FB_WRITE_ENABLE
);
802 pm2_WR(par
, PM2R_FB_READ_MODE
, partprod(xres
));
803 pm2_WR(par
, PM2R_LB_READ_MODE
, partprod(xres
));
804 pm2_WR(par
, PM2R_TEXTURE_MAP_FORMAT
, txtmap
| partprod(xres
));
805 pm2_WR(par
, PM2R_H_TOTAL
, htotal
);
806 pm2_WR(par
, PM2R_HS_START
, hsstart
);
807 pm2_WR(par
, PM2R_HS_END
, hsend
);
808 pm2_WR(par
, PM2R_HG_END
, hbend
);
809 pm2_WR(par
, PM2R_HB_END
, hbend
);
810 pm2_WR(par
, PM2R_V_TOTAL
, vtotal
);
811 pm2_WR(par
, PM2R_VS_START
, vsstart
);
812 pm2_WR(par
, PM2R_VS_END
, vsend
);
813 pm2_WR(par
, PM2R_VB_END
, vbend
);
814 pm2_WR(par
, PM2R_SCREEN_STRIDE
, stride
);
816 pm2_WR(par
, PM2R_WINDOW_ORIGIN
, 0);
817 pm2_WR(par
, PM2R_SCREEN_SIZE
, (height
<< 16) | width
);
818 pm2_WR(par
, PM2R_SCISSOR_MODE
, PM2F_SCREEN_SCISSOR_ENABLE
);
820 pm2_WR(par
, PM2R_SCREEN_BASE
, base
);
822 set_video(par
, video
);
825 case PM2_TYPE_PERMEDIA2
:
826 pm2_RDAC_WR(par
, PM2I_RD_COLOR_MODE
, clrmode
);
828 case PM2_TYPE_PERMEDIA2V
:
829 pm2v_RDAC_WR(par
, PM2VI_RD_PIXEL_SIZE
, pixsize
);
830 pm2v_RDAC_WR(par
, PM2VI_RD_COLOR_FORMAT
, clrformat
);
833 set_pixclock(par
, pixclock
);
834 DPRINTK("Setting graphics mode at %dx%d depth %d\n",
835 info
->var
.xres
, info
->var
.yres
, info
->var
.bits_per_pixel
);
840 * pm2fb_setcolreg - Sets a color register.
841 * @regno: boolean, 0 copy local, 1 get_user() function
842 * @red: frame buffer colormap structure
843 * @green: The green value which can be up to 16 bits wide
844 * @blue: The blue value which can be up to 16 bits wide.
845 * @transp: If supported the alpha value which can be up to 16 bits wide.
846 * @info: frame buffer info structure
848 * Set a single color register. The values supplied have a 16 bit
849 * magnitude which needs to be scaled in this function for the hardware.
850 * Pretty much a direct lift from tdfxfb.c.
852 * Returns negative errno on error, or zero on success.
854 static int pm2fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
855 unsigned blue
, unsigned transp
,
856 struct fb_info
*info
)
858 struct pm2fb_par
*par
= info
->par
;
860 if (regno
>= info
->cmap
.len
) /* no. of hw registers */
863 * Program hardware... do anything you want with transp
866 /* grayscale works only partially under directcolor */
867 if (info
->var
.grayscale
) {
868 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
869 red
= green
= blue
= (red
* 77 + green
* 151 + blue
* 28) >> 8;
873 * var->{color}.offset contains start of bitfield
874 * var->{color}.length contains length of bitfield
875 * {hardwarespecific} contains width of DAC
876 * cmap[X] is programmed to
877 * (X << red.offset) | (X << green.offset) | (X << blue.offset)
878 * RAMDAC[X] is programmed to (red, green, blue)
881 * uses offset = 0 && length = DAC register width.
882 * var->{color}.offset is 0
883 * var->{color}.length contains widht of DAC
885 * DAC[X] is programmed to (red, green, blue)
887 * does not use RAMDAC (usually has 3 of them).
888 * var->{color}.offset contains start of bitfield
889 * var->{color}.length contains length of bitfield
890 * cmap is programmed to
891 * (red << red.offset) | (green << green.offset) |
892 * (blue << blue.offset) | (transp << transp.offset)
893 * RAMDAC does not exist
895 #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
896 switch (info
->fix
.visual
) {
897 case FB_VISUAL_TRUECOLOR
:
898 case FB_VISUAL_PSEUDOCOLOR
:
899 red
= CNVT_TOHW(red
, info
->var
.red
.length
);
900 green
= CNVT_TOHW(green
, info
->var
.green
.length
);
901 blue
= CNVT_TOHW(blue
, info
->var
.blue
.length
);
902 transp
= CNVT_TOHW(transp
, info
->var
.transp
.length
);
904 case FB_VISUAL_DIRECTCOLOR
:
905 /* example here assumes 8 bit DAC. Might be different
906 * for your hardware */
907 red
= CNVT_TOHW(red
, 8);
908 green
= CNVT_TOHW(green
, 8);
909 blue
= CNVT_TOHW(blue
, 8);
910 /* hey, there is bug in transp handling... */
911 transp
= CNVT_TOHW(transp
, 8);
915 /* Truecolor has hardware independent palette */
916 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
922 v
= (red
<< info
->var
.red
.offset
) |
923 (green
<< info
->var
.green
.offset
) |
924 (blue
<< info
->var
.blue
.offset
) |
925 (transp
<< info
->var
.transp
.offset
);
927 switch (info
->var
.bits_per_pixel
) {
933 par
->palette
[regno
] = v
;
938 else if (info
->fix
.visual
== FB_VISUAL_PSEUDOCOLOR
)
939 set_color(par
, regno
, red
, green
, blue
);
945 * pm2fb_pan_display - Pans the display.
946 * @var: frame buffer variable screen structure
947 * @info: frame buffer structure that represents a single frame buffer
949 * Pan (or wrap, depending on the `vmode' field) the display using the
950 * `xoffset' and `yoffset' fields of the `var' structure.
951 * If the values don't fit, return -EINVAL.
953 * Returns negative errno on error, or zero on success.
956 static int pm2fb_pan_display(struct fb_var_screeninfo
*var
,
957 struct fb_info
*info
)
959 struct pm2fb_par
*p
= info
->par
;
964 xres
= (var
->xres
+ 31) & ~31;
965 depth
= (var
->bits_per_pixel
+ 7) & ~7;
966 depth
= (depth
> 32) ? 32 : depth
;
967 base
= to3264(var
->yoffset
* xres
+ var
->xoffset
, depth
, 1);
969 pm2_WR(p
, PM2R_SCREEN_BASE
, base
);
974 * pm2fb_blank - Blanks the display.
975 * @blank_mode: the blank mode we want.
976 * @info: frame buffer structure that represents a single frame buffer
978 * Blank the screen if blank_mode != 0, else unblank. Return 0 if
979 * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
980 * video mode which doesn't support it. Implements VESA suspend
981 * and powerdown modes on hardware that supports disabling hsync/vsync:
982 * blank_mode == 2: suspend vsync
983 * blank_mode == 3: suspend hsync
984 * blank_mode == 4: powerdown
986 * Returns negative errno on error, or zero on success.
989 static int pm2fb_blank(int blank_mode
, struct fb_info
*info
)
991 struct pm2fb_par
*par
= info
->par
;
992 u32 video
= par
->video
;
994 DPRINTK("blank_mode %d\n", blank_mode
);
996 switch (blank_mode
) {
997 case FB_BLANK_UNBLANK
:
999 video
|= PM2F_VIDEO_ENABLE
;
1001 case FB_BLANK_NORMAL
:
1003 video
&= ~PM2F_VIDEO_ENABLE
;
1005 case FB_BLANK_VSYNC_SUSPEND
:
1007 video
&= ~(PM2F_VSYNC_MASK
| PM2F_BLANK_LOW
);
1009 case FB_BLANK_HSYNC_SUSPEND
:
1011 video
&= ~(PM2F_HSYNC_MASK
| PM2F_BLANK_LOW
);
1013 case FB_BLANK_POWERDOWN
:
1014 /* HSync: Off, VSync: Off */
1015 video
&= ~(PM2F_VSYNC_MASK
| PM2F_HSYNC_MASK
| PM2F_BLANK_LOW
);
1018 set_video(par
, video
);
1022 /* ------------ Hardware Independent Functions ------------ */
1025 * Frame buffer operations
1028 static struct fb_ops pm2fb_ops
= {
1029 .owner
= THIS_MODULE
,
1030 .fb_check_var
= pm2fb_check_var
,
1031 .fb_set_par
= pm2fb_set_par
,
1032 .fb_setcolreg
= pm2fb_setcolreg
,
1033 .fb_blank
= pm2fb_blank
,
1034 .fb_pan_display
= pm2fb_pan_display
,
1035 .fb_fillrect
= cfb_fillrect
,
1036 .fb_copyarea
= cfb_copyarea
,
1037 .fb_imageblit
= cfb_imageblit
,
1046 * Device initialisation
1048 * Initialise and allocate resource for PCI device.
1050 * @param pdev PCI device.
1051 * @param id PCI device ID.
1053 static int __devinit
pm2fb_probe(struct pci_dev
*pdev
,
1054 const struct pci_device_id
*id
)
1056 struct pm2fb_par
*default_par
;
1057 struct fb_info
*info
;
1058 int err
, err_retval
= -ENXIO
;
1060 err
= pci_enable_device(pdev
);
1062 printk(KERN_WARNING
"pm2fb: Can't enable pdev: %d\n", err
);
1066 info
= framebuffer_alloc(sizeof(struct pm2fb_par
), &pdev
->dev
);
1069 default_par
= info
->par
;
1071 switch (pdev
->device
) {
1072 case PCI_DEVICE_ID_TI_TVP4020
:
1073 strcpy(pm2fb_fix
.id
, "TVP4020");
1074 default_par
->type
= PM2_TYPE_PERMEDIA2
;
1076 case PCI_DEVICE_ID_3DLABS_PERMEDIA2
:
1077 strcpy(pm2fb_fix
.id
, "Permedia2");
1078 default_par
->type
= PM2_TYPE_PERMEDIA2
;
1080 case PCI_DEVICE_ID_3DLABS_PERMEDIA2V
:
1081 strcpy(pm2fb_fix
.id
, "Permedia2v");
1082 default_par
->type
= PM2_TYPE_PERMEDIA2V
;
1086 pm2fb_fix
.mmio_start
= pci_resource_start(pdev
, 0);
1087 pm2fb_fix
.mmio_len
= PM2_REGS_SIZE
;
1089 #if defined(__BIG_ENDIAN)
1091 * PM2 has a 64k register file, mapped twice in 128k. Lower
1092 * map is little-endian, upper map is big-endian.
1094 pm2fb_fix
.mmio_start
+= PM2_REGS_SIZE
;
1095 DPRINTK("Adjusting register base for big-endian.\n");
1097 DPRINTK("Register base at 0x%lx\n", pm2fb_fix
.mmio_start
);
1099 /* Registers - request region and map it. */
1100 if ( !request_mem_region(pm2fb_fix
.mmio_start
, pm2fb_fix
.mmio_len
,
1101 "pm2fb regbase") ) {
1102 printk(KERN_WARNING
"pm2fb: Can't reserve regbase.\n");
1103 goto err_exit_neither
;
1105 default_par
->v_regs
=
1106 ioremap_nocache(pm2fb_fix
.mmio_start
, pm2fb_fix
.mmio_len
);
1107 if ( !default_par
->v_regs
) {
1108 printk(KERN_WARNING
"pm2fb: Can't remap %s register area.\n",
1110 release_mem_region(pm2fb_fix
.mmio_start
, pm2fb_fix
.mmio_len
);
1111 goto err_exit_neither
;
1114 /* Stash away memory register info for use when we reset the board */
1115 default_par
->mem_control
= pm2_RD(default_par
, PM2R_MEM_CONTROL
);
1116 default_par
->boot_address
= pm2_RD(default_par
, PM2R_BOOT_ADDRESS
);
1117 default_par
->mem_config
= pm2_RD(default_par
, PM2R_MEM_CONFIG
);
1118 DPRINTK("MemControl 0x%x BootAddress 0x%x MemConfig 0x%x\n",
1119 default_par
->mem_control
, default_par
->boot_address
,
1120 default_par
->mem_config
);
1122 if(default_par
->mem_control
== 0 &&
1123 default_par
->boot_address
== 0x31 &&
1124 default_par
->mem_config
== 0x259fffff &&
1125 pdev
->subsystem_vendor
== 0x1048 &&
1126 pdev
->subsystem_device
== 0x0a31) {
1127 DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
1128 pdev
->subsystem_vendor
, pdev
->subsystem_device
);
1129 DPRINTK("We have not been initialized by VGA BIOS "
1130 "and are running on an Elsa Winner 2000 Office\n");
1131 DPRINTK("Initializing card timings manually...\n");
1132 default_par
->mem_control
=0;
1133 default_par
->boot_address
=0x20;
1134 default_par
->mem_config
=0xe6002021;
1135 default_par
->memclock
=100000;
1138 /* Now work out how big lfb is going to be. */
1139 switch(default_par
->mem_config
& PM2F_MEM_CONFIG_RAM_MASK
) {
1140 case PM2F_MEM_BANKS_1
:
1141 default_par
->fb_size
=0x200000;
1143 case PM2F_MEM_BANKS_2
:
1144 default_par
->fb_size
=0x400000;
1146 case PM2F_MEM_BANKS_3
:
1147 default_par
->fb_size
=0x600000;
1149 case PM2F_MEM_BANKS_4
:
1150 default_par
->fb_size
=0x800000;
1153 default_par
->memclock
= CVPPC_MEMCLOCK
;
1154 pm2fb_fix
.smem_start
= pci_resource_start(pdev
, 1);
1155 pm2fb_fix
.smem_len
= default_par
->fb_size
;
1157 /* Linear frame buffer - request region and map it. */
1158 if ( !request_mem_region(pm2fb_fix
.smem_start
, pm2fb_fix
.smem_len
,
1160 printk(KERN_WARNING
"pm2fb: Can't reserve smem.\n");
1163 info
->screen_base
= default_par
->v_fb
=
1164 ioremap_nocache(pm2fb_fix
.smem_start
, pm2fb_fix
.smem_len
);
1165 if ( !default_par
->v_fb
) {
1166 printk(KERN_WARNING
"pm2fb: Can't ioremap smem area.\n");
1167 release_mem_region(pm2fb_fix
.smem_start
, pm2fb_fix
.smem_len
);
1171 info
->fbops
= &pm2fb_ops
;
1172 info
->fix
= pm2fb_fix
;
1173 info
->pseudo_palette
= default_par
->palette
;
1174 info
->flags
= FBINFO_DEFAULT
|
1175 FBINFO_HWACCEL_YPAN
;
1178 mode
= "640x480@60";
1180 err
= fb_find_mode(&info
->var
, info
, mode
, NULL
, 0, NULL
, 8);
1181 if (!err
|| err
== 4)
1182 info
->var
= pm2fb_var
;
1184 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0)
1187 if (register_framebuffer(info
) < 0)
1190 printk(KERN_INFO
"fb%d: %s frame buffer device, memory = %dK.\n",
1191 info
->node
, info
->fix
.id
, default_par
->fb_size
/ 1024);
1196 pci_set_drvdata(pdev
, info
);
1201 fb_dealloc_cmap(&info
->cmap
);
1203 iounmap(info
->screen_base
);
1204 release_mem_region(pm2fb_fix
.smem_start
, pm2fb_fix
.smem_len
);
1206 iounmap(default_par
->v_regs
);
1207 release_mem_region(pm2fb_fix
.mmio_start
, pm2fb_fix
.mmio_len
);
1209 framebuffer_release(info
);
1216 * Release all device resources.
1218 * @param pdev PCI device to clean up.
1220 static void __devexit
pm2fb_remove(struct pci_dev
*pdev
)
1222 struct fb_info
* info
= pci_get_drvdata(pdev
);
1223 struct fb_fix_screeninfo
* fix
= &info
->fix
;
1224 struct pm2fb_par
*par
= info
->par
;
1226 unregister_framebuffer(info
);
1228 iounmap(info
->screen_base
);
1229 release_mem_region(fix
->smem_start
, fix
->smem_len
);
1230 iounmap(par
->v_regs
);
1231 release_mem_region(fix
->mmio_start
, fix
->mmio_len
);
1233 pci_set_drvdata(pdev
, NULL
);
1237 static struct pci_device_id pm2fb_id_table
[] = {
1238 { PCI_VENDOR_ID_TI
, PCI_DEVICE_ID_TI_TVP4020
,
1239 PCI_ANY_ID
, PCI_ANY_ID
, PCI_BASE_CLASS_DISPLAY
<< 16,
1241 { PCI_VENDOR_ID_3DLABS
, PCI_DEVICE_ID_3DLABS_PERMEDIA2
,
1242 PCI_ANY_ID
, PCI_ANY_ID
, PCI_BASE_CLASS_DISPLAY
<< 16,
1244 { PCI_VENDOR_ID_3DLABS
, PCI_DEVICE_ID_3DLABS_PERMEDIA2V
,
1245 PCI_ANY_ID
, PCI_ANY_ID
, PCI_BASE_CLASS_DISPLAY
<< 16,
1250 static struct pci_driver pm2fb_driver
= {
1252 .id_table
= pm2fb_id_table
,
1253 .probe
= pm2fb_probe
,
1254 .remove
= __devexit_p(pm2fb_remove
),
1257 MODULE_DEVICE_TABLE(pci
, pm2fb_id_table
);
1262 * Parse user speficied options.
1264 * This is, comma-separated options following `video=pm2fb:'.
1266 static int __init
pm2fb_setup(char *options
)
1270 if (!options
|| !*options
)
1273 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1276 if(!strcmp(this_opt
, "lowhsync")) {
1278 } else if(!strcmp(this_opt
, "lowvsync")) {
1289 static int __init
pm2fb_init(void)
1292 char *option
= NULL
;
1294 if (fb_get_options("pm2fb", &option
))
1296 pm2fb_setup(option
);
1299 return pci_register_driver(&pm2fb_driver
);
1302 module_init(pm2fb_init
);
1309 static void __exit
pm2fb_exit(void)
1311 pci_unregister_driver(&pm2fb_driver
);
1316 module_exit(pm2fb_exit
);
1318 module_param(mode
, charp
, 0);
1319 MODULE_PARM_DESC(mode
, "Preferred video mode e.g. '648x480-8@60'");
1320 module_param(lowhsync
, bool, 0);
1321 MODULE_PARM_DESC(lowhsync
, "Force horizontal sync low regardless of mode");
1322 module_param(lowvsync
, bool, 0);
1323 MODULE_PARM_DESC(lowvsync
, "Force vertical sync low regardless of mode");
1325 MODULE_AUTHOR("Jim Hague <jim.hague@acm.org>");
1326 MODULE_DESCRIPTION("Permedia2 framebuffer device driver");
1327 MODULE_LICENSE("GPL");