2 * linux/drivers/video/sstfb.c -- voodoo graphics frame buffer
4 * Copyright (c) 2000-2002 Ghozlane Toumi <gtoumi@laposte.net>
6 * Created 15 Jan 2000 by Ghozlane Toumi
8 * Contributions (and many thanks) :
10 * 03/2001 James Simmons <jsimmons@infradead.org>
11 * 04/2001 Paul Mundt <lethal@chaoticdreams.org>
12 * 05/2001 Urs Ganse <ursg@uni.de>
13 * (initial work on voodoo2 port, interlace)
14 * 09/2002 Helge Deller <deller@gmx.de>
15 * (enable driver on big-endian machines (hppa), ioctl fixes)
16 * 12/2002 Helge Deller <deller@gmx.de>
17 * (port driver to new frambuffer infrastructure)
18 * 01/2003 Helge Deller <deller@gmx.de>
19 * (initial work on fb hardware acceleration for voodoo2)
24 * The voodoo1 has the following memory mapped address space:
25 * 0x000000 - 0x3fffff : registers (4MB)
26 * 0x400000 - 0x7fffff : linear frame buffer (4MB)
27 * 0x800000 - 0xffffff : texture memory (8MB)
31 * misc notes, TODOs, toASKs, and deep thoughts
33 -TODO: at one time or another test that the mode is acceptable by the monitor
34 -ASK: Can I choose different ordering for the color bitfields (rgba argb ...)
35 wich one should i use ? is there any preferred one ? It seems ARGB is
37 -TODO: in set_var check the validity of timings (hsync vsync)...
38 -TODO: check and recheck the use of sst_wait_idle : we don't flush the fifo via
39 a nop command. so it's ok as long as the commands we pass don't go
40 through the fifo. warning: issuing a nop command seems to need pci_fifo
41 -FIXME: in case of failure in the init sequence, be sure we return to a safe
43 -FIXME: 4MB boards have banked memory (FbiInit2 bits 1 & 20)
48 * SST_DEBUG : enable debugging
49 * SST_DEBUG_REG : debug registers
51 * 1 : dac calls, [un]set_bits, FbiInit
52 * 2 : insane debug level (log every register read/write)
53 * SST_DEBUG_FUNC : functions
55 * 1 : function call / debug ioctl
57 * 3 : flood . you don't want to do that. trust me.
58 * SST_DEBUG_VAR : debug display/var structs
60 * 1 : dumps display, fb_var
62 * sstfb specific ioctls:
63 * toggle vga (0x46db) : toggle vga_pass_through
64 * fill fb (0x46dc) : fills fb
65 * test disp (0x46de) : draws a test image
70 #define SST_DEBUG_REG 0
71 #define SST_DEBUG_FUNC 0
72 #define SST_DEBUG_VAR 0
74 /* enable 24/32 bpp functions ? (completely untested!) */
79 0 800x600@60 took from glide
80 1 640x480@75 took from glide
81 2 1024x768@76 std fb.mode
82 3 640x480@60 glide default */
83 #define DEFAULT_MODE 3
89 #include <linux/config.h>
90 #include <linux/string.h>
91 #include <linux/kernel.h>
92 #include <linux/module.h>
94 #include <linux/pci.h>
95 #include <linux/delay.h>
96 #include <linux/init.h>
97 #include <linux/slab.h>
99 #include <asm/ioctl.h>
100 #include <asm/uaccess.h>
101 #include <video/sstfb.h>
104 /* initialized by setup */
106 static int vgapass
; /* enable Vga passthrough cable */
107 static int mem
; /* mem size in MB, 0 = autodetect */
108 static int clipping
= 1; /* use clipping (slower, safer) */
109 static int gfxclk
; /* force FBI freq in Mhz . Dangerous */
110 static int slowpci
; /* slow PCI settings */
112 static char *mode_option __devinitdata
;
119 #define IS_VOODOO2(par) ((par)->type == ID_VOODOO2)
121 static struct sst_spec voodoo_spec
[] __devinitdata
= {
122 { .name
= "Voodoo Graphics", .default_gfx_clock
= 50000, .max_gfxclk
= 60 },
123 { .name
= "Voodoo2", .default_gfx_clock
= 75000, .max_gfxclk
= 85 },
126 static struct fb_var_screeninfo sstfb_default
=
127 #if ( DEFAULT_MODE == 0 )
128 { /* 800x600@60, 16 bpp .borowed from glide/sst1/include/sst1init.h */
129 800, 600, 800, 600, 0, 0, 16, 0,
130 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
132 25000, 86, 41, 23, 1, 127, 4,
133 0, FB_VMODE_NONINTERLACED
};
134 #elif ( DEFAULT_MODE == 1 )
135 {/* 640x480@75, 16 bpp .borowed from glide/sst1/include/sst1init.h */
136 640, 480, 640, 480, 0, 0, 16, 0,
137 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
139 31746, 118, 17, 16, 1, 63, 3,
140 0, FB_VMODE_NONINTERLACED
};
141 #elif ( DEFAULT_MODE == 2 )
142 { /* 1024x768@76 took from my /etc/fb.modes */
143 1024, 768, 1024, 768,0, 0, 16,0,
144 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
146 11764, 208, 8, 36, 16, 120, 3 ,
147 0, FB_VMODE_NONINTERLACED
};
148 #elif ( DEFAULT_MODE == 3 )
149 { /* 640x480@60 , 16bpp glide default ?*/
150 640, 480, 640, 480, 0, 0, 16, 0,
151 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
153 39721 , 38, 26 , 25 ,18 , 96 ,2,
154 0, FB_VMODE_NONINTERLACED
};
156 #error "Invalid DEFAULT_MODE value !"
164 static void sstfb_drawdebugimage(struct fb_info
*info
);
165 static int sstfb_dump_regs(struct fb_info
*info
);
168 #if (SST_DEBUG_REG > 0)
169 static void sst_dbg_print_read_reg(u32 reg
, u32 val
) {
172 case FBIINIT0
: regname
= "FbiInit0"; break;
173 case FBIINIT1
: regname
= "FbiInit1"; break;
174 case FBIINIT2
: regname
= "FbiInit2"; break;
175 case FBIINIT3
: regname
= "FbiInit3"; break;
176 case FBIINIT4
: regname
= "FbiInit4"; break;
177 case FBIINIT5
: regname
= "FbiInit5"; break;
178 case FBIINIT6
: regname
= "FbiInit6"; break;
179 default: regname
= NULL
; break;
182 r_ddprintk("sst_read(%#x): %#x\n", reg
, val
);
184 r_dprintk(" sst_read(%s): %#x\n", regname
, val
);
187 static void sst_dbg_print_write_reg(u32 reg
, u32 val
) {
190 case FBIINIT0
: regname
= "FbiInit0"; break;
191 case FBIINIT1
: regname
= "FbiInit1"; break;
192 case FBIINIT2
: regname
= "FbiInit2"; break;
193 case FBIINIT3
: regname
= "FbiInit3"; break;
194 case FBIINIT4
: regname
= "FbiInit4"; break;
195 case FBIINIT5
: regname
= "FbiInit5"; break;
196 case FBIINIT6
: regname
= "FbiInit6"; break;
197 default: regname
= NULL
; break;
200 r_ddprintk("sst_write(%#x, %#x)\n", reg
, val
);
202 r_dprintk(" sst_write(%s, %#x)\n", regname
, val
);
204 #else /* (SST_DEBUG_REG > 0) */
205 # define sst_dbg_print_read_reg(reg, val) do {} while(0)
206 # define sst_dbg_print_write_reg(reg, val) do {} while(0)
207 #endif /* (SST_DEBUG_REG > 0) */
210 * hardware access functions
213 /* register access */
214 #define sst_read(reg) __sst_read(par->mmio_vbase, reg)
215 #define sst_write(reg,val) __sst_write(par->mmio_vbase, reg, val)
216 #define sst_set_bits(reg,val) __sst_set_bits(par->mmio_vbase, reg, val)
217 #define sst_unset_bits(reg,val) __sst_unset_bits(par->mmio_vbase, reg, val)
218 #define sst_dac_read(reg) __sst_dac_read(par->mmio_vbase, reg)
219 #define sst_dac_write(reg,val) __sst_dac_write(par->mmio_vbase, reg, val)
220 #define dac_i_read(reg) __dac_i_read(par->mmio_vbase, reg)
221 #define dac_i_write(reg,val) __dac_i_write(par->mmio_vbase, reg, val)
223 static inline u32
__sst_read(u_long vbase
, u32 reg
)
225 u32 ret
= readl(vbase
+ reg
);
226 sst_dbg_print_read_reg(reg
, ret
);
230 static inline void __sst_write(u_long vbase
, u32 reg
, u32 val
)
232 sst_dbg_print_write_reg(reg
, val
);
233 writel(val
, vbase
+ reg
);
236 static inline void __sst_set_bits(u_long vbase
, u32 reg
, u32 val
)
238 r_dprintk("sst_set_bits(%#x, %#x)\n", reg
, val
);
239 __sst_write(vbase
, reg
, __sst_read(vbase
, reg
) | val
);
242 static inline void __sst_unset_bits(u_long vbase
, u32 reg
, u32 val
)
244 r_dprintk("sst_unset_bits(%#x, %#x)\n", reg
, val
);
245 __sst_write(vbase
, reg
, __sst_read(vbase
, reg
) & ~val
);
249 * wait for the fbi chip. ASK: what happens if the fbi is stuck ?
251 * the FBI is supposed to be ready if we receive 5 time
252 * in a row a "idle" answer to our requests
255 #define sst_wait_idle() __sst_wait_idle(par->mmio_vbase)
257 static int __sst_wait_idle(u_long vbase
)
261 /* if (doFBINOP) __sst_write(vbase, NOPCMD, 0); */
264 if (__sst_read(vbase
, STATUS
) & STATUS_FBI_BUSY
) {
265 f_dddprintk("status: busy\n");
266 /* FIXME basicaly, this is a busy wait. maybe not that good. oh well;
267 * this is a small loop after all.
268 * Or maybe we should use mdelay() or udelay() here instead ? */
272 f_dddprintk("status: idle(%d)\n", count
);
274 if (count
>= 5) return 1;
275 /* XXX do something to avoid hanging the machine if the voodoo is out */
281 /* dac_read should be remaped to FbiInit2 (via the pci reg init_enable) */
282 static u8
__sst_dac_read(u_long vbase
, u8 reg
)
287 __sst_write(vbase
, DAC_DATA
, ((u32
)reg
<< 8) | DAC_READ_CMD
);
288 __sst_wait_idle(vbase
);
290 ret
= __sst_read(vbase
, DAC_READ
) & 0xff;
291 r_dprintk("sst_dac_read(%#x): %#x\n", reg
, ret
);
296 static void __sst_dac_write(u_long vbase
, u8 reg
, u8 val
)
298 r_dprintk("sst_dac_write(%#x, %#x)\n", reg
, val
);
300 __sst_write(vbase
, DAC_DATA
,(((u32
)reg
<< 8)) | (u32
)val
);
303 /* indexed access to ti/att dacs */
304 static u32
__dac_i_read(u_long vbase
, u8 reg
)
308 __sst_dac_write(vbase
, DACREG_ADDR_I
, reg
);
309 ret
= __sst_dac_read(vbase
, DACREG_DATA_I
);
310 r_dprintk("sst_dac_read_i(%#x): %#x\n", reg
, ret
);
313 static void __dac_i_write(u_long vbase
, u8 reg
,u8 val
)
315 r_dprintk("sst_dac_write_i(%#x, %#x)\n", reg
, val
);
316 __sst_dac_write(vbase
, DACREG_ADDR_I
, reg
);
317 __sst_dac_write(vbase
, DACREG_DATA_I
, val
);
320 /* compute the m,n,p , returns the real freq
321 * (ics datasheet : N <-> N1 , P <-> N2)
323 * Fout= Fref * (M+2)/( 2^P * (N+2))
324 * we try to get close to the asked freq
325 * with P as high, and M as low as possible
327 * ti/att : 0 <= M <= 255; 0 <= P <= 3; 0<= N <= 63
328 * ics : 1 <= M <= 127; 0 <= P <= 3; 1<= N <= 31
329 * we'll use the lowest limitation, should be precise enouth
331 static int sst_calc_pll(const int freq
, int *freq_out
, struct pll_timing
*t
)
333 int m
, m2
, n
, p
, best_err
, fout
;
339 /* f * 2^P = vco should be less than VCOmax ~ 250 MHz for ics*/
340 while (((1 << p
) * freq
> VCO_MAX
) && (p
>= 0))
344 for (n
= 1; n
< 32; n
++) {
345 /* calc 2 * m so we can round it later*/
346 m2
= (2 * freq
* (1 << p
) * (n
+ 2) ) / DAC_FREF
- 4 ;
348 m
= (m2
% 2 ) ? m2
/2+1 : m2
/2 ;
351 fout
= (DAC_FREF
* (m
+ 2)) / ((1 << p
) * (n
+ 2));
352 if ((abs(fout
- freq
) < best_err
) && (m
> 0)) {
355 best_err
= abs(fout
- freq
);
356 /* we get the lowest m , allowing 0.5% error in freq*/
357 if (200*best_err
< freq
) break;
360 if (best_n
== -1) /* unlikely, but who knows ? */
365 *freq_out
= (DAC_FREF
* (t
->m
+ 2)) / ((1 << t
->p
) * (t
->n
+ 2));
366 f_ddprintk ("m: %d, n: %d, p: %d, F: %dKhz\n",
367 t
->m
, t
->n
, t
->p
, *freq_out
);
374 static void sstfb_clear_screen(struct fb_info
*info
)
377 fb_memset(info
->screen_base
, 0, info
->fix
.smem_len
);
382 * sstfb_check_var - Optional function. Validates a var passed in.
383 * @var: frame buffer variable screen structure
384 * @info: frame buffer structure that represents a single frame buffer
386 static int sstfb_check_var(struct fb_var_screeninfo
*var
,
387 struct fb_info
*info
)
389 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
390 int hSyncOff
= var
->xres
+ var
->right_margin
+ var
->left_margin
;
391 int vSyncOff
= var
->yres
+ var
->lower_margin
+ var
->upper_margin
;
392 int vBackPorch
= var
->left_margin
, yDim
= var
->yres
;
393 int vSyncOn
= var
->vsync_len
;
394 int tiles_in_X
, real_length
;
397 if (sst_calc_pll(PICOS2KHZ(var
->pixclock
), &freq
, &par
->pll
)) {
398 eprintk("Pixclock at %ld KHZ out of range\n",
399 PICOS2KHZ(var
->pixclock
));
402 var
->pixclock
= KHZ2PICOS(freq
);
404 if (var
->vmode
& FB_VMODE_INTERLACED
)
405 vBackPorch
+= (vBackPorch
% 2);
406 if (var
->vmode
& FB_VMODE_DOUBLE
) {
413 switch (var
->bits_per_pixel
) {
415 var
->bits_per_pixel
= 16;
419 var
->bits_per_pixel
= 24;
422 var
->bits_per_pixel
= 32;
426 eprintk("Unsupported bpp %d\n", var
->bits_per_pixel
);
431 if ((var
->xres
<= 1) || (yDim
<= 0 )
432 || (var
->hsync_len
<= 1)
434 || (var
->left_margin
<= 2)
437 || (vBackPorch
<= 0)) {
441 if (IS_VOODOO2(par
)) {
442 /* Voodoo 2 limits */
443 tiles_in_X
= (var
->xres
+ 63 ) / 64 * 2;
445 if (((var
->xres
- 1) >= POW2(11)) || (yDim
>= POW2(11))) {
446 eprintk("Unsupported resolution %dx%d\n",
447 var
->xres
, var
->yres
);
451 if (((var
->hsync_len
-1) >= POW2(9))
452 || ((hSyncOff
-1) >= POW2(11))
453 || ((var
->left_margin
- 2) >= POW2(9))
454 || (vSyncOn
>= POW2(13))
455 || (vSyncOff
>= POW2(13))
456 || (vBackPorch
>= POW2(9))
457 || (tiles_in_X
>= POW2(6))
458 || (tiles_in_X
<= 0)) {
459 eprintk("Unsupported Timings\n");
464 tiles_in_X
= (var
->xres
+ 63 ) / 64;
467 eprintk("Interlace/Doublescan not supported %#x\n",
471 if (((var
->xres
- 1) >= POW2(10)) || (var
->yres
>= POW2(10))) {
472 eprintk("Unsupported resolution %dx%d\n",
473 var
->xres
, var
->yres
);
476 if (((var
->hsync_len
- 1) >= POW2(8))
477 || ((hSyncOff
-1) >= POW2(10))
478 || ((var
->left_margin
- 2) >= POW2(8))
479 || (vSyncOn
>= POW2(12))
480 || (vSyncOff
>= POW2(12))
481 || (vBackPorch
>= POW2(8))
482 || (tiles_in_X
>= POW2(4))
483 || (tiles_in_X
<= 0)) {
484 eprintk("Unsupported Timings\n");
489 /* it seems that the fbi uses tiles of 64x16 pixels to "map" the mem */
490 /* FIXME: i don't like this... looks wrong */
491 real_length
= tiles_in_X
* (IS_VOODOO2(par
) ? 32 : 64 )
492 * ((var
->bits_per_pixel
== 16) ? 2 : 4);
494 if ((real_length
* yDim
) > info
->fix
.smem_len
) {
495 eprintk("Not enough video memory\n");
499 var
->sync
&= (FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
);
500 var
->vmode
&= (FB_VMODE_INTERLACED
| FB_VMODE_DOUBLE
);
507 * correct the color bit fields
509 /* var->{red|green|blue}.msb_right = 0; */
511 switch (var
->bits_per_pixel
) {
512 case 16: /* RGB 565 LfbMode 0 */
514 var
->green
.length
= 6;
515 var
->blue
.length
= 5;
516 var
->transp
.length
= 0;
518 var
->red
.offset
= 11;
519 var
->green
.offset
= 5;
520 var
->blue
.offset
= 0;
521 var
->transp
.offset
= 0;
524 case 24: /* RGB 888 LfbMode 4 */
525 case 32: /* ARGB 8888 LfbMode 5 */
527 var
->green
.length
= 8;
528 var
->blue
.length
= 8;
529 var
->transp
.length
= 0;
531 var
->red
.offset
= 16;
532 var
->green
.offset
= 8;
533 var
->blue
.offset
= 0;
534 var
->transp
.offset
= 0; /* in 24bpp we fake a 32 bpp mode */
544 * sstfb_set_par - Optional function. Alters the hardware state.
545 * @info: frame buffer structure that represents a single frame buffer
547 static int sstfb_set_par(struct fb_info
*info
)
549 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
550 u32 lfbmode
, fbiinit1
, fbiinit2
, fbiinit3
, fbiinit5
, fbiinit6
=0;
551 struct pci_dev
*sst_dev
= par
->dev
;
555 par
->hSyncOff
= info
->var
.xres
+ info
->var
.right_margin
+ info
->var
.left_margin
;
557 par
->yDim
= info
->var
.yres
;
558 par
->vSyncOn
= info
->var
.vsync_len
;
559 par
->vSyncOff
= info
->var
.yres
+ info
->var
.lower_margin
+ info
->var
.upper_margin
;
560 par
->vBackPorch
= info
->var
.upper_margin
;
562 /* We need par->pll */
563 sst_calc_pll(PICOS2KHZ(info
->var
.pixclock
), &freq
, &par
->pll
);
565 if (info
->var
.vmode
& FB_VMODE_INTERLACED
)
566 par
->vBackPorch
+= (par
->vBackPorch
% 2);
567 if (info
->var
.vmode
& FB_VMODE_DOUBLE
) {
568 par
->vBackPorch
<<= 1;
574 if (IS_VOODOO2(par
)) {
575 /* voodoo2 has 32 pixel wide tiles , BUT stange things
576 happen with odd number of tiles */
577 par
->tiles_in_X
= (info
->var
.xres
+ 63 ) / 64 * 2;
579 /* voodoo1 has 64 pixels wide tiles. */
580 par
->tiles_in_X
= (info
->var
.xres
+ 63 ) / 64;
583 f_ddprintk("hsync_len hSyncOff vsync_len vSyncOff\n");
584 f_ddprintk("%-7d %-8d %-7d %-8d\n",
585 info
->var
.hsync_len
, par
->hSyncOff
,
586 par
->vSyncOn
, par
->vSyncOff
);
587 f_ddprintk("left_margin upper_margin xres yres Freq\n");
588 f_ddprintk("%-10d %-10d %-4d %-4d %-8ld\n",
589 info
->var
.left_margin
, info
->var
.upper_margin
,
590 info
->var
.xres
, info
->var
.yres
, PICOS2KHZ(info
->var
.pixclock
));
592 sst_write(NOPCMD
, 0);
594 pci_write_config_dword(sst_dev
, PCI_INIT_ENABLE
, PCI_EN_INIT_WR
);
595 sst_set_bits(FBIINIT1
, VIDEO_RESET
);
596 sst_set_bits(FBIINIT0
, FBI_RESET
| FIFO_RESET
);
597 sst_unset_bits(FBIINIT2
, EN_DRAM_REFRESH
);
600 /*sst_unset_bits (FBIINIT0, FBI_RESET); / reenable FBI ? */
602 sst_write(BACKPORCH
, par
->vBackPorch
<< 16 | (info
->var
.left_margin
- 2));
603 sst_write(VIDEODIMENSIONS
, par
->yDim
<< 16 | (info
->var
.xres
- 1));
604 sst_write(HSYNC
, (par
->hSyncOff
- 1) << 16 | (info
->var
.hsync_len
- 1));
605 sst_write(VSYNC
, par
->vSyncOff
<< 16 | par
->vSyncOn
);
607 fbiinit2
= sst_read(FBIINIT2
);
608 fbiinit3
= sst_read(FBIINIT3
);
610 /* everything is reset. we enable fbiinit2/3 remap : dac acces ok */
611 pci_write_config_dword(sst_dev
, PCI_INIT_ENABLE
,
612 PCI_EN_INIT_WR
| PCI_REMAP_DAC
);
614 par
->dac_sw
.set_vidmod(info
, info
->var
.bits_per_pixel
);
616 /* set video clock */
617 par
->dac_sw
.set_pll(info
, &par
->pll
, VID_CLOCK
);
619 /* disable fbiinit2/3 remap */
620 pci_write_config_dword(sst_dev
, PCI_INIT_ENABLE
,
623 /* restore fbiinit2/3 */
624 sst_write(FBIINIT2
,fbiinit2
);
625 sst_write(FBIINIT3
,fbiinit3
);
627 fbiinit1
= (sst_read(FBIINIT1
) & VIDEO_MASK
)
632 /* | (15 << TILES_IN_X_SHIFT) */
634 /* | (2 << VCLK_2X_SEL_DEL_SHIFT)
635 | (2 << VCLK_DEL_SHIFT) */;
636 /* try with vclk_in_delay =0 (bits 29:30) , vclk_out_delay =0 (bits(27:28)
637 in (near) future set them accordingly to revision + resolution (cf glide)
638 first understand what it stands for :)
639 FIXME: there are some artefacts... check for the vclk_in_delay
640 lets try with 6ns delay in both vclk_out & in...
641 doh... they're still there :\
644 ntiles
= par
->tiles_in_X
;
645 if (IS_VOODOO2(par
)) {
646 fbiinit1
|= ((ntiles
& 0x20) >> 5) << TILES_IN_X_MSB_SHIFT
647 | ((ntiles
& 0x1e) >> 1) << TILES_IN_X_SHIFT
;
648 /* as the only value of importance for us in fbiinit6 is tiles in X (lsb),
649 and as reading fbinit 6 will return crap (see FBIINIT6_DEFAULT) we just
650 write our value. BTW due to the dac unable to read odd number of tiles, this
651 field is always null ... */
652 fbiinit6
= (ntiles
& 0x1) << TILES_IN_X_LSB_SHIFT
;
655 fbiinit1
|= ntiles
<< TILES_IN_X_SHIFT
;
657 switch (info
->var
.bits_per_pixel
) {
659 fbiinit1
|= SEL_SOURCE_VCLK_2X_SEL
;
664 /* sst_set_bits(FBIINIT1, SEL_SOURCE_VCLK_2X_DIV2 | EN_24BPP);*/
665 fbiinit1
|= SEL_SOURCE_VCLK_2X_SEL
| EN_24BPP
;
671 sst_write(FBIINIT1
, fbiinit1
);
672 if (IS_VOODOO2(par
)) {
673 sst_write(FBIINIT6
, fbiinit6
);
674 fbiinit5
=sst_read(FBIINIT5
) & FBIINIT5_MASK
;
675 if (info
->var
.vmode
& FB_VMODE_INTERLACED
)
676 fbiinit5
|= INTERLACE
;
677 if (info
->var
.vmode
& FB_VMODE_DOUBLE
)
678 fbiinit5
|= VDOUBLESCAN
;
679 if (info
->var
.sync
& FB_SYNC_HOR_HIGH_ACT
)
680 fbiinit5
|= HSYNC_HIGH
;
681 if (info
->var
.sync
& FB_SYNC_VERT_HIGH_ACT
)
682 fbiinit5
|= VSYNC_HIGH
;
683 sst_write(FBIINIT5
, fbiinit5
);
686 sst_unset_bits(FBIINIT1
, VIDEO_RESET
);
687 sst_unset_bits(FBIINIT0
, FBI_RESET
| FIFO_RESET
);
688 sst_set_bits(FBIINIT2
, EN_DRAM_REFRESH
);
689 /* disables fbiinit writes */
690 pci_write_config_dword(sst_dev
, PCI_INIT_ENABLE
, PCI_EN_FIFO_WR
);
692 /* set lfbmode : set mode + front buffer for reads/writes
693 + disable pipeline */
694 switch (info
->var
.bits_per_pixel
) {
710 #if defined(__BIG_ENDIAN)
711 /* Enable byte-swizzle functionality in hardware.
712 * With this enabled, all our read- and write-accesses to
713 * the voodoo framebuffer can be done in native format, and
714 * the hardware will automatically convert it to little-endian.
715 * - tested on HP-PARISC, Helge Deller <deller@gmx.de> */
716 lfbmode
|= ( LFB_WORD_SWIZZLE_WR
| LFB_BYTE_SWIZZLE_WR
|
717 LFB_WORD_SWIZZLE_RD
| LFB_BYTE_SWIZZLE_RD
);
721 sst_write(LFBMODE
, lfbmode
| EN_PXL_PIPELINE
);
723 * Set "clipping" dimensions. If clipping is disabled and
724 * writes to offscreen areas of the framebuffer are performed,
725 * the "behaviour is undefined" (_very_ undefined) - Urs
727 /* btw, it requires enabling pixel pipeline in LFBMODE .
728 off screen read/writes will just wrap and read/print pixels
729 on screen. Ugly but not that dangerous */
730 f_ddprintk("setting clipping dimensions 0..%d, 0..%d\n",
731 info
->var
.xres
- 1, par
->yDim
- 1);
733 sst_write(CLIP_LEFT_RIGHT
, info
->var
.xres
);
734 sst_write(CLIP_LOWY_HIGHY
, par
->yDim
);
735 sst_set_bits(FBZMODE
, EN_CLIPPING
| EN_RGB_WRITE
);
737 /* no clipping : direct access, no pipeline */
738 sst_write(LFBMODE
, lfbmode
);
744 * sstfb_setcolreg - Optional function. Sets a color register.
745 * @regno: hardware colormap register
746 * @red: frame buffer colormap structure
747 * @green: The green value which can be up to 16 bits wide
748 * @blue: The blue value which can be up to 16 bits wide.
749 * @transp: If supported the alpha value which can be up to 16 bits wide.
750 * @info: frame buffer info structure
752 static int sstfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
753 u_int transp
, struct fb_info
*info
)
757 f_dddprintk("sstfb_setcolreg\n");
758 f_dddprintk("%-2d rgbt: %#x, %#x, %#x, %#x\n",
759 regno
, red
, green
, blue
, transp
);
763 red
>>= (16 - info
->var
.red
.length
);
764 green
>>= (16 - info
->var
.green
.length
);
765 blue
>>= (16 - info
->var
.blue
.length
);
766 transp
>>= (16 - info
->var
.transp
.length
);
767 col
= (red
<< info
->var
.red
.offset
)
768 | (green
<< info
->var
.green
.offset
)
769 | (blue
<< info
->var
.blue
.offset
)
770 | (transp
<< info
->var
.transp
.offset
);
772 ((u32
*)info
->pseudo_palette
)[regno
] = col
;
777 static int sstfb_ioctl(struct inode
*inode
, struct file
*file
,
778 u_int cmd
, u_long arg
, struct fb_info
*info
)
780 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
781 struct pci_dev
*sst_dev
= par
->dev
;
782 u32 fbiinit0
, tmp
, val
;
787 /* dump current FBIINIT values to system log */
788 case _IO('F', 0xdb): /* 0x46db */
789 return sstfb_dump_regs(info
);
791 /* fills lfb with #arg pixels */
792 case _IOW('F', 0xdc, u32
): /* 0x46dc */
793 if (copy_from_user(&val
, (void __user
*)arg
, sizeof(val
)))
795 if (val
> info
->fix
.smem_len
)
796 val
= info
->fix
.smem_len
;
797 printk("filling %#x \n", val
);
798 for (p
=0 ; p
<val
; p
+=2)
799 writew(p
>> 6, info
->screen_base
+ p
);
802 /* change VGA pass_through mode */
803 case _IOW('F', 0xdd, u32
): /* 0x46dd */
804 if (copy_from_user(&val
, (void __user
*)arg
, sizeof(val
)))
806 pci_read_config_dword(sst_dev
, PCI_INIT_ENABLE
, &tmp
);
807 pci_write_config_dword(sst_dev
, PCI_INIT_ENABLE
,
808 tmp
| PCI_EN_INIT_WR
);
809 fbiinit0
= sst_read (FBIINIT0
);
811 sst_write(FBIINIT0
, fbiinit0
& ~EN_VGA_PASSTHROUGH
);
812 iprintk("Disabling VGA pass-through\n");
814 sst_write(FBIINIT0
, fbiinit0
| EN_VGA_PASSTHROUGH
);
815 iprintk("Enabling VGA pass-through\n");
817 pci_write_config_dword(sst_dev
, PCI_INIT_ENABLE
, tmp
);
820 /* draw test image */
821 case _IO('F', 0xde): /* 0x46de */
822 f_dprintk("test color display at %d bpp\n",
823 info
->var
.bits_per_pixel
);
824 sstfb_drawdebugimage(info
);
832 * Screen-to-Screen BitBlt 2D command (for the bmove fb op.) - Voodoo2 only
835 static void sstfb_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
)
837 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
838 u32 stride
= info
->fix
.line_length
;
840 if (!IS_VOODOO2(par
))
843 sst_write(BLTSRCBASEADDR
, 0);
844 sst_write(BLTDSTBASEADDR
, 0);
845 sst_write(BLTROP
, BLTROP_COPY
);
846 sst_write(BLTXYSTRIDES
, stride
| (stride
<< 16));
847 sst_write(BLTSRCXY
, area
->sx
| (area
->sy
<< 16));
848 sst_write(BLTDSTXY
, area
->dx
| (area
->dy
<< 16));
849 sst_write(BLTSIZE
, area
->width
| (area
->height
<< 16));
850 sst_write(BLTCOMMAND
, BLT_SCR2SCR_BITBLT
| LAUNCH_BITBLT
|
851 (BLT_16BPP_FMT
<< 3) /* | BIT(14) */ | BIT(15) );
858 * FillRect 2D command (solidfill or invert (via ROP_XOR)) - Voodoo2 only
860 static void sstfb_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
862 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
863 u32 stride
= info
->fix
.line_length
;
865 if (!IS_VOODOO2(par
))
868 sst_write(BLTCLIPX
, info
->var
.xres
);
869 sst_write(BLTCLIPY
, info
->var
.yres
);
871 sst_write(BLTDSTBASEADDR
, 0);
872 sst_write(BLTCOLOR
, rect
->color
);
873 sst_write(BLTROP
, rect
->rop
== ROP_COPY
? BLTROP_COPY
: BLTROP_XOR
);
874 sst_write(BLTXYSTRIDES
, stride
| (stride
<< 16));
875 sst_write(BLTDSTXY
, rect
->dx
| (rect
->dy
<< 16));
876 sst_write(BLTSIZE
, rect
->width
| (rect
->height
<< 16));
877 sst_write(BLTCOMMAND
, BLT_RECFILL_BITBLT
| LAUNCH_BITBLT
878 | (BLT_16BPP_FMT
<< 3) /* | BIT(14) */ | BIT(15) | BIT(16) );
887 static int __devinit
sst_get_memsize(struct fb_info
*info
, __u32
*memsize
)
889 u_long fbbase_virt
= (u_long
) info
->screen_base
;
892 if ((mem
>= 1 ) && (mem
<= 4)) {
893 *memsize
= (mem
* 0x100000);
894 iprintk("supplied memsize: %#x\n", *memsize
);
898 writel(0xdeadbeef, fbbase_virt
);
899 writel(0xdeadbeef, fbbase_virt
+0x100000);
900 writel(0xdeadbeef, fbbase_virt
+0x200000);
901 f_ddprintk("0MB: %#x, 1MB: %#x, 2MB: %#x\n",
902 readl(fbbase_virt
), readl(fbbase_virt
+ 0x100000),
903 readl(fbbase_virt
+ 0x200000));
905 writel(0xabcdef01, fbbase_virt
);
907 f_ddprintk("0MB: %#x, 1MB: %#x, 2MB: %#x\n",
908 readl(fbbase_virt
), readl(fbbase_virt
+ 0x100000),
909 readl(fbbase_virt
+ 0x200000));
911 /* checks for 4mb lfb, then 2, then defaults to 1 */
912 if (readl(fbbase_virt
+ 0x200000) == 0xdeadbeef)
914 else if (readl(fbbase_virt
+ 0x100000) == 0xdeadbeef)
918 f_ddprintk("detected memsize: %dMB\n", *memsize
>> 20);
924 * DAC detection routines
927 /* fbi should be idle, and fifo emty and mem disabled */
928 /* supposed to detect AT&T ATT20C409 and Ti TVP3409 ramdacs */
930 static int __devinit
sst_detect_att(struct fb_info
*info
)
932 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
935 for (i
=0; i
<3; i
++) {
936 sst_dac_write(DACREG_WMA
, 0); /* backdoor */
937 sst_dac_read(DACREG_RMR
); /* read 4 times RMR */
938 sst_dac_read(DACREG_RMR
);
939 sst_dac_read(DACREG_RMR
);
940 sst_dac_read(DACREG_RMR
);
941 /* the fifth time, CR0 is read */
942 sst_dac_read(DACREG_RMR
);
943 /* the 6th, manufacturer id register */
944 mir
= sst_dac_read(DACREG_RMR
);
945 /*the 7th, device ID register */
946 dir
= sst_dac_read(DACREG_RMR
);
947 f_ddprintk("mir: %#x, dir: %#x\n", mir
, dir
);
948 if ((mir
== DACREG_MIR_ATT
) && (dir
== DACREG_DIR_ATT
)) {
955 static int __devinit
sst_detect_ti(struct fb_info
*info
)
957 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
960 for (i
= 0; i
<3; i
++) {
961 sst_dac_write(DACREG_WMA
, 0); /* backdoor */
962 sst_dac_read(DACREG_RMR
); /* read 4 times RMR */
963 sst_dac_read(DACREG_RMR
);
964 sst_dac_read(DACREG_RMR
);
965 sst_dac_read(DACREG_RMR
);
966 /* the fifth time, CR0 is read */
967 sst_dac_read(DACREG_RMR
);
968 /* the 6th, manufacturer id register */
969 mir
= sst_dac_read(DACREG_RMR
);
970 /*the 7th, device ID register */
971 dir
= sst_dac_read(DACREG_RMR
);
972 f_ddprintk("mir: %#x, dir: %#x\n", mir
, dir
);
973 if ((mir
== DACREG_MIR_TI
) && (dir
== DACREG_DIR_TI
)) {
981 * try to detect ICS5342 ramdac
982 * we get the 1st byte (M value) of preset f1,f7 and fB
983 * why those 3 ? mmmh... for now, i'll do it the glide way...
984 * and ask questions later. anyway, it seems that all the freq registers are
985 * realy at their default state (cf specs) so i ask again, why those 3 regs ?
986 * mmmmh.. it seems that's much more ugly than i thought. we use f0 and fA for
987 * pll programming, so in fact, we *hope* that the f1, f7 & fB won't be
989 * is it realy safe ? how can i reset this ramdac ? geee...
991 static int __devinit
sst_detect_ics(struct fb_info
*info
)
993 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
994 int m_clk0_1
, m_clk0_7
, m_clk1_b
;
995 int n_clk0_1
, n_clk0_7
, n_clk1_b
;
998 for (i
= 0; i
<5; i
++ ) {
999 sst_dac_write(DACREG_ICS_PLLRMA
, 0x1); /* f1 */
1000 m_clk0_1
= sst_dac_read(DACREG_ICS_PLLDATA
);
1001 n_clk0_1
= sst_dac_read(DACREG_ICS_PLLDATA
);
1002 sst_dac_write(DACREG_ICS_PLLRMA
, 0x7); /* f7 */
1003 m_clk0_7
= sst_dac_read(DACREG_ICS_PLLDATA
);
1004 n_clk0_7
= sst_dac_read(DACREG_ICS_PLLDATA
);
1005 sst_dac_write(DACREG_ICS_PLLRMA
, 0xb); /* fB */
1006 m_clk1_b
= sst_dac_read(DACREG_ICS_PLLDATA
);
1007 n_clk1_b
= sst_dac_read(DACREG_ICS_PLLDATA
);
1008 f_ddprintk("m_clk0_1: %#x, m_clk0_7: %#x, m_clk1_b: %#x\n",
1009 m_clk0_1
, m_clk0_7
, m_clk1_b
);
1010 f_ddprintk("n_clk0_1: %#x, n_clk0_7: %#x, n_clk1_b: %#x\n",
1011 n_clk0_1
, n_clk0_7
, n_clk1_b
);
1012 if (( m_clk0_1
== DACREG_ICS_PLL_CLK0_1_INI
)
1013 && (m_clk0_7
== DACREG_ICS_PLL_CLK0_7_INI
)
1014 && (m_clk1_b
== DACREG_ICS_PLL_CLK1_B_INI
)) {
1023 * gfx, video, pci fifo should be reset, dram refresh disabled
1027 static int sst_set_pll_att_ti(struct fb_info
*info
,
1028 const struct pll_timing
*t
, const int clock
)
1030 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
1033 /* enable indexed mode */
1034 sst_dac_write(DACREG_WMA
, 0); /* backdoor */
1035 sst_dac_read(DACREG_RMR
); /* 1 time: RMR */
1036 sst_dac_read(DACREG_RMR
); /* 2 RMR */
1037 sst_dac_read(DACREG_RMR
); /* 3 // */
1038 sst_dac_read(DACREG_RMR
); /* 4 // */
1039 cr0
= sst_dac_read(DACREG_RMR
); /* 5 CR0 */
1041 sst_dac_write(DACREG_WMA
, 0);
1042 sst_dac_read(DACREG_RMR
);
1043 sst_dac_read(DACREG_RMR
);
1044 sst_dac_read(DACREG_RMR
);
1045 sst_dac_read(DACREG_RMR
);
1046 sst_dac_write(DACREG_RMR
, (cr0
& 0xf0)
1047 | DACREG_CR0_EN_INDEXED
1049 | DACREG_CR0_PWDOWN
);
1050 /* so, now we are in indexed mode . dunno if its common, but
1051 i find this way of doing things a little bit weird :p */
1054 cc
= dac_i_read(DACREG_CC_I
);
1057 dac_i_write(DACREG_AC0_I
, t
->m
);
1058 dac_i_write(DACREG_AC1_I
, t
->p
<< 6 | t
->n
);
1059 dac_i_write(DACREG_CC_I
,
1060 (cc
& 0x0f) | DACREG_CC_CLKA
| DACREG_CC_CLKA_C
);
1063 dac_i_write(DACREG_BD0_I
, t
->m
);
1064 dac_i_write(DACREG_BD1_I
, t
->p
<< 6 | t
->n
);
1065 dac_i_write(DACREG_CC_I
,
1066 (cc
& 0xf0) | DACREG_CC_CLKB
| DACREG_CC_CLKB_D
);
1069 dprintk("%s: wrong clock code '%d'\n",
1070 __FUNCTION__
, clock
);
1075 /* power up the dac & return to "normal" non-indexed mode */
1076 dac_i_write(DACREG_CR0_I
,
1077 cr0
& ~DACREG_CR0_PWDOWN
& ~DACREG_CR0_EN_INDEXED
);
1081 static int sst_set_pll_ics(struct fb_info
*info
,
1082 const struct pll_timing
*t
, const int clock
)
1084 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
1087 sst_dac_write(DACREG_ICS_PLLRMA
, DACREG_ICS_PLL_CTRL
);
1088 pll_ctrl
= sst_dac_read(DACREG_ICS_PLLDATA
);
1091 sst_dac_write(DACREG_ICS_PLLWMA
, 0x0); /* CLK0, f0 */
1092 sst_dac_write(DACREG_ICS_PLLDATA
, t
->m
);
1093 sst_dac_write(DACREG_ICS_PLLDATA
, t
->p
<< 5 | t
->n
);
1094 /* selects freq f0 for clock 0 */
1095 sst_dac_write(DACREG_ICS_PLLWMA
, DACREG_ICS_PLL_CTRL
);
1096 sst_dac_write(DACREG_ICS_PLLDATA
,
1099 | DACREG_ICS_CLK0_0
);
1102 sst_dac_write(DACREG_ICS_PLLWMA
, 0xa); /* CLK1, fA */
1103 sst_dac_write(DACREG_ICS_PLLDATA
, t
->m
);
1104 sst_dac_write(DACREG_ICS_PLLDATA
, t
->p
<< 5 | t
->n
);
1105 /* selects freq fA for clock 1 */
1106 sst_dac_write(DACREG_ICS_PLLWMA
, DACREG_ICS_PLL_CTRL
);
1107 sst_dac_write(DACREG_ICS_PLLDATA
,
1108 (pll_ctrl
& 0xef) | DACREG_ICS_CLK1_A
);
1111 dprintk("%s: wrong clock code '%d'\n",
1112 __FUNCTION__
, clock
);
1119 static void sst_set_vidmod_att_ti(struct fb_info
*info
, const int bpp
)
1121 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
1124 sst_dac_write(DACREG_WMA
, 0); /* backdoor */
1125 sst_dac_read(DACREG_RMR
); /* read 4 times RMR */
1126 sst_dac_read(DACREG_RMR
);
1127 sst_dac_read(DACREG_RMR
);
1128 sst_dac_read(DACREG_RMR
);
1129 /* the fifth time, CR0 is read */
1130 cr0
= sst_dac_read(DACREG_RMR
);
1132 sst_dac_write(DACREG_WMA
, 0); /* backdoor */
1133 sst_dac_read(DACREG_RMR
); /* read 4 times RMR */
1134 sst_dac_read(DACREG_RMR
);
1135 sst_dac_read(DACREG_RMR
);
1136 sst_dac_read(DACREG_RMR
);
1140 sst_dac_write(DACREG_RMR
, (cr0
& 0x0f) | DACREG_CR0_16BPP
);
1145 sst_dac_write(DACREG_RMR
, (cr0
& 0x0f) | DACREG_CR0_24BPP
);
1149 dprintk("%s: bad depth '%u'\n", __FUNCTION__
, bpp
);
1154 static void sst_set_vidmod_ics(struct fb_info
*info
, const int bpp
)
1156 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
1160 sst_dac_write(DACREG_ICS_CMD
, DACREG_ICS_CMD_16BPP
);
1165 sst_dac_write(DACREG_ICS_CMD
, DACREG_ICS_CMD_24BPP
);
1169 dprintk("%s: bad depth '%u'\n", __FUNCTION__
, bpp
);
1176 * prerequisite : write to FbiInitx enabled, video and fbi and pci fifo reset,
1177 * dram refresh disabled, FbiInit remaped.
1178 * TODO: mmh.. maybe i shoud put the "prerequisite" in the func ...
1182 static struct dac_switch dacs
[] __devinitdata
= {
1183 { .name
= "TI TVP3409",
1184 .detect
= sst_detect_ti
,
1185 .set_pll
= sst_set_pll_att_ti
,
1186 .set_vidmod
= sst_set_vidmod_att_ti
},
1188 { .name
= "AT&T ATT20C409",
1189 .detect
= sst_detect_att
,
1190 .set_pll
= sst_set_pll_att_ti
,
1191 .set_vidmod
= sst_set_vidmod_att_ti
},
1192 { .name
= "ICS ICS5342",
1193 .detect
= sst_detect_ics
,
1194 .set_pll
= sst_set_pll_ics
,
1195 .set_vidmod
= sst_set_vidmod_ics
},
1198 static int __devinit
sst_detect_dactype(struct fb_info
*info
, struct sstfb_par
*par
)
1202 for (i
=0; i
<sizeof(dacs
)/sizeof(dacs
[0]); i
++) {
1203 ret
= dacs
[i
].detect(info
);
1208 f_dprintk("%s found %s\n", __FUNCTION__
, dacs
[i
].name
);
1209 par
->dac_sw
= dacs
[i
];
1216 static int __devinit
sst_init(struct fb_info
*info
, struct sstfb_par
*par
)
1218 u32 fbiinit0
, fbiinit1
, fbiinit4
;
1219 struct pci_dev
*dev
= par
->dev
;
1220 struct pll_timing gfx_timings
;
1221 struct sst_spec
*spec
;
1224 spec
= &voodoo_spec
[par
->type
];
1225 f_ddprintk(" fbiinit0 fbiinit1 fbiinit2 fbiinit3 fbiinit4 "
1227 f_ddprintk("%0#10x %0#10x %0#10x %0#10x %0#10x %0#10x\n",
1228 sst_read(FBIINIT0
), sst_read(FBIINIT1
), sst_read(FBIINIT2
),
1229 sst_read(FBIINIT3
), sst_read(FBIINIT4
), sst_read(FBIINIT6
));
1230 /* disable video clock */
1231 pci_write_config_dword(dev
, PCI_VCLK_DISABLE
, 0);
1233 /* enable writing to init registers, disable pci fifo */
1234 pci_write_config_dword(dev
, PCI_INIT_ENABLE
, PCI_EN_INIT_WR
);
1236 sst_set_bits(FBIINIT1
, VIDEO_RESET
);
1238 /* reset gfx + pci fifo */
1239 sst_set_bits(FBIINIT0
, FBI_RESET
| FIFO_RESET
);
1243 /*sst_unset_bits(FBIINIT0, FIFO_RESET);
1246 /*sst_unset_bits(FBIINIT0, FBI_RESET);
1249 /* disable dram refresh */
1250 sst_unset_bits(FBIINIT2
, EN_DRAM_REFRESH
);
1252 /* remap fbinit2/3 to dac */
1253 pci_write_config_dword(dev
, PCI_INIT_ENABLE
,
1254 PCI_EN_INIT_WR
| PCI_REMAP_DAC
);
1255 /* detect dac type */
1256 if (!sst_detect_dactype(info
, par
)) {
1257 eprintk("Unknown dac type\n");
1258 //FIXME watch it: we are not in a safe state, bad bad bad.
1262 /* set graphic clock */
1263 par
->gfx_clock
= spec
->default_gfx_clock
;
1264 if ((gfxclk
>10 ) && (gfxclk
< spec
->max_gfxclk
)) {
1265 iprintk("Using supplied graphic freq : %dMHz\n", gfxclk
);
1266 par
->gfx_clock
= gfxclk
*1000;
1267 } else if (gfxclk
) {
1268 wprintk ("%dMhz is way out of spec! Using default\n", gfxclk
);
1271 sst_calc_pll(par
->gfx_clock
, &Fout
, &gfx_timings
);
1272 par
->dac_sw
.set_pll(info
, &gfx_timings
, GFX_CLOCK
);
1274 /* disable fbiinit remap */
1275 pci_write_config_dword(dev
, PCI_INIT_ENABLE
,
1276 PCI_EN_INIT_WR
| PCI_EN_FIFO_WR
);
1277 /* defaults init registers */
1278 /* FbiInit0: unreset gfx, unreset fifo */
1279 fbiinit0
= FBIINIT0_DEFAULT
;
1280 fbiinit1
= FBIINIT1_DEFAULT
;
1281 fbiinit4
= FBIINIT4_DEFAULT
;
1283 fbiinit0
&= ~EN_VGA_PASSTHROUGH
;
1285 fbiinit0
|= EN_VGA_PASSTHROUGH
;
1287 fbiinit1
|= SLOW_PCI_WRITES
;
1288 fbiinit4
|= SLOW_PCI_READS
;
1290 fbiinit1
&= ~SLOW_PCI_WRITES
;
1291 fbiinit4
&= ~SLOW_PCI_READS
;
1293 sst_write(FBIINIT0
, fbiinit0
);
1295 sst_write(FBIINIT1
, fbiinit1
);
1297 sst_write(FBIINIT2
, FBIINIT2_DEFAULT
);
1299 sst_write(FBIINIT3
, FBIINIT3_DEFAULT
);
1301 sst_write(FBIINIT4
, fbiinit4
);
1303 if (IS_VOODOO2(par
)) {
1304 sst_write(FBIINIT6
, FBIINIT6_DEFAULT
);
1308 pci_write_config_dword(dev
, PCI_INIT_ENABLE
, PCI_EN_FIFO_WR
);
1309 pci_write_config_dword(dev
, PCI_VCLK_ENABLE
, 0);
1313 static void __devexit
sst_shutdown(struct fb_info
*info
)
1315 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
1316 struct pci_dev
*dev
= par
->dev
;
1317 struct pll_timing gfx_timings
;
1320 /* reset video, gfx, fifo, disable dram + remap fbiinit2/3 */
1321 pci_write_config_dword(dev
, PCI_INIT_ENABLE
, PCI_EN_INIT_WR
);
1322 sst_set_bits(FBIINIT1
, VIDEO_RESET
| EN_BLANKING
);
1323 sst_unset_bits(FBIINIT2
, EN_DRAM_REFRESH
);
1324 sst_set_bits(FBIINIT0
, FBI_RESET
| FIFO_RESET
);
1326 pci_write_config_dword(dev
, PCI_INIT_ENABLE
,
1327 PCI_EN_INIT_WR
| PCI_REMAP_DAC
);
1328 /* set 20Mhz gfx clock */
1329 sst_calc_pll(20000, &Fout
, &gfx_timings
);
1330 par
->dac_sw
.set_pll(info
, &gfx_timings
, GFX_CLOCK
);
1331 /* TODO maybe shutdown the dac, vrefresh and so on... */
1332 pci_write_config_dword(dev
, PCI_INIT_ENABLE
,
1334 sst_unset_bits(FBIINIT0
, FBI_RESET
| FIFO_RESET
| EN_VGA_PASSTHROUGH
);
1335 pci_write_config_dword(dev
, PCI_VCLK_DISABLE
,0);
1336 /* maybe keep fbiinit* and PCI_INIT_enable in the fb_info struct
1338 pci_write_config_dword(dev
, PCI_INIT_ENABLE
, 0);
1343 * Interface to the world
1346 int __init
sstfb_setup(char *options
)
1350 if (!options
|| !*options
)
1353 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1354 if (!*this_opt
) continue;
1356 f_ddprintk("option %s\n", this_opt
);
1358 if (!strcmp(this_opt
, "vganopass"))
1360 else if (!strcmp(this_opt
, "vgapass"))
1362 else if (!strcmp(this_opt
, "clipping"))
1364 else if (!strcmp(this_opt
, "noclipping"))
1366 else if (!strcmp(this_opt
, "fastpci"))
1368 else if (!strcmp(this_opt
, "slowpci"))
1370 else if (!strncmp(this_opt
, "mem:",4))
1371 mem
= simple_strtoul (this_opt
+4, NULL
, 0);
1372 else if (!strncmp(this_opt
, "gfxclk:",7))
1373 gfxclk
= simple_strtoul (this_opt
+7, NULL
, 0);
1375 mode_option
= this_opt
;
1380 static struct fb_ops sstfb_ops
= {
1381 .owner
= THIS_MODULE
,
1382 .fb_check_var
= sstfb_check_var
,
1383 .fb_set_par
= sstfb_set_par
,
1384 .fb_setcolreg
= sstfb_setcolreg
,
1385 .fb_fillrect
= cfb_fillrect
, /* sstfb_fillrect */
1386 .fb_copyarea
= cfb_copyarea
, /* sstfb_copyarea */
1387 .fb_imageblit
= cfb_imageblit
,
1388 .fb_cursor
= soft_cursor
,
1389 .fb_ioctl
= sstfb_ioctl
,
1392 static int __devinit
sstfb_probe(struct pci_dev
*pdev
,
1393 const struct pci_device_id
*id
)
1395 struct fb_info
*info
;
1396 struct fb_fix_screeninfo
*fix
;
1397 struct sstfb_par
*par
;
1398 struct sst_spec
*spec
;
1402 struct fb_info info
;
1403 struct sstfb_par par
;
1404 u32 pseudo_palette
[16];
1407 /* Enable device in PCI config. */
1408 if ((err
=pci_enable_device(pdev
))) {
1409 eprintk("cannot enable device\n");
1413 /* Allocate the fb and par structures. */
1414 all
= kmalloc(sizeof(*all
), GFP_KERNEL
);
1417 memset(all
, 0, sizeof(*all
));
1418 pci_set_drvdata(pdev
, all
);
1421 par
= info
->par
= &all
->par
;
1424 par
->type
= id
->driver_data
;
1425 spec
= &voodoo_spec
[par
->type
];
1426 f_ddprintk("found device : %s\n", spec
->name
);
1429 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &par
->revision
);
1431 fix
->mmio_start
= pci_resource_start(pdev
,0);
1432 fix
->mmio_len
= 0x400000;
1433 fix
->smem_start
= fix
->mmio_start
+ 0x400000;
1435 if (!request_mem_region(fix
->mmio_start
, fix
->mmio_len
, "sstfb MMIO")) {
1436 eprintk("cannot reserve mmio memory\n");
1440 if (!request_mem_region(fix
->smem_start
, 0x400000,"sstfb FB")) {
1441 eprintk("cannot reserve fb memory\n");
1445 par
->mmio_vbase
= (u_long
) ioremap_nocache(fix
->mmio_start
,
1447 if (!par
->mmio_vbase
) {
1448 eprintk("cannot remap register area %#lx\n",
1450 goto fail_mmio_remap
;
1452 info
->screen_base
= ioremap_nocache(fix
->smem_start
, 0x400000);
1453 if (!info
->screen_base
) {
1454 eprintk("cannot remap framebuffer %#lx\n",
1459 if (!sst_init(info
, par
)) {
1460 eprintk("Init failed\n");
1463 sst_get_memsize(info
, &fix
->smem_len
);
1464 strlcpy(fix
->id
, spec
->name
, sizeof(fix
->id
));
1466 iprintk("%s (revision %d) with %s dac\n",
1467 fix
->id
, par
->revision
, par
->dac_sw
.name
);
1468 iprintk("framebuffer at %#lx, mapped to 0x%p, size %dMB\n",
1469 fix
->smem_start
, info
->screen_base
,
1470 fix
->smem_len
>> 20);
1472 f_ddprintk("regbase_virt: %#lx\n", par
->mmio_vbase
);
1473 f_ddprintk("membase_phys: %#lx\n", fix
->smem_start
);
1474 f_ddprintk("fbbase_virt: %p\n", info
->screen_base
);
1476 info
->flags
= FBINFO_DEFAULT
;
1477 info
->fbops
= &sstfb_ops
;
1479 info
->pseudo_palette
= &all
->pseudo_palette
;
1481 fix
->type
= FB_TYPE_PACKED_PIXELS
;
1482 fix
->visual
= FB_VISUAL_TRUECOLOR
;
1483 fix
->accel
= FB_ACCEL_NONE
; /* FIXME */
1485 * According to the specs, the linelength must be of 1024 *pixels*
1486 * and the 24bpp mode is in fact a 32 bpp mode.
1488 fix
->line_length
= 2048; /* default value, for 24 or 32bit: 4096 */
1491 fb_find_mode(&info
->var
, info
, mode_option
, NULL
, 0, NULL
, 16)) {
1492 eprintk("can't set supplied video mode. Using default\n");
1493 info
->var
= sstfb_default
;
1495 info
->var
= sstfb_default
;
1497 if (sstfb_check_var(&info
->var
, info
)) {
1498 eprintk("invalid default video mode.\n");
1502 if (sstfb_set_par(info
)) {
1503 eprintk("can't set default video mode.\n");
1507 fb_alloc_cmap(&info
->cmap
, 256, 0);
1510 if (register_framebuffer(info
) < 0) {
1511 eprintk("can't register framebuffer.\n");
1515 if (1) /* set to 0 to see an initial bitmap instead */
1516 sstfb_clear_screen(info
);
1518 sstfb_drawdebugimage(info
);
1520 printk(KERN_INFO
"fb%d: %s frame buffer device at 0x%p\n",
1521 info
->node
, fix
->id
, info
->screen_base
);
1526 iounmap(info
->screen_base
);
1528 iounmap((void *)par
->mmio_vbase
);
1530 release_mem_region(fix
->smem_start
, 0x400000);
1532 release_mem_region(fix
->mmio_start
, info
->fix
.mmio_len
);
1535 return -ENXIO
; /* no voodoo detected */
1538 static void __devexit
sstfb_remove(struct pci_dev
*pdev
)
1540 struct sstfb_par
*par
;
1541 struct fb_info
*info
;
1543 info
= pci_get_drvdata(pdev
);
1544 par
= (struct sstfb_par
*) info
->par
;
1547 unregister_framebuffer(info
);
1548 iounmap(info
->screen_base
);
1549 iounmap((void*)par
->mmio_vbase
);
1550 release_mem_region(info
->fix
.smem_start
, 0x400000);
1551 release_mem_region(info
->fix
.mmio_start
, info
->fix
.mmio_len
);
1556 static struct pci_device_id sstfb_id_tbl
[] = {
1557 { PCI_VENDOR_ID_3DFX
, PCI_DEVICE_ID_3DFX_VOODOO
,
1558 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, ID_VOODOO1
},
1559 { PCI_VENDOR_ID_3DFX
, PCI_DEVICE_ID_3DFX_VOODOO2
,
1560 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, ID_VOODOO2
},
1564 static struct pci_driver sstfb_driver
= {
1566 .id_table
= sstfb_id_tbl
,
1567 .probe
= sstfb_probe
,
1568 .remove
= __devexit_p(sstfb_remove
),
1572 int __devinit
sstfb_init(void)
1575 char *option
= NULL
;
1577 if (fb_get_options("sstfb", &option
))
1579 sstfb_setup(option
);
1581 return pci_module_init(&sstfb_driver
);
1584 void __devexit
sstfb_exit(void)
1586 pci_unregister_driver(&sstfb_driver
);
1591 * testing and debugging functions
1594 static int sstfb_dump_regs(struct fb_info
*info
)
1597 static struct { u32 reg
; const char *reg_name
;} pci_regs
[] = {
1598 { PCI_INIT_ENABLE
, "initenable"},
1599 { PCI_VCLK_ENABLE
, "enable vclk"},
1600 { PCI_VCLK_DISABLE
, "disable vclk"},
1603 static struct { u32 reg
; const char *reg_name
;} sst_regs
[] = {
1604 {FBIINIT0
,"fbiinit0"},
1605 {FBIINIT1
,"fbiinit1"},
1606 {FBIINIT2
,"fbiinit2"},
1607 {FBIINIT3
,"fbiinit3"},
1608 {FBIINIT4
,"fbiinit4"},
1609 {FBIINIT5
,"fbiinit5"},
1610 {FBIINIT6
,"fbiinit6"},
1611 {FBIINIT7
,"fbiinit7"},
1612 {LFBMODE
,"lfbmode"},
1613 {FBZMODE
,"fbzmode"},
1616 const int pci_s
= sizeof(pci_regs
)/sizeof(pci_regs
[0]);
1617 const int sst_s
= sizeof(sst_regs
)/sizeof(sst_regs
[0]);
1618 struct sstfb_par
*par
= (struct sstfb_par
*) info
->par
;
1619 struct pci_dev
*dev
= par
->dev
;
1624 for (i
=0; i
<pci_s
; i
++) {
1625 pci_read_config_dword(dev
, pci_regs
[i
].reg
, &pci_res
[i
]);
1627 for (i
=0; i
<sst_s
; i
++) {
1628 sst_res
[i
] = sst_read(sst_regs
[i
].reg
);
1631 dprintk("hardware register dump:\n");
1632 for (i
=0; i
<pci_s
; i
++) {
1633 dprintk("%s %0#10x\n", pci_regs
[i
].reg_name
, pci_res
[i
]);
1635 for (i
=0; i
<sst_s
; i
++) {
1636 dprintk("%s %0#10x\n", sst_regs
[i
].reg_name
, sst_res
[i
]);
1644 static void sstfb_fillrect_softw( struct fb_info
*info
, const struct fb_fillrect
*rect
)
1646 unsigned long fbbase_virt
= (unsigned long) info
->screen_base
;
1647 int x
, y
, w
= info
->var
.bits_per_pixel
== 16 ? 2 : 4;
1648 u32 color
= rect
->color
, height
= rect
->height
;
1651 if (w
==2) color
|= color
<<16;
1652 for (y
=rect
->dy
; height
; y
++, height
--) {
1653 p
= fbbase_virt
+ y
*info
->fix
.line_length
+ rect
->dx
*w
;
1664 static void sstfb_drawrect_XY( struct fb_info
*info
, int x
, int y
,
1665 int w
, int h
, int color
, int hwfunc
)
1667 struct fb_fillrect rect
;
1673 rect
.rop
= ROP_COPY
;
1675 sstfb_fillrect(info
, &rect
);
1677 sstfb_fillrect_softw(info
, &rect
);
1680 /* print some squares on the fb */
1681 static void sstfb_drawdebugimage(struct fb_info
*info
)
1686 sstfb_clear_screen(info
);
1691 sstfb_drawrect_XY(info
, 0, 0, 50, 50, 0xffff, idx
);
1694 sstfb_drawrect_XY(info
, 50, 50, 50, 50, 0x001f, idx
);
1697 sstfb_drawrect_XY(info
, 100, 100, 80, 80, 0x07e0, idx
);
1700 sstfb_drawrect_XY(info
, 250, 250, 120, 100, 0xf800, idx
);
1703 module_init(sstfb_init
);
1706 module_exit(sstfb_exit
);
1709 MODULE_AUTHOR("(c) 2000,2002 Ghozlane Toumi <gtoumi@laposte.net>");
1710 MODULE_DESCRIPTION("FBDev driver for 3dfx Voodoo Graphics and Voodoo2 based video boards");
1711 MODULE_LICENSE("GPL");
1713 MODULE_PARM(mem
, "i");
1714 MODULE_PARM_DESC(mem
, "Size of frame buffer memory in MB (1, 2, 4 MB, default=autodetect)");
1715 MODULE_PARM(vgapass
, "i");
1716 MODULE_PARM_DESC(vgapass
, "Enable VGA PassThrough mode (0 or 1) (default=0)");
1717 MODULE_PARM(clipping
, "i");
1718 MODULE_PARM_DESC(clipping
, "Enable clipping (slower, safer) (0 or 1) (default=1)");
1719 MODULE_PARM(gfxclk
, "i");
1720 MODULE_PARM_DESC(gfxclk
, "Force graphic chip frequency in MHz. DANGEROUS. (default=auto)");
1721 MODULE_PARM(slowpci
, "i");
1722 MODULE_PARM_DESC(slowpci
, "Uses slow PCI settings (0 or 1) (default=0)");