1 // SPDX-License-Identifier: GPL-2.0-only
6 * Author: Hannu Mallat <hmallat@cc.hut.fi>
8 * Copyright © 1999 Hannu Mallat
11 * Created : Thu Sep 23 18:17:43 1999, hmallat
12 * Last modified: Tue Nov 2 21:19:47 1999, hmallat
14 * I2C part copied from the i2c-voodoo3.c driver by:
15 * Frodo Looijaard <frodol@dds.nl>,
16 * Philip Edelbrock <phil@netroedge.com>,
17 * Ralph Metzler <rjkm@thp.uni-koeln.de>, and
18 * Mark D. Studebaker <mdsxyz123@yahoo.com>
20 * Lots of the information here comes from the Daryll Strauss' Banshee
21 * patches to the XF86 server, and the rest comes from the 3dfx
22 * Banshee specification. I'm very much indebted to Daryll for his
23 * work on the X server.
25 * Voodoo3 support was contributed Harold Oga. Lots of additions
26 * (proper acceleration, 24 bpp, hardware cursor) and bug fixes by Attila
27 * Kesmarki. Thanks guys!
29 * Voodoo1 and Voodoo2 support aren't relevant to this driver as they
30 * behave very differently from the Voodoo3/4/5. For anyone wanting to
31 * use frame buffer on the Voodoo1/2, see the sstfb driver (which is
32 * located at http://www.sourceforge.net/projects/sstfb).
34 * While I _am_ grateful to 3Dfx for releasing the specs for Banshee,
35 * I do wish the next version is a bit more complete. Without the XF86
36 * patches I couldn't have gotten even this far... for instance, the
37 * extensions to the VGA register set go completely unmentioned in the
38 * spec! Also, lots of references are made to the 'SST core', but no
39 * spec is publicly available, AFAIK.
41 * The structure of this driver comes pretty much from the Permedia
42 * driver by Ilario Nardinocchi, which in turn is based on skeletonfb.
45 * - multihead support (basically need to support an array of fb_infos)
46 * - support other architectures (PPC, Alpha); does the fact that the VGA
47 * core can be accessed only thru I/O (not memory mapped) complicate
52 * 0.1.4 (released 2002-05-28) ported over to new fbdev api by James Simmons
54 * 0.1.3 (released 1999-11-02) added Attila's panning support, code
55 * reorg, hwcursor address page size alignment
56 * (for mmapping both frame buffer and regs),
57 * and my changes to get rid of hardcoded
58 * VGA i/o register locations (uses PCI
59 * configuration info now)
60 * 0.1.2 (released 1999-10-19) added Attila Kesmarki's bug fixes and
62 * 0.1.1 (released 1999-10-07) added Voodoo3 support by Harold Oga.
63 * 0.1.0 (released 1999-10-06) initial version
67 #include <linux/module.h>
68 #include <linux/kernel.h>
69 #include <linux/errno.h>
70 #include <linux/string.h>
72 #include <linux/slab.h>
74 #include <linux/init.h>
75 #include <linux/pci.h>
78 #include <video/tdfx.h>
80 #define DPRINTK(a, b...) pr_debug("fb: %s: " a, __func__ , ## b)
82 #define BANSHEE_MAX_PIXCLOCK 270000
83 #define VOODOO3_MAX_PIXCLOCK 300000
84 #define VOODOO5_MAX_PIXCLOCK 350000
86 static const struct fb_fix_screeninfo tdfx_fix
= {
87 .type
= FB_TYPE_PACKED_PIXELS
,
88 .visual
= FB_VISUAL_PSEUDOCOLOR
,
91 .accel
= FB_ACCEL_3DFX_BANSHEE
94 static const struct fb_var_screeninfo tdfx_var
= {
95 /* "640x480, 8 bpp @ 60 Hz */
104 .activate
= FB_ACTIVATE_NOW
,
107 .accel_flags
= FB_ACCELF_TEXT
,
115 .vmode
= FB_VMODE_NONINTERLACED
119 * PCI driver prototypes
121 static int tdfxfb_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
);
122 static void tdfxfb_remove(struct pci_dev
*pdev
);
124 static const struct pci_device_id tdfxfb_id_table
[] = {
125 { PCI_VENDOR_ID_3DFX
, PCI_DEVICE_ID_3DFX_BANSHEE
,
126 PCI_ANY_ID
, PCI_ANY_ID
, PCI_BASE_CLASS_DISPLAY
<< 16,
128 { PCI_VENDOR_ID_3DFX
, PCI_DEVICE_ID_3DFX_VOODOO3
,
129 PCI_ANY_ID
, PCI_ANY_ID
, PCI_BASE_CLASS_DISPLAY
<< 16,
131 { PCI_VENDOR_ID_3DFX
, PCI_DEVICE_ID_3DFX_VOODOO5
,
132 PCI_ANY_ID
, PCI_ANY_ID
, PCI_BASE_CLASS_DISPLAY
<< 16,
137 static struct pci_driver tdfxfb_driver
= {
139 .id_table
= tdfxfb_id_table
,
140 .probe
= tdfxfb_probe
,
141 .remove
= tdfxfb_remove
,
144 MODULE_DEVICE_TABLE(pci
, tdfxfb_id_table
);
150 static int nowrap
= 1; /* not implemented (yet) */
151 static int hwcursor
= 1;
152 static char *mode_option
;
155 /* -------------------------------------------------------------------------
156 * Hardware-specific funcions
157 * ------------------------------------------------------------------------- */
159 static inline u8
vga_inb(struct tdfx_par
*par
, u32 reg
)
161 return inb(par
->iobase
+ reg
- 0x300);
164 static inline void vga_outb(struct tdfx_par
*par
, u32 reg
, u8 val
)
166 outb(val
, par
->iobase
+ reg
- 0x300);
169 static inline void gra_outb(struct tdfx_par
*par
, u32 idx
, u8 val
)
171 vga_outb(par
, GRA_I
, idx
);
173 vga_outb(par
, GRA_D
, val
);
177 static inline void seq_outb(struct tdfx_par
*par
, u32 idx
, u8 val
)
179 vga_outb(par
, SEQ_I
, idx
);
181 vga_outb(par
, SEQ_D
, val
);
185 static inline u8
seq_inb(struct tdfx_par
*par
, u32 idx
)
187 vga_outb(par
, SEQ_I
, idx
);
189 return vga_inb(par
, SEQ_D
);
192 static inline void crt_outb(struct tdfx_par
*par
, u32 idx
, u8 val
)
194 vga_outb(par
, CRT_I
, idx
);
196 vga_outb(par
, CRT_D
, val
);
200 static inline u8
crt_inb(struct tdfx_par
*par
, u32 idx
)
202 vga_outb(par
, CRT_I
, idx
);
204 return vga_inb(par
, CRT_D
);
207 static inline void att_outb(struct tdfx_par
*par
, u32 idx
, u8 val
)
211 tmp
= vga_inb(par
, IS1_R
);
212 vga_outb(par
, ATT_IW
, idx
);
213 vga_outb(par
, ATT_IW
, val
);
216 static inline void vga_disable_video(struct tdfx_par
*par
)
220 s
= seq_inb(par
, 0x01) | 0x20;
221 seq_outb(par
, 0x00, 0x01);
222 seq_outb(par
, 0x01, s
);
223 seq_outb(par
, 0x00, 0x03);
226 static inline void vga_enable_video(struct tdfx_par
*par
)
230 s
= seq_inb(par
, 0x01) & 0xdf;
231 seq_outb(par
, 0x00, 0x01);
232 seq_outb(par
, 0x01, s
);
233 seq_outb(par
, 0x00, 0x03);
236 static inline void vga_enable_palette(struct tdfx_par
*par
)
240 vga_outb(par
, ATT_IW
, 0x20);
243 static inline u32
tdfx_inl(struct tdfx_par
*par
, unsigned int reg
)
245 return readl(par
->regbase_virt
+ reg
);
248 static inline void tdfx_outl(struct tdfx_par
*par
, unsigned int reg
, u32 val
)
250 writel(val
, par
->regbase_virt
+ reg
);
253 static inline void banshee_make_room(struct tdfx_par
*par
, int size
)
255 /* Note: The Voodoo3's onboard FIFO has 32 slots. This loop
256 * won't quit if you ask for more. */
257 while ((tdfx_inl(par
, STATUS
) & 0x1f) < size
- 1)
261 static int banshee_wait_idle(struct fb_info
*info
)
263 struct tdfx_par
*par
= info
->par
;
266 banshee_make_room(par
, 1);
267 tdfx_outl(par
, COMMAND_3D
, COMMAND_3D_NOP
);
270 if ((tdfx_inl(par
, STATUS
) & STATUS_BUSY
) == 0)
278 * Set the color of a palette entry in 8bpp mode
280 static inline void do_setpalentry(struct tdfx_par
*par
, unsigned regno
, u32 c
)
282 banshee_make_room(par
, 2);
283 tdfx_outl(par
, DACADDR
, regno
);
284 /* read after write makes it working */
285 tdfx_inl(par
, DACADDR
);
286 tdfx_outl(par
, DACDATA
, c
);
289 static u32
do_calc_pll(int freq
, int *freq_out
)
291 int m
, n
, k
, best_m
, best_n
, best_k
, best_error
;
295 best_n
= best_m
= best_k
= 0;
297 for (k
= 3; k
>= 0; k
--) {
298 for (m
= 63; m
>= 0; m
--) {
300 * Estimate value of n that produces target frequency
301 * with current m and k
303 int n_estimated
= ((freq
* (m
+ 2) << k
) / fref
) - 2;
305 /* Search neighborhood of estimated n */
306 for (n
= max(0, n_estimated
);
307 n
<= min(255, n_estimated
+ 1);
310 * Calculate PLL freqency with current m, k and
313 int f
= (fref
* (n
+ 2) / (m
+ 2)) >> k
;
314 int error
= abs(f
- freq
);
317 * If this is the closest we've come to the
318 * target frequency then remember n, m and k
320 if (error
< best_error
) {
333 *freq_out
= (fref
* (n
+ 2) / (m
+ 2)) >> k
;
335 return (n
<< 8) | (m
<< 2) | k
;
338 static void do_write_regs(struct fb_info
*info
, struct banshee_reg
*reg
)
340 struct tdfx_par
*par
= info
->par
;
343 banshee_wait_idle(info
);
345 tdfx_outl(par
, MISCINIT1
, tdfx_inl(par
, MISCINIT1
) | 0x01);
347 crt_outb(par
, 0x11, crt_inb(par
, 0x11) & 0x7f); /* CRT unprotect */
349 banshee_make_room(par
, 3);
350 tdfx_outl(par
, VGAINIT1
, reg
->vgainit1
& 0x001FFFFF);
351 tdfx_outl(par
, VIDPROCCFG
, reg
->vidcfg
& ~0x00000001);
353 tdfx_outl(par
, PLLCTRL1
, reg
->mempll
);
354 tdfx_outl(par
, PLLCTRL2
, reg
->gfxpll
);
356 tdfx_outl(par
, PLLCTRL0
, reg
->vidpll
);
358 vga_outb(par
, MISC_W
, reg
->misc
[0x00] | 0x01);
360 for (i
= 0; i
< 5; i
++)
361 seq_outb(par
, i
, reg
->seq
[i
]);
363 for (i
= 0; i
< 25; i
++)
364 crt_outb(par
, i
, reg
->crt
[i
]);
366 for (i
= 0; i
< 9; i
++)
367 gra_outb(par
, i
, reg
->gra
[i
]);
369 for (i
= 0; i
< 21; i
++)
370 att_outb(par
, i
, reg
->att
[i
]);
372 crt_outb(par
, 0x1a, reg
->ext
[0]);
373 crt_outb(par
, 0x1b, reg
->ext
[1]);
375 vga_enable_palette(par
);
376 vga_enable_video(par
);
378 banshee_make_room(par
, 9);
379 tdfx_outl(par
, VGAINIT0
, reg
->vgainit0
);
380 tdfx_outl(par
, DACMODE
, reg
->dacmode
);
381 tdfx_outl(par
, VIDDESKSTRIDE
, reg
->stride
);
382 tdfx_outl(par
, HWCURPATADDR
, reg
->curspataddr
);
384 tdfx_outl(par
, VIDSCREENSIZE
, reg
->screensize
);
385 tdfx_outl(par
, VIDDESKSTART
, reg
->startaddr
);
386 tdfx_outl(par
, VIDPROCCFG
, reg
->vidcfg
);
387 tdfx_outl(par
, VGAINIT1
, reg
->vgainit1
);
388 tdfx_outl(par
, MISCINIT0
, reg
->miscinit0
);
390 banshee_make_room(par
, 8);
391 tdfx_outl(par
, SRCBASE
, reg
->startaddr
);
392 tdfx_outl(par
, DSTBASE
, reg
->startaddr
);
393 tdfx_outl(par
, COMMANDEXTRA_2D
, 0);
394 tdfx_outl(par
, CLIP0MIN
, 0);
395 tdfx_outl(par
, CLIP0MAX
, 0x0fff0fff);
396 tdfx_outl(par
, CLIP1MIN
, 0);
397 tdfx_outl(par
, CLIP1MAX
, 0x0fff0fff);
398 tdfx_outl(par
, SRCXY
, 0);
400 banshee_wait_idle(info
);
403 static unsigned long do_lfb_size(struct tdfx_par
*par
, unsigned short dev_id
)
405 u32 draminit0
= tdfx_inl(par
, DRAMINIT0
);
406 u32 draminit1
= tdfx_inl(par
, DRAMINIT1
);
408 int num_chips
= (draminit0
& DRAMINIT0_SGRAM_NUM
) ? 8 : 4;
409 int chip_size
; /* in MB */
410 int has_sgram
= draminit1
& DRAMINIT1_MEM_SDRAM
;
412 if (dev_id
< PCI_DEVICE_ID_3DFX_VOODOO5
) {
413 /* Banshee/Voodoo3 */
415 if (has_sgram
&& !(draminit0
& DRAMINIT0_SGRAM_TYPE
))
420 chip_size
= draminit0
& DRAMINIT0_SGRAM_TYPE_MASK
;
421 chip_size
= 1 << (chip_size
>> DRAMINIT0_SGRAM_TYPE_SHIFT
);
424 /* disable block writes for SDRAM */
425 miscinit1
= tdfx_inl(par
, MISCINIT1
);
426 miscinit1
|= has_sgram
? 0 : MISCINIT1_2DBLOCK_DIS
;
427 miscinit1
|= MISCINIT1_CLUT_INV
;
429 banshee_make_room(par
, 1);
430 tdfx_outl(par
, MISCINIT1
, miscinit1
);
431 return num_chips
* chip_size
* 1024l * 1024;
434 /* ------------------------------------------------------------------------- */
436 static int tdfxfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
438 struct tdfx_par
*par
= info
->par
;
441 if (var
->bits_per_pixel
!= 8 && var
->bits_per_pixel
!= 16 &&
442 var
->bits_per_pixel
!= 24 && var
->bits_per_pixel
!= 32) {
443 DPRINTK("depth not supported: %u\n", var
->bits_per_pixel
);
447 if (var
->xres
!= var
->xres_virtual
)
448 var
->xres_virtual
= var
->xres
;
450 if (var
->yres
> var
->yres_virtual
)
451 var
->yres_virtual
= var
->yres
;
454 DPRINTK("xoffset not supported\n");
460 * Banshee doesn't support interlace, but Voodoo4/5 and probably
462 * no direct information about device id now?
463 * use max_pixclock for this...
465 if (((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) &&
466 (par
->max_pixclock
< VOODOO3_MAX_PIXCLOCK
)) {
467 DPRINTK("interlace not supported\n");
471 if (info
->monspecs
.hfmax
&& info
->monspecs
.vfmax
&&
472 info
->monspecs
.dclkmax
&& fb_validate_mode(var
, info
) < 0) {
473 DPRINTK("mode outside monitor's specs\n");
477 var
->xres
= (var
->xres
+ 15) & ~15; /* could sometimes be 8 */
478 lpitch
= var
->xres
* ((var
->bits_per_pixel
+ 7) >> 3);
480 if (var
->xres
< 320 || var
->xres
> 2048) {
481 DPRINTK("width not supported: %u\n", var
->xres
);
485 if (var
->yres
< 200 || var
->yres
> 2048) {
486 DPRINTK("height not supported: %u\n", var
->yres
);
490 if (lpitch
* var
->yres_virtual
> info
->fix
.smem_len
) {
491 var
->yres_virtual
= info
->fix
.smem_len
/ lpitch
;
492 if (var
->yres_virtual
< var
->yres
) {
493 DPRINTK("no memory for screen (%ux%ux%u)\n",
494 var
->xres
, var
->yres_virtual
,
495 var
->bits_per_pixel
);
500 if (PICOS2KHZ(var
->pixclock
) > par
->max_pixclock
) {
501 DPRINTK("pixclock too high (%ldKHz)\n",
502 PICOS2KHZ(var
->pixclock
));
506 var
->transp
.offset
= 0;
507 var
->transp
.length
= 0;
508 switch (var
->bits_per_pixel
) {
512 var
->green
= var
->red
;
513 var
->blue
= var
->red
;
516 var
->red
.offset
= 11;
518 var
->green
.offset
= 5;
519 var
->green
.length
= 6;
520 var
->blue
.offset
= 0;
521 var
->blue
.length
= 5;
524 var
->transp
.offset
= 24;
525 var
->transp
.length
= 8;
528 var
->red
.offset
= 16;
529 var
->green
.offset
= 8;
530 var
->blue
.offset
= 0;
531 var
->red
.length
= var
->green
.length
= var
->blue
.length
= 8;
537 var
->accel_flags
= FB_ACCELF_TEXT
;
539 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
540 var
->xres
, var
->yres
, var
->bits_per_pixel
);
544 static int tdfxfb_set_par(struct fb_info
*info
)
546 struct tdfx_par
*par
= info
->par
;
547 u32 hdispend
= info
->var
.xres
;
548 u32 hsyncsta
= hdispend
+ info
->var
.right_margin
;
549 u32 hsyncend
= hsyncsta
+ info
->var
.hsync_len
;
550 u32 htotal
= hsyncend
+ info
->var
.left_margin
;
551 u32 hd
, hs
, he
, ht
, hbs
, hbe
;
552 u32 vd
, vs
, ve
, vt
, vbs
, vbe
;
553 struct banshee_reg reg
;
556 u32 cpp
= (info
->var
.bits_per_pixel
+ 7) >> 3;
558 memset(®
, 0, sizeof(reg
));
560 reg
.vidcfg
= VIDCFG_VIDPROC_ENABLE
| VIDCFG_DESK_ENABLE
|
562 ((cpp
- 1) << VIDCFG_PIXFMT_SHIFT
) |
563 (cpp
!= 1 ? VIDCFG_CLUT_BYPASS
: 0);
566 freq
= PICOS2KHZ(info
->var
.pixclock
);
568 reg
.vidcfg
&= ~VIDCFG_2X
;
570 if (freq
> par
->max_pixclock
/ 2) {
571 freq
= freq
> par
->max_pixclock
? par
->max_pixclock
: freq
;
572 reg
.dacmode
|= DACMODE_2X
;
573 reg
.vidcfg
|= VIDCFG_2X
;
580 wd
= (hdispend
>> 3) - 1;
582 hs
= (hsyncsta
>> 3) - 1;
583 he
= (hsyncend
>> 3) - 1;
584 ht
= (htotal
>> 3) - 1;
588 if ((info
->var
.vmode
& FB_VMODE_MASK
) == FB_VMODE_DOUBLE
) {
589 vd
= (info
->var
.yres
<< 1) - 1;
590 vs
= vd
+ (info
->var
.lower_margin
<< 1);
591 ve
= vs
+ (info
->var
.vsync_len
<< 1);
592 vt
= ve
+ (info
->var
.upper_margin
<< 1) - 1;
593 reg
.screensize
= info
->var
.xres
| (info
->var
.yres
<< 13);
594 reg
.vidcfg
|= VIDCFG_HALF_MODE
;
595 reg
.crt
[0x09] = 0x80;
597 vd
= info
->var
.yres
- 1;
598 vs
= vd
+ info
->var
.lower_margin
;
599 ve
= vs
+ info
->var
.vsync_len
;
600 vt
= ve
+ info
->var
.upper_margin
- 1;
601 reg
.screensize
= info
->var
.xres
| (info
->var
.yres
<< 12);
602 reg
.vidcfg
&= ~VIDCFG_HALF_MODE
;
607 /* this is all pretty standard VGA register stuffing */
608 reg
.misc
[0x00] = 0x0f |
609 (info
->var
.xres
< 400 ? 0xa0 :
610 info
->var
.xres
< 480 ? 0x60 :
611 info
->var
.xres
< 768 ? 0xe0 : 0x20);
613 reg
.gra
[0x05] = 0x40;
614 reg
.gra
[0x06] = 0x05;
615 reg
.gra
[0x07] = 0x0f;
616 reg
.gra
[0x08] = 0xff;
618 reg
.att
[0x00] = 0x00;
619 reg
.att
[0x01] = 0x01;
620 reg
.att
[0x02] = 0x02;
621 reg
.att
[0x03] = 0x03;
622 reg
.att
[0x04] = 0x04;
623 reg
.att
[0x05] = 0x05;
624 reg
.att
[0x06] = 0x06;
625 reg
.att
[0x07] = 0x07;
626 reg
.att
[0x08] = 0x08;
627 reg
.att
[0x09] = 0x09;
628 reg
.att
[0x0a] = 0x0a;
629 reg
.att
[0x0b] = 0x0b;
630 reg
.att
[0x0c] = 0x0c;
631 reg
.att
[0x0d] = 0x0d;
632 reg
.att
[0x0e] = 0x0e;
633 reg
.att
[0x0f] = 0x0f;
634 reg
.att
[0x10] = 0x41;
635 reg
.att
[0x12] = 0x0f;
637 reg
.seq
[0x00] = 0x03;
638 reg
.seq
[0x01] = 0x01; /* fixme: clkdiv2? */
639 reg
.seq
[0x02] = 0x0f;
640 reg
.seq
[0x03] = 0x00;
641 reg
.seq
[0x04] = 0x0e;
643 reg
.crt
[0x00] = ht
- 4;
646 reg
.crt
[0x03] = 0x80 | (hbe
& 0x1f);
648 reg
.crt
[0x05] = ((hbe
& 0x20) << 2) | (he
& 0x1f);
650 reg
.crt
[0x07] = ((vs
& 0x200) >> 2) |
651 ((vd
& 0x200) >> 3) |
652 ((vt
& 0x200) >> 4) | 0x10 |
653 ((vbs
& 0x100) >> 5) |
654 ((vs
& 0x100) >> 6) |
655 ((vd
& 0x100) >> 7) |
657 reg
.crt
[0x09] |= 0x40 | ((vbs
& 0x200) >> 4);
659 reg
.crt
[0x11] = (ve
& 0x0f) | 0x20;
663 reg
.crt
[0x16] = vbe
+ 1;
664 reg
.crt
[0x17] = 0xc3;
665 reg
.crt
[0x18] = 0xff;
667 /* Banshee's nonvga stuff */
668 reg
.ext
[0x00] = (((ht
& 0x100) >> 8) |
669 ((hd
& 0x100) >> 6) |
670 ((hbs
& 0x100) >> 4) |
671 ((hbe
& 0x40) >> 1) |
672 ((hs
& 0x100) >> 2) |
674 reg
.ext
[0x01] = (((vt
& 0x400) >> 10) |
675 ((vd
& 0x400) >> 8) |
676 ((vbs
& 0x400) >> 6) |
677 ((vbe
& 0x400) >> 4));
679 reg
.vgainit0
= VGAINIT0_8BIT_DAC
|
680 VGAINIT0_EXT_ENABLE
|
681 VGAINIT0_WAKEUP_3C3
|
682 VGAINIT0_ALT_READBACK
|
683 VGAINIT0_EXTSHIFTOUT
;
684 reg
.vgainit1
= tdfx_inl(par
, VGAINIT1
) & 0x1fffff;
687 reg
.curspataddr
= info
->fix
.smem_len
;
692 reg
.cursc1
= 0xffffff;
694 reg
.stride
= info
->var
.xres
* cpp
;
695 reg
.startaddr
= info
->var
.yoffset
* reg
.stride
696 + info
->var
.xoffset
* cpp
;
698 reg
.vidpll
= do_calc_pll(freq
, &fout
);
700 reg
.mempll
= do_calc_pll(..., &fout
);
701 reg
.gfxpll
= do_calc_pll(..., &fout
);
704 if ((info
->var
.vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
)
705 reg
.vidcfg
|= VIDCFG_INTERLACE
;
706 reg
.miscinit0
= tdfx_inl(par
, MISCINIT0
);
708 #if defined(__BIG_ENDIAN)
709 switch (info
->var
.bits_per_pixel
) {
712 reg
.miscinit0
&= ~(1 << 30);
713 reg
.miscinit0
&= ~(1 << 31);
716 reg
.miscinit0
|= (1 << 30);
717 reg
.miscinit0
|= (1 << 31);
720 reg
.miscinit0
|= (1 << 30);
721 reg
.miscinit0
&= ~(1 << 31);
725 do_write_regs(info
, ®
);
727 /* Now change fb_fix_screeninfo according to changes in par */
728 info
->fix
.line_length
= reg
.stride
;
729 info
->fix
.visual
= (info
->var
.bits_per_pixel
== 8)
730 ? FB_VISUAL_PSEUDOCOLOR
731 : FB_VISUAL_TRUECOLOR
;
732 DPRINTK("Graphics mode is now set at %dx%d depth %d\n",
733 info
->var
.xres
, info
->var
.yres
, info
->var
.bits_per_pixel
);
737 /* A handy macro shamelessly pinched from matroxfb */
738 #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16)
740 static int tdfxfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
741 unsigned blue
, unsigned transp
,
742 struct fb_info
*info
)
744 struct tdfx_par
*par
= info
->par
;
747 if (regno
>= info
->cmap
.len
|| regno
> 255)
750 /* grayscale works only partially under directcolor */
751 if (info
->var
.grayscale
) {
752 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
753 blue
= (red
* 77 + green
* 151 + blue
* 28) >> 8;
758 switch (info
->fix
.visual
) {
759 case FB_VISUAL_PSEUDOCOLOR
:
760 rgbcol
= (((u32
)red
& 0xff00) << 8) |
761 (((u32
)green
& 0xff00) << 0) |
762 (((u32
)blue
& 0xff00) >> 8);
763 do_setpalentry(par
, regno
, rgbcol
);
765 /* Truecolor has no hardware color palettes. */
766 case FB_VISUAL_TRUECOLOR
:
768 rgbcol
= (CNVT_TOHW(red
, info
->var
.red
.length
) <<
769 info
->var
.red
.offset
) |
770 (CNVT_TOHW(green
, info
->var
.green
.length
) <<
771 info
->var
.green
.offset
) |
772 (CNVT_TOHW(blue
, info
->var
.blue
.length
) <<
773 info
->var
.blue
.offset
) |
774 (CNVT_TOHW(transp
, info
->var
.transp
.length
) <<
775 info
->var
.transp
.offset
);
776 par
->palette
[regno
] = rgbcol
;
781 DPRINTK("bad depth %u\n", info
->var
.bits_per_pixel
);
788 /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */
789 static int tdfxfb_blank(int blank
, struct fb_info
*info
)
791 struct tdfx_par
*par
= info
->par
;
793 u32 dacmode
= tdfx_inl(par
, DACMODE
);
795 dacmode
&= ~(BIT(1) | BIT(3));
798 case FB_BLANK_UNBLANK
: /* Screen: On; HSync: On, VSync: On */
801 case FB_BLANK_NORMAL
: /* Screen: Off; HSync: On, VSync: On */
803 case FB_BLANK_VSYNC_SUSPEND
: /* Screen: Off; HSync: On, VSync: Off */
806 case FB_BLANK_HSYNC_SUSPEND
: /* Screen: Off; HSync: Off, VSync: On */
809 case FB_BLANK_POWERDOWN
: /* Screen: Off; HSync: Off, VSync: Off */
810 dacmode
|= BIT(1) | BIT(3);
814 banshee_make_room(par
, 1);
815 tdfx_outl(par
, DACMODE
, dacmode
);
817 vga_disable_video(par
);
819 vga_enable_video(par
);
824 * Set the starting position of the visible screen to var->yoffset
826 static int tdfxfb_pan_display(struct fb_var_screeninfo
*var
,
827 struct fb_info
*info
)
829 struct tdfx_par
*par
= info
->par
;
830 u32 addr
= var
->yoffset
* info
->fix
.line_length
;
832 if (nopan
|| var
->xoffset
)
835 banshee_make_room(par
, 1);
836 tdfx_outl(par
, VIDDESKSTART
, addr
);
841 #ifdef CONFIG_FB_3DFX_ACCEL
843 * FillRect 2D command (solidfill or invert (via ROP_XOR))
845 static void tdfxfb_fillrect(struct fb_info
*info
,
846 const struct fb_fillrect
*rect
)
848 struct tdfx_par
*par
= info
->par
;
849 u32 bpp
= info
->var
.bits_per_pixel
;
850 u32 stride
= info
->fix
.line_length
;
851 u32 fmt
= stride
| ((bpp
+ ((bpp
== 8) ? 0 : 8)) << 13);
857 if (rect
->rop
== ROP_COPY
)
858 tdfx_rop
= TDFX_ROP_COPY
;
860 tdfx_rop
= TDFX_ROP_XOR
;
862 /* assume always rect->height < 4096 */
863 if (dy
+ rect
->height
> 4095) {
864 dstbase
= stride
* dy
;
867 /* assume always rect->width < 4096 */
868 if (dx
+ rect
->width
> 4095) {
869 dstbase
+= dx
* bpp
>> 3;
872 banshee_make_room(par
, 6);
873 tdfx_outl(par
, DSTFORMAT
, fmt
);
874 if (info
->fix
.visual
== FB_VISUAL_PSEUDOCOLOR
) {
875 tdfx_outl(par
, COLORFORE
, rect
->color
);
876 } else { /* FB_VISUAL_TRUECOLOR */
877 tdfx_outl(par
, COLORFORE
, par
->palette
[rect
->color
]);
879 tdfx_outl(par
, COMMAND_2D
, COMMAND_2D_FILLRECT
| (tdfx_rop
<< 24));
880 tdfx_outl(par
, DSTBASE
, dstbase
);
881 tdfx_outl(par
, DSTSIZE
, rect
->width
| (rect
->height
<< 16));
882 tdfx_outl(par
, LAUNCH_2D
, dx
| (dy
<< 16));
886 * Screen-to-Screen BitBlt 2D command (for the bmove fb op.)
888 static void tdfxfb_copyarea(struct fb_info
*info
,
889 const struct fb_copyarea
*area
)
891 struct tdfx_par
*par
= info
->par
;
892 u32 sx
= area
->sx
, sy
= area
->sy
, dx
= area
->dx
, dy
= area
->dy
;
893 u32 bpp
= info
->var
.bits_per_pixel
;
894 u32 stride
= info
->fix
.line_length
;
895 u32 blitcmd
= COMMAND_2D_S2S_BITBLT
| (TDFX_ROP_COPY
<< 24);
896 u32 fmt
= stride
| ((bpp
+ ((bpp
== 8) ? 0 : 8)) << 13);
900 /* assume always area->height < 4096 */
901 if (sy
+ area
->height
> 4095) {
902 srcbase
= stride
* sy
;
905 /* assume always area->width < 4096 */
906 if (sx
+ area
->width
> 4095) {
907 srcbase
+= sx
* bpp
>> 3;
910 /* assume always area->height < 4096 */
911 if (dy
+ area
->height
> 4095) {
912 dstbase
= stride
* dy
;
915 /* assume always area->width < 4096 */
916 if (dx
+ area
->width
> 4095) {
917 dstbase
+= dx
* bpp
>> 3;
921 if (area
->sx
<= area
->dx
) {
924 sx
+= area
->width
- 1;
925 dx
+= area
->width
- 1;
927 if (area
->sy
<= area
->dy
) {
930 sy
+= area
->height
- 1;
931 dy
+= area
->height
- 1;
934 banshee_make_room(par
, 8);
936 tdfx_outl(par
, SRCFORMAT
, fmt
);
937 tdfx_outl(par
, DSTFORMAT
, fmt
);
938 tdfx_outl(par
, COMMAND_2D
, blitcmd
);
939 tdfx_outl(par
, DSTSIZE
, area
->width
| (area
->height
<< 16));
940 tdfx_outl(par
, DSTXY
, dx
| (dy
<< 16));
941 tdfx_outl(par
, SRCBASE
, srcbase
);
942 tdfx_outl(par
, DSTBASE
, dstbase
);
943 tdfx_outl(par
, LAUNCH_2D
, sx
| (sy
<< 16));
946 static void tdfxfb_imageblit(struct fb_info
*info
, const struct fb_image
*image
)
948 struct tdfx_par
*par
= info
->par
;
949 int size
= image
->height
* ((image
->width
* image
->depth
+ 7) >> 3);
951 int i
, stride
= info
->fix
.line_length
;
952 u32 bpp
= info
->var
.bits_per_pixel
;
953 u32 dstfmt
= stride
| ((bpp
+ ((bpp
== 8) ? 0 : 8)) << 13);
954 u8
*chardata
= (u8
*) image
->data
;
960 if (image
->depth
!= 1) {
962 banshee_make_room(par
, 6 + ((size
+ 3) >> 2));
963 srcfmt
= stride
| ((bpp
+ ((bpp
== 8) ? 0 : 8)) << 13) |
966 cfb_imageblit(info
, image
);
970 banshee_make_room(par
, 9);
971 switch (info
->fix
.visual
) {
972 case FB_VISUAL_PSEUDOCOLOR
:
973 tdfx_outl(par
, COLORFORE
, image
->fg_color
);
974 tdfx_outl(par
, COLORBACK
, image
->bg_color
);
976 case FB_VISUAL_TRUECOLOR
:
978 tdfx_outl(par
, COLORFORE
,
979 par
->palette
[image
->fg_color
]);
980 tdfx_outl(par
, COLORBACK
,
981 par
->palette
[image
->bg_color
]);
984 srcfmt
= 0x400000 | BIT(20);
988 /* assume always image->height < 4096 */
989 if (dy
+ image
->height
> 4095) {
990 dstbase
= stride
* dy
;
993 /* assume always image->width < 4096 */
994 if (dx
+ image
->width
> 4095) {
995 dstbase
+= dx
* bpp
>> 3;
999 tdfx_outl(par
, DSTBASE
, dstbase
);
1000 tdfx_outl(par
, SRCXY
, 0);
1001 tdfx_outl(par
, DSTXY
, dx
| (dy
<< 16));
1002 tdfx_outl(par
, COMMAND_2D
,
1003 COMMAND_2D_H2S_BITBLT
| (TDFX_ROP_COPY
<< 24));
1004 tdfx_outl(par
, SRCFORMAT
, srcfmt
);
1005 tdfx_outl(par
, DSTFORMAT
, dstfmt
);
1006 tdfx_outl(par
, DSTSIZE
, image
->width
| (image
->height
<< 16));
1008 /* A count of how many free FIFO entries we've requested.
1009 * When this goes negative, we need to request more. */
1012 /* Send four bytes at a time of data */
1013 for (i
= (size
>> 2); i
> 0; i
--) {
1014 if (--fifo_free
< 0) {
1016 banshee_make_room(par
, fifo_free
);
1018 tdfx_outl(par
, LAUNCH_2D
, *(u32
*)chardata
);
1022 /* Send the leftovers now */
1023 banshee_make_room(par
, 3);
1028 tdfx_outl(par
, LAUNCH_2D
, *chardata
);
1031 tdfx_outl(par
, LAUNCH_2D
, *(u16
*)chardata
);
1034 tdfx_outl(par
, LAUNCH_2D
,
1035 *(u16
*)chardata
| (chardata
[3] << 24));
1039 #endif /* CONFIG_FB_3DFX_ACCEL */
1041 static int tdfxfb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
1043 struct tdfx_par
*par
= info
->par
;
1047 return -EINVAL
; /* just to force soft_cursor() call */
1049 /* Too large of a cursor or wrong bpp :-( */
1050 if (cursor
->image
.width
> 64 ||
1051 cursor
->image
.height
> 64 ||
1052 cursor
->image
.depth
> 1)
1055 vidcfg
= tdfx_inl(par
, VIDPROCCFG
);
1057 tdfx_outl(par
, VIDPROCCFG
, vidcfg
| VIDCFG_HWCURSOR_ENABLE
);
1059 tdfx_outl(par
, VIDPROCCFG
, vidcfg
& ~VIDCFG_HWCURSOR_ENABLE
);
1062 * If the cursor is not be changed this means either we want the
1063 * current cursor state (if enable is set) or we want to query what
1064 * we can do with the cursor (if enable is not set)
1069 /* fix cursor color - XFree86 forgets to restore it properly */
1070 if (cursor
->set
& FB_CUR_SETCMAP
) {
1071 struct fb_cmap cmap
= info
->cmap
;
1072 u32 bg_idx
= cursor
->image
.bg_color
;
1073 u32 fg_idx
= cursor
->image
.fg_color
;
1074 unsigned long bg_color
, fg_color
;
1076 fg_color
= (((u32
)cmap
.red
[fg_idx
] & 0xff00) << 8) |
1077 (((u32
)cmap
.green
[fg_idx
] & 0xff00) << 0) |
1078 (((u32
)cmap
.blue
[fg_idx
] & 0xff00) >> 8);
1079 bg_color
= (((u32
)cmap
.red
[bg_idx
] & 0xff00) << 8) |
1080 (((u32
)cmap
.green
[bg_idx
] & 0xff00) << 0) |
1081 (((u32
)cmap
.blue
[bg_idx
] & 0xff00) >> 8);
1082 banshee_make_room(par
, 2);
1083 tdfx_outl(par
, HWCURC0
, bg_color
);
1084 tdfx_outl(par
, HWCURC1
, fg_color
);
1087 if (cursor
->set
& FB_CUR_SETPOS
) {
1088 int x
= cursor
->image
.dx
;
1089 int y
= cursor
->image
.dy
- info
->var
.yoffset
;
1093 banshee_make_room(par
, 1);
1094 tdfx_outl(par
, HWCURLOC
, (y
<< 16) + x
);
1096 if (cursor
->set
& (FB_CUR_SETIMAGE
| FB_CUR_SETSHAPE
)) {
1098 * Voodoo 3 and above cards use 2 monochrome cursor patterns.
1099 * The reason is so the card can fetch 8 words at a time
1100 * and are stored on chip for use for the next 8 scanlines.
1101 * This reduces the number of times for access to draw the
1102 * cursor for each screen refresh.
1103 * Each pattern is a bitmap of 64 bit wide and 64 bit high
1104 * (total of 8192 bits or 1024 bytes). The two patterns are
1105 * stored in such a way that pattern 0 always resides in the
1106 * lower half (least significant 64 bits) of a 128 bit word
1107 * and pattern 1 the upper half. If you examine the data of
1108 * the cursor image the graphics card uses then from the
1109 * beginning you see line one of pattern 0, line one of
1110 * pattern 1, line two of pattern 0, line two of pattern 1,
1111 * etc etc. The linear stride for the cursor is always 16 bytes
1112 * (128 bits) which is the maximum cursor width times two for
1113 * the two monochrome patterns.
1115 u8 __iomem
*cursorbase
= info
->screen_base
+ info
->fix
.smem_len
;
1116 u8
*bitmap
= (u8
*)cursor
->image
.data
;
1117 u8
*mask
= (u8
*)cursor
->mask
;
1120 fb_memset(cursorbase
, 0, 1024);
1122 for (i
= 0; i
< cursor
->image
.height
; i
++) {
1124 int j
= (cursor
->image
.width
+ 7) >> 3;
1126 for (; j
> 0; j
--) {
1127 u8 data
= *mask
^ *bitmap
;
1128 if (cursor
->rop
== ROP_COPY
)
1129 data
= *mask
& *bitmap
;
1130 /* Pattern 0. Copy the cursor mask to it */
1131 fb_writeb(*mask
, cursorbase
+ h
);
1133 /* Pattern 1. Copy the cursor bitmap to it */
1134 fb_writeb(data
, cursorbase
+ h
+ 8);
1144 static const struct fb_ops tdfxfb_ops
= {
1145 .owner
= THIS_MODULE
,
1146 .fb_check_var
= tdfxfb_check_var
,
1147 .fb_set_par
= tdfxfb_set_par
,
1148 .fb_setcolreg
= tdfxfb_setcolreg
,
1149 .fb_blank
= tdfxfb_blank
,
1150 .fb_pan_display
= tdfxfb_pan_display
,
1151 .fb_sync
= banshee_wait_idle
,
1152 .fb_cursor
= tdfxfb_cursor
,
1153 #ifdef CONFIG_FB_3DFX_ACCEL
1154 .fb_fillrect
= tdfxfb_fillrect
,
1155 .fb_copyarea
= tdfxfb_copyarea
,
1156 .fb_imageblit
= tdfxfb_imageblit
,
1158 .fb_fillrect
= cfb_fillrect
,
1159 .fb_copyarea
= cfb_copyarea
,
1160 .fb_imageblit
= cfb_imageblit
,
1164 #ifdef CONFIG_FB_3DFX_I2C
1165 /* The voo GPIO registers don't have individual masks for each bit
1166 so we always have to read before writing. */
1168 static void tdfxfb_i2c_setscl(void *data
, int val
)
1170 struct tdfxfb_i2c_chan
*chan
= data
;
1171 struct tdfx_par
*par
= chan
->par
;
1174 r
= tdfx_inl(par
, VIDSERPARPORT
);
1179 tdfx_outl(par
, VIDSERPARPORT
, r
);
1180 tdfx_inl(par
, VIDSERPARPORT
); /* flush posted write */
1183 static void tdfxfb_i2c_setsda(void *data
, int val
)
1185 struct tdfxfb_i2c_chan
*chan
= data
;
1186 struct tdfx_par
*par
= chan
->par
;
1189 r
= tdfx_inl(par
, VIDSERPARPORT
);
1194 tdfx_outl(par
, VIDSERPARPORT
, r
);
1195 tdfx_inl(par
, VIDSERPARPORT
); /* flush posted write */
1198 /* The GPIO pins are open drain, so the pins always remain outputs.
1199 We rely on the i2c-algo-bit routines to set the pins high before
1200 reading the input from other chips. */
1202 static int tdfxfb_i2c_getscl(void *data
)
1204 struct tdfxfb_i2c_chan
*chan
= data
;
1205 struct tdfx_par
*par
= chan
->par
;
1207 return (0 != (tdfx_inl(par
, VIDSERPARPORT
) & I2C_SCL_IN
));
1210 static int tdfxfb_i2c_getsda(void *data
)
1212 struct tdfxfb_i2c_chan
*chan
= data
;
1213 struct tdfx_par
*par
= chan
->par
;
1215 return (0 != (tdfx_inl(par
, VIDSERPARPORT
) & I2C_SDA_IN
));
1218 static void tdfxfb_ddc_setscl(void *data
, int val
)
1220 struct tdfxfb_i2c_chan
*chan
= data
;
1221 struct tdfx_par
*par
= chan
->par
;
1224 r
= tdfx_inl(par
, VIDSERPARPORT
);
1229 tdfx_outl(par
, VIDSERPARPORT
, r
);
1230 tdfx_inl(par
, VIDSERPARPORT
); /* flush posted write */
1233 static void tdfxfb_ddc_setsda(void *data
, int val
)
1235 struct tdfxfb_i2c_chan
*chan
= data
;
1236 struct tdfx_par
*par
= chan
->par
;
1239 r
= tdfx_inl(par
, VIDSERPARPORT
);
1244 tdfx_outl(par
, VIDSERPARPORT
, r
);
1245 tdfx_inl(par
, VIDSERPARPORT
); /* flush posted write */
1248 static int tdfxfb_ddc_getscl(void *data
)
1250 struct tdfxfb_i2c_chan
*chan
= data
;
1251 struct tdfx_par
*par
= chan
->par
;
1253 return (0 != (tdfx_inl(par
, VIDSERPARPORT
) & DDC_SCL_IN
));
1256 static int tdfxfb_ddc_getsda(void *data
)
1258 struct tdfxfb_i2c_chan
*chan
= data
;
1259 struct tdfx_par
*par
= chan
->par
;
1261 return (0 != (tdfx_inl(par
, VIDSERPARPORT
) & DDC_SDA_IN
));
1264 static int tdfxfb_setup_ddc_bus(struct tdfxfb_i2c_chan
*chan
, const char *name
,
1269 strlcpy(chan
->adapter
.name
, name
, sizeof(chan
->adapter
.name
));
1270 chan
->adapter
.owner
= THIS_MODULE
;
1271 chan
->adapter
.class = I2C_CLASS_DDC
;
1272 chan
->adapter
.algo_data
= &chan
->algo
;
1273 chan
->adapter
.dev
.parent
= dev
;
1274 chan
->algo
.setsda
= tdfxfb_ddc_setsda
;
1275 chan
->algo
.setscl
= tdfxfb_ddc_setscl
;
1276 chan
->algo
.getsda
= tdfxfb_ddc_getsda
;
1277 chan
->algo
.getscl
= tdfxfb_ddc_getscl
;
1278 chan
->algo
.udelay
= 10;
1279 chan
->algo
.timeout
= msecs_to_jiffies(500);
1280 chan
->algo
.data
= chan
;
1282 i2c_set_adapdata(&chan
->adapter
, chan
);
1284 rc
= i2c_bit_add_bus(&chan
->adapter
);
1286 DPRINTK("I2C bus %s registered.\n", name
);
1293 static int tdfxfb_setup_i2c_bus(struct tdfxfb_i2c_chan
*chan
, const char *name
,
1298 strlcpy(chan
->adapter
.name
, name
, sizeof(chan
->adapter
.name
));
1299 chan
->adapter
.owner
= THIS_MODULE
;
1300 chan
->adapter
.algo_data
= &chan
->algo
;
1301 chan
->adapter
.dev
.parent
= dev
;
1302 chan
->algo
.setsda
= tdfxfb_i2c_setsda
;
1303 chan
->algo
.setscl
= tdfxfb_i2c_setscl
;
1304 chan
->algo
.getsda
= tdfxfb_i2c_getsda
;
1305 chan
->algo
.getscl
= tdfxfb_i2c_getscl
;
1306 chan
->algo
.udelay
= 10;
1307 chan
->algo
.timeout
= msecs_to_jiffies(500);
1308 chan
->algo
.data
= chan
;
1310 i2c_set_adapdata(&chan
->adapter
, chan
);
1312 rc
= i2c_bit_add_bus(&chan
->adapter
);
1314 DPRINTK("I2C bus %s registered.\n", name
);
1321 static void tdfxfb_create_i2c_busses(struct fb_info
*info
)
1323 struct tdfx_par
*par
= info
->par
;
1325 tdfx_outl(par
, VIDINFORMAT
, 0x8160);
1326 tdfx_outl(par
, VIDSERPARPORT
, 0xcffc0020);
1328 par
->chan
[0].par
= par
;
1329 par
->chan
[1].par
= par
;
1331 tdfxfb_setup_ddc_bus(&par
->chan
[0], "Voodoo3-DDC", info
->dev
);
1332 tdfxfb_setup_i2c_bus(&par
->chan
[1], "Voodoo3-I2C", info
->dev
);
1335 static void tdfxfb_delete_i2c_busses(struct tdfx_par
*par
)
1337 if (par
->chan
[0].par
)
1338 i2c_del_adapter(&par
->chan
[0].adapter
);
1339 par
->chan
[0].par
= NULL
;
1341 if (par
->chan
[1].par
)
1342 i2c_del_adapter(&par
->chan
[1].adapter
);
1343 par
->chan
[1].par
= NULL
;
1346 static int tdfxfb_probe_i2c_connector(struct tdfx_par
*par
,
1347 struct fb_monspecs
*specs
)
1351 DPRINTK("Probe DDC Bus\n");
1352 if (par
->chan
[0].par
)
1353 edid
= fb_ddc_read(&par
->chan
[0].adapter
);
1356 fb_edid_to_monspecs(edid
, specs
);
1362 #endif /* CONFIG_FB_3DFX_I2C */
1365 * tdfxfb_probe - Device Initializiation
1367 * @pdev: PCI Device to initialize
1368 * @id: PCI Device ID
1370 * Initializes and allocates resources for PCI device @pdev.
1373 static int tdfxfb_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1375 struct tdfx_par
*default_par
;
1376 struct fb_info
*info
;
1378 struct fb_monspecs
*specs
;
1381 err
= pci_enable_device(pdev
);
1383 printk(KERN_ERR
"tdfxfb: Can't enable pdev: %d\n", err
);
1387 info
= framebuffer_alloc(sizeof(struct tdfx_par
), &pdev
->dev
);
1392 default_par
= info
->par
;
1393 info
->fix
= tdfx_fix
;
1395 /* Configure the default fb_fix_screeninfo first */
1396 switch (pdev
->device
) {
1397 case PCI_DEVICE_ID_3DFX_BANSHEE
:
1398 strcpy(info
->fix
.id
, "3Dfx Banshee");
1399 default_par
->max_pixclock
= BANSHEE_MAX_PIXCLOCK
;
1401 case PCI_DEVICE_ID_3DFX_VOODOO3
:
1402 strcpy(info
->fix
.id
, "3Dfx Voodoo3");
1403 default_par
->max_pixclock
= VOODOO3_MAX_PIXCLOCK
;
1405 case PCI_DEVICE_ID_3DFX_VOODOO5
:
1406 strcpy(info
->fix
.id
, "3Dfx Voodoo5");
1407 default_par
->max_pixclock
= VOODOO5_MAX_PIXCLOCK
;
1411 info
->fix
.mmio_start
= pci_resource_start(pdev
, 0);
1412 info
->fix
.mmio_len
= pci_resource_len(pdev
, 0);
1413 if (!request_mem_region(info
->fix
.mmio_start
, info
->fix
.mmio_len
,
1415 printk(KERN_ERR
"tdfxfb: Can't reserve regbase\n");
1419 default_par
->regbase_virt
=
1420 ioremap(info
->fix
.mmio_start
, info
->fix
.mmio_len
);
1421 if (!default_par
->regbase_virt
) {
1422 printk(KERN_ERR
"fb: Can't remap %s register area.\n",
1424 goto out_err_regbase
;
1427 info
->fix
.smem_start
= pci_resource_start(pdev
, 1);
1428 info
->fix
.smem_len
= do_lfb_size(default_par
, pdev
->device
);
1429 if (!info
->fix
.smem_len
) {
1430 printk(KERN_ERR
"fb: Can't count %s memory.\n", info
->fix
.id
);
1431 goto out_err_regbase
;
1434 if (!request_mem_region(info
->fix
.smem_start
,
1435 pci_resource_len(pdev
, 1), "tdfx smem")) {
1436 printk(KERN_ERR
"tdfxfb: Can't reserve smem\n");
1437 goto out_err_regbase
;
1440 info
->screen_base
= ioremap_wc(info
->fix
.smem_start
,
1441 info
->fix
.smem_len
);
1442 if (!info
->screen_base
) {
1443 printk(KERN_ERR
"fb: Can't remap %s framebuffer.\n",
1445 goto out_err_screenbase
;
1448 default_par
->iobase
= pci_resource_start(pdev
, 2);
1450 if (!request_region(pci_resource_start(pdev
, 2),
1451 pci_resource_len(pdev
, 2), "tdfx iobase")) {
1452 printk(KERN_ERR
"tdfxfb: Can't reserve iobase\n");
1453 goto out_err_screenbase
;
1456 printk(KERN_INFO
"fb: %s memory = %dK\n", info
->fix
.id
,
1457 info
->fix
.smem_len
>> 10);
1460 default_par
->wc_cookie
= arch_phys_wc_add(info
->fix
.smem_start
,
1461 info
->fix
.smem_len
);
1463 info
->fix
.ypanstep
= nopan
? 0 : 1;
1464 info
->fix
.ywrapstep
= nowrap
? 0 : 1;
1466 info
->fbops
= &tdfxfb_ops
;
1467 info
->pseudo_palette
= default_par
->palette
;
1468 info
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
1469 #ifdef CONFIG_FB_3DFX_ACCEL
1470 info
->flags
|= FBINFO_HWACCEL_FILLRECT
|
1471 FBINFO_HWACCEL_COPYAREA
|
1472 FBINFO_HWACCEL_IMAGEBLIT
|
1475 /* reserve 8192 bits for cursor */
1476 /* the 2.4 driver says PAGE_MASK boundary is not enough for Voodoo4 */
1478 info
->fix
.smem_len
= (info
->fix
.smem_len
- 1024) &
1480 specs
= &info
->monspecs
;
1482 info
->var
.bits_per_pixel
= 8;
1483 #ifdef CONFIG_FB_3DFX_I2C
1484 tdfxfb_create_i2c_busses(info
);
1485 err
= tdfxfb_probe_i2c_connector(default_par
, specs
);
1488 if (specs
->modedb
== NULL
)
1489 DPRINTK("Unable to get Mode Database\n");
1491 const struct fb_videomode
*m
;
1493 fb_videomode_to_modelist(specs
->modedb
,
1496 m
= fb_find_best_display(specs
, &info
->modelist
);
1498 fb_videomode_to_var(&info
->var
, m
);
1499 /* fill all other info->var's fields */
1500 if (tdfxfb_check_var(&info
->var
, info
) < 0)
1501 info
->var
= tdfx_var
;
1508 if (!mode_option
&& !found
)
1509 mode_option
= "640x480@60";
1512 err
= fb_find_mode(&info
->var
, info
, mode_option
,
1513 specs
->modedb
, specs
->modedb_len
,
1514 NULL
, info
->var
.bits_per_pixel
);
1515 if (!err
|| err
== 4)
1516 info
->var
= tdfx_var
;
1520 fb_destroy_modedb(specs
->modedb
);
1521 specs
->modedb
= NULL
;
1524 /* maximize virtual vertical length */
1525 lpitch
= info
->var
.xres_virtual
* ((info
->var
.bits_per_pixel
+ 7) >> 3);
1526 info
->var
.yres_virtual
= info
->fix
.smem_len
/ lpitch
;
1527 if (info
->var
.yres_virtual
< info
->var
.yres
)
1528 goto out_err_iobase
;
1530 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
1531 printk(KERN_ERR
"tdfxfb: Can't allocate color map\n");
1532 goto out_err_iobase
;
1535 if (register_framebuffer(info
) < 0) {
1536 printk(KERN_ERR
"tdfxfb: can't register framebuffer\n");
1537 fb_dealloc_cmap(&info
->cmap
);
1538 goto out_err_iobase
;
1543 pci_set_drvdata(pdev
, info
);
1547 #ifdef CONFIG_FB_3DFX_I2C
1548 tdfxfb_delete_i2c_busses(default_par
);
1550 arch_phys_wc_del(default_par
->wc_cookie
);
1551 release_region(pci_resource_start(pdev
, 2),
1552 pci_resource_len(pdev
, 2));
1554 if (info
->screen_base
)
1555 iounmap(info
->screen_base
);
1556 release_mem_region(info
->fix
.smem_start
, pci_resource_len(pdev
, 1));
1559 * Cleanup after anything that was remapped/allocated.
1561 if (default_par
->regbase_virt
)
1562 iounmap(default_par
->regbase_virt
);
1563 release_mem_region(info
->fix
.mmio_start
, info
->fix
.mmio_len
);
1565 framebuffer_release(info
);
1570 static void __init
tdfxfb_setup(char *options
)
1574 if (!options
|| !*options
)
1577 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1580 if (!strcmp(this_opt
, "nopan")) {
1582 } else if (!strcmp(this_opt
, "nowrap")) {
1584 } else if (!strncmp(this_opt
, "hwcursor=", 9)) {
1585 hwcursor
= simple_strtoul(this_opt
+ 9, NULL
, 0);
1586 } else if (!strncmp(this_opt
, "nomtrr", 6)) {
1589 mode_option
= this_opt
;
1596 * tdfxfb_remove - Device removal
1598 * @pdev: PCI Device to cleanup
1600 * Releases all resources allocated during the course of the driver's
1601 * lifetime for the PCI device @pdev.
1604 static void tdfxfb_remove(struct pci_dev
*pdev
)
1606 struct fb_info
*info
= pci_get_drvdata(pdev
);
1607 struct tdfx_par
*par
= info
->par
;
1609 unregister_framebuffer(info
);
1610 #ifdef CONFIG_FB_3DFX_I2C
1611 tdfxfb_delete_i2c_busses(par
);
1613 arch_phys_wc_del(par
->wc_cookie
);
1614 iounmap(par
->regbase_virt
);
1615 iounmap(info
->screen_base
);
1617 /* Clean up after reserved regions */
1618 release_region(pci_resource_start(pdev
, 2),
1619 pci_resource_len(pdev
, 2));
1620 release_mem_region(pci_resource_start(pdev
, 1),
1621 pci_resource_len(pdev
, 1));
1622 release_mem_region(pci_resource_start(pdev
, 0),
1623 pci_resource_len(pdev
, 0));
1624 fb_dealloc_cmap(&info
->cmap
);
1625 framebuffer_release(info
);
1628 static int __init
tdfxfb_init(void)
1631 char *option
= NULL
;
1633 if (fb_get_options("tdfxfb", &option
))
1636 tdfxfb_setup(option
);
1638 return pci_register_driver(&tdfxfb_driver
);
1641 static void __exit
tdfxfb_exit(void)
1643 pci_unregister_driver(&tdfxfb_driver
);
1646 MODULE_AUTHOR("Hannu Mallat <hmallat@cc.hut.fi>");
1647 MODULE_DESCRIPTION("3Dfx framebuffer device driver");
1648 MODULE_LICENSE("GPL");
1650 module_param(hwcursor
, int, 0644);
1651 MODULE_PARM_DESC(hwcursor
, "Enable hardware cursor "
1652 "(1=enable, 0=disable, default=1)");
1653 module_param(mode_option
, charp
, 0);
1654 MODULE_PARM_DESC(mode_option
, "Initial video mode e.g. '648x480-8@60'");
1655 module_param(nomtrr
, bool, 0);
1656 MODULE_PARM_DESC(nomtrr
, "Disable MTRR support (default: enabled)");
1658 module_init(tdfxfb_init
);
1659 module_exit(tdfxfb_exit
);