]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * | |
3 | * tdfxfb.c | |
4 | * | |
5 | * Author: Hannu Mallat <[email protected]> | |
6 | * | |
3cbe9cff | 7 | * Copyright © 1999 Hannu Mallat |
1da177e4 LT |
8 | * All rights reserved |
9 | * | |
10 | * Created : Thu Sep 23 18:17:43 1999, hmallat | |
11 | * Last modified: Tue Nov 2 21:19:47 1999, hmallat | |
12 | * | |
8af1d50f | 13 | * Lots of the information here comes from the Daryll Strauss' Banshee |
1da177e4 LT |
14 | * patches to the XF86 server, and the rest comes from the 3dfx |
15 | * Banshee specification. I'm very much indebted to Daryll for his | |
16 | * work on the X server. | |
17 | * | |
18 | * Voodoo3 support was contributed Harold Oga. Lots of additions | |
19 | * (proper acceleration, 24 bpp, hardware cursor) and bug fixes by Attila | |
20 | * Kesmarki. Thanks guys! | |
21 | * | |
22 | * Voodoo1 and Voodoo2 support aren't relevant to this driver as they | |
23 | * behave very differently from the Voodoo3/4/5. For anyone wanting to | |
24 | * use frame buffer on the Voodoo1/2, see the sstfb driver (which is | |
25 | * located at http://www.sourceforge.net/projects/sstfb). | |
8af1d50f | 26 | * |
1da177e4 LT |
27 | * While I _am_ grateful to 3Dfx for releasing the specs for Banshee, |
28 | * I do wish the next version is a bit more complete. Without the XF86 | |
29 | * patches I couldn't have gotten even this far... for instance, the | |
30 | * extensions to the VGA register set go completely unmentioned in the | |
31 | * spec! Also, lots of references are made to the 'SST core', but no | |
32 | * spec is publicly available, AFAIK. | |
33 | * | |
34 | * The structure of this driver comes pretty much from the Permedia | |
35 | * driver by Ilario Nardinocchi, which in turn is based on skeletonfb. | |
8af1d50f | 36 | * |
1da177e4 | 37 | * TODO: |
1da177e4 LT |
38 | * - multihead support (basically need to support an array of fb_infos) |
39 | * - support other architectures (PPC, Alpha); does the fact that the VGA | |
40 | * core can be accessed only thru I/O (not memory mapped) complicate | |
41 | * things? | |
42 | * | |
43 | * Version history: | |
44 | * | |
3cbe9cff | 45 | * 0.1.4 (released 2002-05-28) ported over to new fbdev api by James Simmons |
1da177e4 | 46 | * |
3cbe9cff KH |
47 | * 0.1.3 (released 1999-11-02) added Attila's panning support, code |
48 | * reorg, hwcursor address page size alignment | |
49 | * (for mmaping both frame buffer and regs), | |
50 | * and my changes to get rid of hardcoded | |
51 | * VGA i/o register locations (uses PCI | |
52 | * configuration info now) | |
53 | * 0.1.2 (released 1999-10-19) added Attila Kesmarki's bug fixes and | |
54 | * improvements | |
55 | * 0.1.1 (released 1999-10-07) added Voodoo3 support by Harold Oga. | |
56 | * 0.1.0 (released 1999-10-06) initial version | |
1da177e4 LT |
57 | * |
58 | */ | |
59 | ||
1da177e4 LT |
60 | #include <linux/module.h> |
61 | #include <linux/kernel.h> | |
62 | #include <linux/errno.h> | |
63 | #include <linux/string.h> | |
64 | #include <linux/mm.h> | |
1da177e4 | 65 | #include <linux/slab.h> |
1da177e4 LT |
66 | #include <linux/fb.h> |
67 | #include <linux/init.h> | |
68 | #include <linux/pci.h> | |
1da177e4 | 69 | #include <asm/io.h> |
1da177e4 LT |
70 | |
71 | #include <video/tdfx.h> | |
72 | ||
5ae12170 | 73 | #define DPRINTK(a, b...) pr_debug("fb: %s: " a, __func__ , ## b) |
1da177e4 | 74 | |
0960bd3d KH |
75 | #ifdef CONFIG_MTRR |
76 | #include <asm/mtrr.h> | |
77 | #else | |
78 | /* duplicate asm/mtrr.h defines to work on archs without mtrr */ | |
79 | #define MTRR_TYPE_WRCOMB 1 | |
80 | ||
81 | static inline int mtrr_add(unsigned long base, unsigned long size, | |
82 | unsigned int type, char increment) | |
83 | { | |
84 | return -ENODEV; | |
85 | } | |
86 | static inline int mtrr_del(int reg, unsigned long base, | |
87 | unsigned long size) | |
88 | { | |
89 | return -ENODEV; | |
90 | } | |
91 | #endif | |
92 | ||
1da177e4 LT |
93 | #define BANSHEE_MAX_PIXCLOCK 270000 |
94 | #define VOODOO3_MAX_PIXCLOCK 300000 | |
95 | #define VOODOO5_MAX_PIXCLOCK 350000 | |
96 | ||
97 | static struct fb_fix_screeninfo tdfx_fix __devinitdata = { | |
98 | .id = "3Dfx", | |
99 | .type = FB_TYPE_PACKED_PIXELS, | |
8af1d50f | 100 | .visual = FB_VISUAL_PSEUDOCOLOR, |
1da177e4 | 101 | .ypanstep = 1, |
8af1d50f | 102 | .ywrapstep = 1, |
1da177e4 LT |
103 | .accel = FB_ACCEL_3DFX_BANSHEE |
104 | }; | |
105 | ||
106 | static struct fb_var_screeninfo tdfx_var __devinitdata = { | |
107 | /* "640x480, 8 bpp @ 60 Hz */ | |
108 | .xres = 640, | |
109 | .yres = 480, | |
110 | .xres_virtual = 640, | |
111 | .yres_virtual = 1024, | |
8af1d50f | 112 | .bits_per_pixel = 8, |
1da177e4 LT |
113 | .red = {0, 8, 0}, |
114 | .blue = {0, 8, 0}, | |
115 | .green = {0, 8, 0}, | |
116 | .activate = FB_ACTIVATE_NOW, | |
117 | .height = -1, | |
118 | .width = -1, | |
119 | .accel_flags = FB_ACCELF_TEXT, | |
120 | .pixclock = 39722, | |
121 | .left_margin = 40, | |
122 | .right_margin = 24, | |
123 | .upper_margin = 32, | |
124 | .lower_margin = 11, | |
125 | .hsync_len = 96, | |
126 | .vsync_len = 2, | |
127 | .vmode = FB_VMODE_NONINTERLACED | |
128 | }; | |
129 | ||
130 | /* | |
131 | * PCI driver prototypes | |
132 | */ | |
133 | static int __devinit tdfxfb_probe(struct pci_dev *pdev, | |
134 | const struct pci_device_id *id); | |
135 | static void __devexit tdfxfb_remove(struct pci_dev *pdev); | |
136 | ||
137 | static struct pci_device_id tdfxfb_id_table[] = { | |
138 | { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_BANSHEE, | |
139 | PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, | |
140 | 0xff0000, 0 }, | |
141 | { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO3, | |
142 | PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, | |
143 | 0xff0000, 0 }, | |
144 | { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO5, | |
145 | PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, | |
146 | 0xff0000, 0 }, | |
147 | { 0, } | |
148 | }; | |
149 | ||
150 | static struct pci_driver tdfxfb_driver = { | |
151 | .name = "tdfxfb", | |
8af1d50f KH |
152 | .id_table = tdfxfb_id_table, |
153 | .probe = tdfxfb_probe, | |
154 | .remove = __devexit_p(tdfxfb_remove), | |
1da177e4 LT |
155 | }; |
156 | ||
157 | MODULE_DEVICE_TABLE(pci, tdfxfb_id_table); | |
158 | ||
159 | /* | |
8af1d50f | 160 | * Driver data |
1da177e4 | 161 | */ |
90b0f085 KH |
162 | static int nopan; |
163 | static int nowrap = 1; /* not implemented (yet) */ | |
164 | static int hwcursor = 1; | |
0960bd3d KH |
165 | static char *mode_option __devinitdata; |
166 | /* mtrr option */ | |
167 | static int nomtrr __devinitdata; | |
1da177e4 | 168 | |
8af1d50f | 169 | /* ------------------------------------------------------------------------- |
3cbe9cff | 170 | * Hardware-specific funcions |
1da177e4 LT |
171 | * ------------------------------------------------------------------------- */ |
172 | ||
8af1d50f KH |
173 | static inline u8 vga_inb(struct tdfx_par *par, u32 reg) |
174 | { | |
175 | return inb(par->iobase + reg - 0x300); | |
1da177e4 | 176 | } |
4f05b53b | 177 | |
8af1d50f KH |
178 | static inline void vga_outb(struct tdfx_par *par, u32 reg, u8 val) |
179 | { | |
180 | outb(val, par->iobase + reg - 0x300); | |
1da177e4 | 181 | } |
1da177e4 | 182 | |
8af1d50f KH |
183 | static inline void gra_outb(struct tdfx_par *par, u32 idx, u8 val) |
184 | { | |
185 | vga_outb(par, GRA_I, idx); | |
254c9471 | 186 | wmb(); |
8af1d50f | 187 | vga_outb(par, GRA_D, val); |
254c9471 | 188 | wmb(); |
1da177e4 LT |
189 | } |
190 | ||
8af1d50f KH |
191 | static inline void seq_outb(struct tdfx_par *par, u32 idx, u8 val) |
192 | { | |
193 | vga_outb(par, SEQ_I, idx); | |
254c9471 | 194 | wmb(); |
8af1d50f | 195 | vga_outb(par, SEQ_D, val); |
254c9471 | 196 | wmb(); |
1da177e4 LT |
197 | } |
198 | ||
8af1d50f KH |
199 | static inline u8 seq_inb(struct tdfx_par *par, u32 idx) |
200 | { | |
201 | vga_outb(par, SEQ_I, idx); | |
254c9471 | 202 | mb(); |
8af1d50f | 203 | return vga_inb(par, SEQ_D); |
1da177e4 LT |
204 | } |
205 | ||
8af1d50f KH |
206 | static inline void crt_outb(struct tdfx_par *par, u32 idx, u8 val) |
207 | { | |
208 | vga_outb(par, CRT_I, idx); | |
254c9471 | 209 | wmb(); |
8af1d50f | 210 | vga_outb(par, CRT_D, val); |
254c9471 | 211 | wmb(); |
1da177e4 LT |
212 | } |
213 | ||
8af1d50f KH |
214 | static inline u8 crt_inb(struct tdfx_par *par, u32 idx) |
215 | { | |
216 | vga_outb(par, CRT_I, idx); | |
254c9471 | 217 | mb(); |
8af1d50f | 218 | return vga_inb(par, CRT_D); |
1da177e4 LT |
219 | } |
220 | ||
8af1d50f | 221 | static inline void att_outb(struct tdfx_par *par, u32 idx, u8 val) |
1da177e4 LT |
222 | { |
223 | unsigned char tmp; | |
8af1d50f | 224 | |
1da177e4 LT |
225 | tmp = vga_inb(par, IS1_R); |
226 | vga_outb(par, ATT_IW, idx); | |
227 | vga_outb(par, ATT_IW, val); | |
228 | } | |
229 | ||
230 | static inline void vga_disable_video(struct tdfx_par *par) | |
231 | { | |
232 | unsigned char s; | |
233 | ||
234 | s = seq_inb(par, 0x01) | 0x20; | |
235 | seq_outb(par, 0x00, 0x01); | |
236 | seq_outb(par, 0x01, s); | |
237 | seq_outb(par, 0x00, 0x03); | |
238 | } | |
239 | ||
240 | static inline void vga_enable_video(struct tdfx_par *par) | |
241 | { | |
242 | unsigned char s; | |
243 | ||
244 | s = seq_inb(par, 0x01) & 0xdf; | |
245 | seq_outb(par, 0x00, 0x01); | |
246 | seq_outb(par, 0x01, s); | |
247 | seq_outb(par, 0x00, 0x03); | |
248 | } | |
249 | ||
250 | static inline void vga_enable_palette(struct tdfx_par *par) | |
251 | { | |
252 | vga_inb(par, IS1_R); | |
254c9471 | 253 | mb(); |
1da177e4 LT |
254 | vga_outb(par, ATT_IW, 0x20); |
255 | } | |
256 | ||
8af1d50f | 257 | static inline u32 tdfx_inl(struct tdfx_par *par, unsigned int reg) |
1da177e4 LT |
258 | { |
259 | return readl(par->regbase_virt + reg); | |
260 | } | |
261 | ||
262 | static inline void tdfx_outl(struct tdfx_par *par, unsigned int reg, u32 val) | |
263 | { | |
264 | writel(val, par->regbase_virt + reg); | |
265 | } | |
266 | ||
267 | static inline void banshee_make_room(struct tdfx_par *par, int size) | |
268 | { | |
269 | /* Note: The Voodoo3's onboard FIFO has 32 slots. This loop | |
270 | * won't quit if you ask for more. */ | |
f67fd7c1 KH |
271 | while ((tdfx_inl(par, STATUS) & 0x1f) < size - 1) |
272 | cpu_relax(); | |
1da177e4 | 273 | } |
3cbe9cff | 274 | |
1da177e4 LT |
275 | static int banshee_wait_idle(struct fb_info *info) |
276 | { | |
a807f618 | 277 | struct tdfx_par *par = info->par; |
1da177e4 LT |
278 | int i = 0; |
279 | ||
280 | banshee_make_room(par, 1); | |
281 | tdfx_outl(par, COMMAND_3D, COMMAND_3D_NOP); | |
282 | ||
4f05b53b | 283 | do { |
3cbe9cff KH |
284 | if ((tdfx_inl(par, STATUS) & STATUS_BUSY) == 0) |
285 | i++; | |
4f05b53b KH |
286 | } while (i < 3); |
287 | ||
1da177e4 LT |
288 | return 0; |
289 | } | |
290 | ||
291 | /* | |
8af1d50f | 292 | * Set the color of a palette entry in 8bpp mode |
1da177e4 LT |
293 | */ |
294 | static inline void do_setpalentry(struct tdfx_par *par, unsigned regno, u32 c) | |
3cbe9cff | 295 | { |
1da177e4 LT |
296 | banshee_make_room(par, 2); |
297 | tdfx_outl(par, DACADDR, regno); | |
254c9471 KH |
298 | /* read after write makes it working */ |
299 | tdfx_inl(par, DACADDR); | |
1da177e4 LT |
300 | tdfx_outl(par, DACDATA, c); |
301 | } | |
302 | ||
8af1d50f | 303 | static u32 do_calc_pll(int freq, int *freq_out) |
1da177e4 | 304 | { |
0fbe9caf | 305 | int m, n, k, best_m, best_n, best_k, best_error; |
1da177e4 | 306 | int fref = 14318; |
8af1d50f | 307 | |
1da177e4 LT |
308 | best_error = freq; |
309 | best_n = best_m = best_k = 0; | |
0fbe9caf RD |
310 | |
311 | for (k = 3; k >= 0; k--) { | |
312 | for (m = 63; m >= 0; m--) { | |
313 | /* | |
314 | * Estimate value of n that produces target frequency | |
315 | * with current m and k | |
316 | */ | |
4f05b53b | 317 | int n_estimated = ((freq * (m + 2) << k) / fref) - 2; |
0fbe9caf RD |
318 | |
319 | /* Search neighborhood of estimated n */ | |
4f05b53b KH |
320 | for (n = max(0, n_estimated); |
321 | n <= min(255, n_estimated + 1); | |
322 | n++) { | |
0fbe9caf RD |
323 | /* |
324 | * Calculate PLL freqency with current m, k and | |
325 | * estimated n | |
326 | */ | |
4f05b53b | 327 | int f = (fref * (n + 2) / (m + 2)) >> k; |
8af1d50f | 328 | int error = abs(f - freq); |
0fbe9caf RD |
329 | |
330 | /* | |
8af1d50f | 331 | * If this is the closest we've come to the |
0fbe9caf RD |
332 | * target frequency then remember n, m and k |
333 | */ | |
8af1d50f | 334 | if (error < best_error) { |
0fbe9caf | 335 | best_error = error; |
8af1d50f KH |
336 | best_n = n; |
337 | best_m = m; | |
338 | best_k = k; | |
1da177e4 LT |
339 | } |
340 | } | |
341 | } | |
342 | } | |
0fbe9caf | 343 | |
1da177e4 LT |
344 | n = best_n; |
345 | m = best_m; | |
346 | k = best_k; | |
4f05b53b | 347 | *freq_out = (fref * (n + 2) / (m + 2)) >> k; |
0fbe9caf | 348 | |
1da177e4 LT |
349 | return (n << 8) | (m << 2) | k; |
350 | } | |
351 | ||
8af1d50f | 352 | static void do_write_regs(struct fb_info *info, struct banshee_reg *reg) |
1da177e4 | 353 | { |
a807f618 | 354 | struct tdfx_par *par = info->par; |
1da177e4 LT |
355 | int i; |
356 | ||
357 | banshee_wait_idle(info); | |
358 | ||
359 | tdfx_outl(par, MISCINIT1, tdfx_inl(par, MISCINIT1) | 0x01); | |
360 | ||
361 | crt_outb(par, 0x11, crt_inb(par, 0x11) & 0x7f); /* CRT unprotect */ | |
362 | ||
363 | banshee_make_room(par, 3); | |
8af1d50f KH |
364 | tdfx_outl(par, VGAINIT1, reg->vgainit1 & 0x001FFFFF); |
365 | tdfx_outl(par, VIDPROCCFG, reg->vidcfg & ~0x00000001); | |
1da177e4 LT |
366 | #if 0 |
367 | tdfx_outl(par, PLLCTRL1, reg->mempll); | |
368 | tdfx_outl(par, PLLCTRL2, reg->gfxpll); | |
369 | #endif | |
8af1d50f | 370 | tdfx_outl(par, PLLCTRL0, reg->vidpll); |
1da177e4 LT |
371 | |
372 | vga_outb(par, MISC_W, reg->misc[0x00] | 0x01); | |
373 | ||
374 | for (i = 0; i < 5; i++) | |
375 | seq_outb(par, i, reg->seq[i]); | |
376 | ||
377 | for (i = 0; i < 25; i++) | |
378 | crt_outb(par, i, reg->crt[i]); | |
379 | ||
380 | for (i = 0; i < 9; i++) | |
381 | gra_outb(par, i, reg->gra[i]); | |
382 | ||
383 | for (i = 0; i < 21; i++) | |
384 | att_outb(par, i, reg->att[i]); | |
385 | ||
386 | crt_outb(par, 0x1a, reg->ext[0]); | |
387 | crt_outb(par, 0x1b, reg->ext[1]); | |
388 | ||
389 | vga_enable_palette(par); | |
390 | vga_enable_video(par); | |
391 | ||
4f05b53b | 392 | banshee_make_room(par, 9); |
8af1d50f KH |
393 | tdfx_outl(par, VGAINIT0, reg->vgainit0); |
394 | tdfx_outl(par, DACMODE, reg->dacmode); | |
395 | tdfx_outl(par, VIDDESKSTRIDE, reg->stride); | |
90b0f085 | 396 | tdfx_outl(par, HWCURPATADDR, reg->curspataddr); |
8af1d50f KH |
397 | |
398 | tdfx_outl(par, VIDSCREENSIZE, reg->screensize); | |
399 | tdfx_outl(par, VIDDESKSTART, reg->startaddr); | |
400 | tdfx_outl(par, VIDPROCCFG, reg->vidcfg); | |
401 | tdfx_outl(par, VGAINIT1, reg->vgainit1); | |
402 | tdfx_outl(par, MISCINIT0, reg->miscinit0); | |
403 | ||
404 | banshee_make_room(par, 8); | |
4f05b53b KH |
405 | tdfx_outl(par, SRCBASE, reg->startaddr); |
406 | tdfx_outl(par, DSTBASE, reg->startaddr); | |
8af1d50f KH |
407 | tdfx_outl(par, COMMANDEXTRA_2D, 0); |
408 | tdfx_outl(par, CLIP0MIN, 0); | |
409 | tdfx_outl(par, CLIP0MAX, 0x0fff0fff); | |
410 | tdfx_outl(par, CLIP1MIN, 0); | |
411 | tdfx_outl(par, CLIP1MAX, 0x0fff0fff); | |
412 | tdfx_outl(par, SRCXY, 0); | |
1da177e4 LT |
413 | |
414 | banshee_wait_idle(info); | |
415 | } | |
416 | ||
8af1d50f | 417 | static unsigned long do_lfb_size(struct tdfx_par *par, unsigned short dev_id) |
1da177e4 | 418 | { |
4f05b53b KH |
419 | u32 draminit0 = tdfx_inl(par, DRAMINIT0); |
420 | u32 draminit1 = tdfx_inl(par, DRAMINIT1); | |
333f9817 | 421 | u32 miscinit1; |
4f05b53b | 422 | int num_chips = (draminit0 & DRAMINIT0_SGRAM_NUM) ? 8 : 4; |
333f9817 | 423 | int chip_size; /* in MB */ |
4f05b53b | 424 | int has_sgram = draminit1 & DRAMINIT1_MEM_SDRAM; |
8af1d50f | 425 | |
333f9817 RD |
426 | if (dev_id < PCI_DEVICE_ID_3DFX_VOODOO5) { |
427 | /* Banshee/Voodoo3 */ | |
8af1d50f | 428 | chip_size = 2; |
4f05b53b KH |
429 | if (has_sgram && (draminit0 & DRAMINIT0_SGRAM_TYPE)) |
430 | chip_size = 1; | |
1da177e4 LT |
431 | } else { |
432 | /* Voodoo4/5 */ | |
333f9817 | 433 | has_sgram = 0; |
4f05b53b KH |
434 | chip_size = draminit0 & DRAMINIT0_SGRAM_TYPE_MASK; |
435 | chip_size = 1 << (chip_size >> DRAMINIT0_SGRAM_TYPE_SHIFT); | |
333f9817 | 436 | } |
333f9817 RD |
437 | |
438 | /* disable block writes for SDRAM */ | |
1da177e4 | 439 | miscinit1 = tdfx_inl(par, MISCINIT1); |
333f9817 | 440 | miscinit1 |= has_sgram ? 0 : MISCINIT1_2DBLOCK_DIS; |
1da177e4 LT |
441 | miscinit1 |= MISCINIT1_CLUT_INV; |
442 | ||
8af1d50f | 443 | banshee_make_room(par, 1); |
1da177e4 | 444 | tdfx_outl(par, MISCINIT1, miscinit1); |
4f05b53b | 445 | return num_chips * chip_size * 1024l * 1024; |
1da177e4 LT |
446 | } |
447 | ||
448 | /* ------------------------------------------------------------------------- */ | |
449 | ||
8af1d50f | 450 | static int tdfxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
1da177e4 | 451 | { |
a807f618 | 452 | struct tdfx_par *par = info->par; |
1da177e4 LT |
453 | u32 lpitch; |
454 | ||
455 | if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 && | |
456 | var->bits_per_pixel != 24 && var->bits_per_pixel != 32) { | |
457 | DPRINTK("depth not supported: %u\n", var->bits_per_pixel); | |
458 | return -EINVAL; | |
459 | } | |
460 | ||
461 | if (var->xres != var->xres_virtual) | |
462 | var->xres_virtual = var->xres; | |
463 | ||
464 | if (var->yres > var->yres_virtual) | |
465 | var->yres_virtual = var->yres; | |
466 | ||
467 | if (var->xoffset) { | |
468 | DPRINTK("xoffset not supported\n"); | |
469 | return -EINVAL; | |
470 | } | |
90b0f085 | 471 | var->yoffset = 0; |
1da177e4 | 472 | |
3cbe9cff KH |
473 | /* |
474 | * Banshee doesn't support interlace, but Voodoo4/5 and probably | |
475 | * Voodoo3 do. | |
476 | * no direct information about device id now? | |
477 | * use max_pixclock for this... | |
478 | */ | |
1da177e4 | 479 | if (((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) && |
8af1d50f | 480 | (par->max_pixclock < VOODOO3_MAX_PIXCLOCK)) { |
1da177e4 LT |
481 | DPRINTK("interlace not supported\n"); |
482 | return -EINVAL; | |
483 | } | |
484 | ||
485 | var->xres = (var->xres + 15) & ~15; /* could sometimes be 8 */ | |
8af1d50f KH |
486 | lpitch = var->xres * ((var->bits_per_pixel + 7) >> 3); |
487 | ||
1da177e4 LT |
488 | if (var->xres < 320 || var->xres > 2048) { |
489 | DPRINTK("width not supported: %u\n", var->xres); | |
490 | return -EINVAL; | |
491 | } | |
8af1d50f | 492 | |
1da177e4 LT |
493 | if (var->yres < 200 || var->yres > 2048) { |
494 | DPRINTK("height not supported: %u\n", var->yres); | |
495 | return -EINVAL; | |
496 | } | |
8af1d50f | 497 | |
1da177e4 | 498 | if (lpitch * var->yres_virtual > info->fix.smem_len) { |
8af1d50f | 499 | var->yres_virtual = info->fix.smem_len / lpitch; |
1da177e4 LT |
500 | if (var->yres_virtual < var->yres) { |
501 | DPRINTK("no memory for screen (%ux%ux%u)\n", | |
8af1d50f KH |
502 | var->xres, var->yres_virtual, |
503 | var->bits_per_pixel); | |
1da177e4 LT |
504 | return -EINVAL; |
505 | } | |
506 | } | |
8af1d50f | 507 | |
1da177e4 | 508 | if (PICOS2KHZ(var->pixclock) > par->max_pixclock) { |
8af1d50f KH |
509 | DPRINTK("pixclock too high (%ldKHz)\n", |
510 | PICOS2KHZ(var->pixclock)); | |
1da177e4 LT |
511 | return -EINVAL; |
512 | } | |
513 | ||
92744dd5 KH |
514 | var->transp.offset = 0; |
515 | var->transp.length = 0; | |
8af1d50f KH |
516 | switch (var->bits_per_pixel) { |
517 | case 8: | |
3cbe9cff KH |
518 | var->red.length = 8; |
519 | var->red.offset = 0; | |
520 | var->green = var->red; | |
521 | var->blue = var->red; | |
8af1d50f KH |
522 | break; |
523 | case 16: | |
524 | var->red.offset = 11; | |
525 | var->red.length = 5; | |
526 | var->green.offset = 5; | |
527 | var->green.length = 6; | |
528 | var->blue.offset = 0; | |
529 | var->blue.length = 5; | |
530 | break; | |
531 | case 32: | |
92744dd5 KH |
532 | var->transp.offset = 24; |
533 | var->transp.length = 8; | |
8af1d50f | 534 | case 24: |
92744dd5 KH |
535 | var->red.offset = 16; |
536 | var->green.offset = 8; | |
537 | var->blue.offset = 0; | |
8af1d50f KH |
538 | var->red.length = var->green.length = var->blue.length = 8; |
539 | break; | |
1da177e4 | 540 | } |
3cbe9cff KH |
541 | var->width = -1; |
542 | var->height = -1; | |
8af1d50f | 543 | |
1da177e4 | 544 | var->accel_flags = FB_ACCELF_TEXT; |
8af1d50f KH |
545 | |
546 | DPRINTK("Checking graphics mode at %dx%d depth %d\n", | |
547 | var->xres, var->yres, var->bits_per_pixel); | |
1da177e4 LT |
548 | return 0; |
549 | } | |
550 | ||
551 | static int tdfxfb_set_par(struct fb_info *info) | |
552 | { | |
a807f618 | 553 | struct tdfx_par *par = info->par; |
4f05b53b KH |
554 | u32 hdispend = info->var.xres; |
555 | u32 hsyncsta = hdispend + info->var.right_margin; | |
556 | u32 hsyncend = hsyncsta + info->var.hsync_len; | |
557 | u32 htotal = hsyncend + info->var.left_margin; | |
1da177e4 LT |
558 | u32 hd, hs, he, ht, hbs, hbe; |
559 | u32 vd, vs, ve, vt, vbs, vbe; | |
560 | struct banshee_reg reg; | |
561 | int fout, freq; | |
4f05b53b KH |
562 | u32 wd; |
563 | u32 cpp = (info->var.bits_per_pixel + 7) >> 3; | |
8af1d50f | 564 | |
1da177e4 | 565 | memset(®, 0, sizeof(reg)); |
8af1d50f KH |
566 | |
567 | reg.vidcfg = VIDCFG_VIDPROC_ENABLE | VIDCFG_DESK_ENABLE | | |
568 | VIDCFG_CURS_X11 | | |
569 | ((cpp - 1) << VIDCFG_PIXFMT_SHIFT) | | |
570 | (cpp != 1 ? VIDCFG_CLUT_BYPASS : 0); | |
1da177e4 LT |
571 | |
572 | /* PLL settings */ | |
573 | freq = PICOS2KHZ(info->var.pixclock); | |
574 | ||
8af1d50f | 575 | reg.vidcfg &= ~VIDCFG_2X; |
1da177e4 | 576 | |
8af1d50f | 577 | if (freq > par->max_pixclock / 2) { |
1da177e4 LT |
578 | freq = freq > par->max_pixclock ? par->max_pixclock : freq; |
579 | reg.dacmode |= DACMODE_2X; | |
580 | reg.vidcfg |= VIDCFG_2X; | |
581 | hdispend >>= 1; | |
582 | hsyncsta >>= 1; | |
583 | hsyncend >>= 1; | |
584 | htotal >>= 1; | |
585 | } | |
8af1d50f | 586 | |
3cbe9cff KH |
587 | wd = (hdispend >> 3) - 1; |
588 | hd = wd; | |
1da177e4 LT |
589 | hs = (hsyncsta >> 3) - 1; |
590 | he = (hsyncend >> 3) - 1; | |
591 | ht = (htotal >> 3) - 1; | |
592 | hbs = hd; | |
593 | hbe = ht; | |
594 | ||
595 | if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { | |
3cbe9cff | 596 | vd = (info->var.yres << 1) - 1; |
1da177e4 LT |
597 | vs = vd + (info->var.lower_margin << 1); |
598 | ve = vs + (info->var.vsync_len << 1); | |
3cbe9cff | 599 | vt = ve + (info->var.upper_margin << 1) - 1; |
4f05b53b KH |
600 | reg.screensize = info->var.xres | (info->var.yres << 13); |
601 | reg.vidcfg |= VIDCFG_HALF_MODE; | |
602 | reg.crt[0x09] = 0x80; | |
1da177e4 | 603 | } else { |
3cbe9cff | 604 | vd = info->var.yres - 1; |
1da177e4 LT |
605 | vs = vd + info->var.lower_margin; |
606 | ve = vs + info->var.vsync_len; | |
3cbe9cff | 607 | vt = ve + info->var.upper_margin - 1; |
4f05b53b KH |
608 | reg.screensize = info->var.xres | (info->var.yres << 12); |
609 | reg.vidcfg &= ~VIDCFG_HALF_MODE; | |
1da177e4 | 610 | } |
3cbe9cff KH |
611 | vbs = vd; |
612 | vbe = vt; | |
8af1d50f | 613 | |
1da177e4 | 614 | /* this is all pretty standard VGA register stuffing */ |
8af1d50f | 615 | reg.misc[0x00] = 0x0f | |
1da177e4 LT |
616 | (info->var.xres < 400 ? 0xa0 : |
617 | info->var.xres < 480 ? 0x60 : | |
618 | info->var.xres < 768 ? 0xe0 : 0x20); | |
8af1d50f | 619 | |
1da177e4 LT |
620 | reg.gra[0x05] = 0x40; |
621 | reg.gra[0x06] = 0x05; | |
622 | reg.gra[0x07] = 0x0f; | |
623 | reg.gra[0x08] = 0xff; | |
624 | ||
625 | reg.att[0x00] = 0x00; | |
626 | reg.att[0x01] = 0x01; | |
627 | reg.att[0x02] = 0x02; | |
628 | reg.att[0x03] = 0x03; | |
629 | reg.att[0x04] = 0x04; | |
630 | reg.att[0x05] = 0x05; | |
631 | reg.att[0x06] = 0x06; | |
632 | reg.att[0x07] = 0x07; | |
633 | reg.att[0x08] = 0x08; | |
634 | reg.att[0x09] = 0x09; | |
635 | reg.att[0x0a] = 0x0a; | |
636 | reg.att[0x0b] = 0x0b; | |
637 | reg.att[0x0c] = 0x0c; | |
638 | reg.att[0x0d] = 0x0d; | |
639 | reg.att[0x0e] = 0x0e; | |
640 | reg.att[0x0f] = 0x0f; | |
641 | reg.att[0x10] = 0x41; | |
1da177e4 | 642 | reg.att[0x12] = 0x0f; |
1da177e4 LT |
643 | |
644 | reg.seq[0x00] = 0x03; | |
645 | reg.seq[0x01] = 0x01; /* fixme: clkdiv2? */ | |
646 | reg.seq[0x02] = 0x0f; | |
647 | reg.seq[0x03] = 0x00; | |
648 | reg.seq[0x04] = 0x0e; | |
649 | ||
650 | reg.crt[0x00] = ht - 4; | |
651 | reg.crt[0x01] = hd; | |
652 | reg.crt[0x02] = hbs; | |
653 | reg.crt[0x03] = 0x80 | (hbe & 0x1f); | |
654 | reg.crt[0x04] = hs; | |
8af1d50f | 655 | reg.crt[0x05] = ((hbe & 0x20) << 2) | (he & 0x1f); |
1da177e4 LT |
656 | reg.crt[0x06] = vt; |
657 | reg.crt[0x07] = ((vs & 0x200) >> 2) | | |
658 | ((vd & 0x200) >> 3) | | |
659 | ((vt & 0x200) >> 4) | 0x10 | | |
660 | ((vbs & 0x100) >> 5) | | |
8af1d50f KH |
661 | ((vs & 0x100) >> 6) | |
662 | ((vd & 0x100) >> 7) | | |
663 | ((vt & 0x100) >> 8); | |
4f05b53b | 664 | reg.crt[0x09] |= 0x40 | ((vbs & 0x200) >> 4); |
1da177e4 | 665 | reg.crt[0x10] = vs; |
8af1d50f | 666 | reg.crt[0x11] = (ve & 0x0f) | 0x20; |
1da177e4 LT |
667 | reg.crt[0x12] = vd; |
668 | reg.crt[0x13] = wd; | |
1da177e4 | 669 | reg.crt[0x15] = vbs; |
8af1d50f | 670 | reg.crt[0x16] = vbe + 1; |
1da177e4 LT |
671 | reg.crt[0x17] = 0xc3; |
672 | reg.crt[0x18] = 0xff; | |
8af1d50f | 673 | |
1da177e4 | 674 | /* Banshee's nonvga stuff */ |
8af1d50f KH |
675 | reg.ext[0x00] = (((ht & 0x100) >> 8) | |
676 | ((hd & 0x100) >> 6) | | |
1da177e4 | 677 | ((hbs & 0x100) >> 4) | |
8af1d50f KH |
678 | ((hbe & 0x40) >> 1) | |
679 | ((hs & 0x100) >> 2) | | |
680 | ((he & 0x20) << 2)); | |
681 | reg.ext[0x01] = (((vt & 0x400) >> 10) | | |
682 | ((vd & 0x400) >> 8) | | |
683 | ((vbs & 0x400) >> 6) | | |
684 | ((vbe & 0x400) >> 4)); | |
685 | ||
686 | reg.vgainit0 = VGAINIT0_8BIT_DAC | | |
1da177e4 LT |
687 | VGAINIT0_EXT_ENABLE | |
688 | VGAINIT0_WAKEUP_3C3 | | |
689 | VGAINIT0_ALT_READBACK | | |
690 | VGAINIT0_EXTSHIFTOUT; | |
691 | reg.vgainit1 = tdfx_inl(par, VGAINIT1) & 0x1fffff; | |
692 | ||
90b0f085 KH |
693 | if (hwcursor) |
694 | reg.curspataddr = info->fix.smem_len; | |
695 | ||
1da177e4 | 696 | reg.cursloc = 0; |
8af1d50f KH |
697 | |
698 | reg.cursc0 = 0; | |
1da177e4 | 699 | reg.cursc1 = 0xffffff; |
8af1d50f | 700 | |
1da177e4 | 701 | reg.stride = info->var.xres * cpp; |
4f05b53b KH |
702 | reg.startaddr = info->var.yoffset * reg.stride |
703 | + info->var.xoffset * cpp; | |
1da177e4 | 704 | |
1da177e4 LT |
705 | reg.vidpll = do_calc_pll(freq, &fout); |
706 | #if 0 | |
707 | reg.mempll = do_calc_pll(..., &fout); | |
708 | reg.gfxpll = do_calc_pll(..., &fout); | |
709 | #endif | |
710 | ||
1da177e4 LT |
711 | if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) |
712 | reg.vidcfg |= VIDCFG_INTERLACE; | |
713 | reg.miscinit0 = tdfx_inl(par, MISCINIT0); | |
714 | ||
715 | #if defined(__BIG_ENDIAN) | |
716 | switch (info->var.bits_per_pixel) { | |
8af1d50f KH |
717 | case 8: |
718 | case 24: | |
719 | reg.miscinit0 &= ~(1 << 30); | |
720 | reg.miscinit0 &= ~(1 << 31); | |
721 | break; | |
722 | case 16: | |
723 | reg.miscinit0 |= (1 << 30); | |
724 | reg.miscinit0 |= (1 << 31); | |
725 | break; | |
726 | case 32: | |
727 | reg.miscinit0 |= (1 << 30); | |
728 | reg.miscinit0 &= ~(1 << 31); | |
729 | break; | |
1da177e4 | 730 | } |
8af1d50f | 731 | #endif |
1da177e4 LT |
732 | do_write_regs(info, ®); |
733 | ||
734 | /* Now change fb_fix_screeninfo according to changes in par */ | |
4f05b53b | 735 | info->fix.line_length = reg.stride; |
8af1d50f | 736 | info->fix.visual = (info->var.bits_per_pixel == 8) |
1da177e4 LT |
737 | ? FB_VISUAL_PSEUDOCOLOR |
738 | : FB_VISUAL_TRUECOLOR; | |
8af1d50f KH |
739 | DPRINTK("Graphics mode is now set at %dx%d depth %d\n", |
740 | info->var.xres, info->var.yres, info->var.bits_per_pixel); | |
741 | return 0; | |
1da177e4 LT |
742 | } |
743 | ||
744 | /* A handy macro shamelessly pinched from matroxfb */ | |
3cbe9cff | 745 | #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16) |
1da177e4 | 746 | |
8af1d50f KH |
747 | static int tdfxfb_setcolreg(unsigned regno, unsigned red, unsigned green, |
748 | unsigned blue, unsigned transp, | |
749 | struct fb_info *info) | |
1da177e4 | 750 | { |
a807f618 | 751 | struct tdfx_par *par = info->par; |
1da177e4 | 752 | u32 rgbcol; |
8af1d50f KH |
753 | |
754 | if (regno >= info->cmap.len || regno > 255) | |
755 | return 1; | |
756 | ||
254c9471 KH |
757 | /* grayscale works only partially under directcolor */ |
758 | if (info->var.grayscale) { | |
759 | /* grayscale = 0.30*R + 0.59*G + 0.11*B */ | |
3cbe9cff KH |
760 | blue = (red * 77 + green * 151 + blue * 28) >> 8; |
761 | green = blue; | |
762 | red = blue; | |
254c9471 KH |
763 | } |
764 | ||
1da177e4 | 765 | switch (info->fix.visual) { |
54243cef | 766 | case FB_VISUAL_PSEUDOCOLOR: |
3cbe9cff KH |
767 | rgbcol = (((u32)red & 0xff00) << 8) | |
768 | (((u32)green & 0xff00) << 0) | | |
769 | (((u32)blue & 0xff00) >> 8); | |
54243cef AD |
770 | do_setpalentry(par, regno, rgbcol); |
771 | break; | |
772 | /* Truecolor has no hardware color palettes. */ | |
773 | case FB_VISUAL_TRUECOLOR: | |
774 | if (regno < 16) { | |
8af1d50f | 775 | rgbcol = (CNVT_TOHW(red, info->var.red.length) << |
a807f618 | 776 | info->var.red.offset) | |
8af1d50f | 777 | (CNVT_TOHW(green, info->var.green.length) << |
54243cef | 778 | info->var.green.offset) | |
8af1d50f | 779 | (CNVT_TOHW(blue, info->var.blue.length) << |
54243cef | 780 | info->var.blue.offset) | |
8af1d50f | 781 | (CNVT_TOHW(transp, info->var.transp.length) << |
54243cef AD |
782 | info->var.transp.offset); |
783 | par->palette[regno] = rgbcol; | |
784 | } | |
785 | ||
786 | break; | |
787 | default: | |
788 | DPRINTK("bad depth %u\n", info->var.bits_per_pixel); | |
789 | break; | |
1da177e4 | 790 | } |
54243cef | 791 | |
1da177e4 LT |
792 | return 0; |
793 | } | |
794 | ||
795 | /* 0 unblank, 1 blank, 2 no vsync, 3 no hsync, 4 off */ | |
796 | static int tdfxfb_blank(int blank, struct fb_info *info) | |
8af1d50f | 797 | { |
a807f618 | 798 | struct tdfx_par *par = info->par; |
4f05b53b KH |
799 | int vgablank = 1; |
800 | u32 dacmode = tdfx_inl(par, DACMODE); | |
1da177e4 | 801 | |
4f05b53b | 802 | dacmode &= ~(BIT(1) | BIT(3)); |
1da177e4 LT |
803 | |
804 | switch (blank) { | |
8af1d50f | 805 | case FB_BLANK_UNBLANK: /* Screen: On; HSync: On, VSync: On */ |
8af1d50f KH |
806 | vgablank = 0; |
807 | break; | |
808 | case FB_BLANK_NORMAL: /* Screen: Off; HSync: On, VSync: On */ | |
8af1d50f KH |
809 | break; |
810 | case FB_BLANK_VSYNC_SUSPEND: /* Screen: Off; HSync: On, VSync: Off */ | |
4f05b53b | 811 | dacmode |= BIT(3); |
8af1d50f KH |
812 | break; |
813 | case FB_BLANK_HSYNC_SUSPEND: /* Screen: Off; HSync: Off, VSync: On */ | |
4f05b53b | 814 | dacmode |= BIT(1); |
8af1d50f KH |
815 | break; |
816 | case FB_BLANK_POWERDOWN: /* Screen: Off; HSync: Off, VSync: Off */ | |
4f05b53b | 817 | dacmode |= BIT(1) | BIT(3); |
8af1d50f | 818 | break; |
1da177e4 LT |
819 | } |
820 | ||
8af1d50f | 821 | banshee_make_room(par, 1); |
1da177e4 | 822 | tdfx_outl(par, DACMODE, dacmode); |
8af1d50f | 823 | if (vgablank) |
1da177e4 LT |
824 | vga_disable_video(par); |
825 | else | |
826 | vga_enable_video(par); | |
827 | return 0; | |
828 | } | |
829 | ||
8af1d50f | 830 | /* |
1da177e4 | 831 | * Set the starting position of the visible screen to var->yoffset |
8af1d50f | 832 | */ |
1da177e4 | 833 | static int tdfxfb_pan_display(struct fb_var_screeninfo *var, |
8af1d50f | 834 | struct fb_info *info) |
1da177e4 | 835 | { |
a807f618 | 836 | struct tdfx_par *par = info->par; |
4f05b53b | 837 | u32 addr = var->yoffset * info->fix.line_length; |
1da177e4 | 838 | |
c2c12155 | 839 | if (nopan || var->xoffset) |
1da177e4 LT |
840 | return -EINVAL; |
841 | ||
1da177e4 LT |
842 | banshee_make_room(par, 1); |
843 | tdfx_outl(par, VIDDESKSTART, addr); | |
8af1d50f | 844 | |
1da177e4 LT |
845 | return 0; |
846 | } | |
847 | ||
848 | #ifdef CONFIG_FB_3DFX_ACCEL | |
849 | /* | |
8af1d50f | 850 | * FillRect 2D command (solidfill or invert (via ROP_XOR)) |
1da177e4 | 851 | */ |
8af1d50f KH |
852 | static void tdfxfb_fillrect(struct fb_info *info, |
853 | const struct fb_fillrect *rect) | |
1da177e4 | 854 | { |
a807f618 | 855 | struct tdfx_par *par = info->par; |
1da177e4 LT |
856 | u32 bpp = info->var.bits_per_pixel; |
857 | u32 stride = info->fix.line_length; | |
3cbe9cff | 858 | u32 fmt = stride | ((bpp + ((bpp == 8) ? 0 : 8)) << 13); |
1da177e4 | 859 | int tdfx_rop; |
92744dd5 KH |
860 | u32 dx = rect->dx; |
861 | u32 dy = rect->dy; | |
862 | u32 dstbase = 0; | |
8af1d50f KH |
863 | |
864 | if (rect->rop == ROP_COPY) | |
1da177e4 | 865 | tdfx_rop = TDFX_ROP_COPY; |
8af1d50f | 866 | else |
1da177e4 LT |
867 | tdfx_rop = TDFX_ROP_XOR; |
868 | ||
92744dd5 KH |
869 | /* asume always rect->height < 4096 */ |
870 | if (dy + rect->height > 4095) { | |
871 | dstbase = stride * dy; | |
872 | dy = 0; | |
873 | } | |
874 | /* asume always rect->width < 4096 */ | |
875 | if (dx + rect->width > 4095) { | |
876 | dstbase += dx * bpp >> 3; | |
877 | dx = 0; | |
878 | } | |
879 | banshee_make_room(par, 6); | |
8af1d50f | 880 | tdfx_outl(par, DSTFORMAT, fmt); |
1da177e4 | 881 | if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) { |
8af1d50f | 882 | tdfx_outl(par, COLORFORE, rect->color); |
1da177e4 | 883 | } else { /* FB_VISUAL_TRUECOLOR */ |
a807f618 | 884 | tdfx_outl(par, COLORFORE, par->palette[rect->color]); |
1da177e4 | 885 | } |
8af1d50f | 886 | tdfx_outl(par, COMMAND_2D, COMMAND_2D_FILLRECT | (tdfx_rop << 24)); |
92744dd5 | 887 | tdfx_outl(par, DSTBASE, dstbase); |
8af1d50f | 888 | tdfx_outl(par, DSTSIZE, rect->width | (rect->height << 16)); |
92744dd5 | 889 | tdfx_outl(par, LAUNCH_2D, dx | (dy << 16)); |
1da177e4 LT |
890 | } |
891 | ||
892 | /* | |
8af1d50f | 893 | * Screen-to-Screen BitBlt 2D command (for the bmove fb op.) |
1da177e4 | 894 | */ |
8af1d50f KH |
895 | static void tdfxfb_copyarea(struct fb_info *info, |
896 | const struct fb_copyarea *area) | |
1da177e4 | 897 | { |
a807f618 | 898 | struct tdfx_par *par = info->par; |
8af1d50f | 899 | u32 sx = area->sx, sy = area->sy, dx = area->dx, dy = area->dy; |
1da177e4 LT |
900 | u32 bpp = info->var.bits_per_pixel; |
901 | u32 stride = info->fix.line_length; | |
902 | u32 blitcmd = COMMAND_2D_S2S_BITBLT | (TDFX_ROP_COPY << 24); | |
8af1d50f | 903 | u32 fmt = stride | ((bpp + ((bpp == 8) ? 0 : 8)) << 13); |
92744dd5 KH |
904 | u32 dstbase = 0; |
905 | u32 srcbase = 0; | |
906 | ||
907 | /* asume always area->height < 4096 */ | |
908 | if (sy + area->height > 4095) { | |
909 | srcbase = stride * sy; | |
910 | sy = 0; | |
911 | } | |
912 | /* asume always area->width < 4096 */ | |
913 | if (sx + area->width > 4095) { | |
914 | srcbase += sx * bpp >> 3; | |
915 | sx = 0; | |
916 | } | |
917 | /* asume always area->height < 4096 */ | |
918 | if (dy + area->height > 4095) { | |
919 | dstbase = stride * dy; | |
920 | dy = 0; | |
921 | } | |
922 | /* asume always area->width < 4096 */ | |
923 | if (dx + area->width > 4095) { | |
924 | dstbase += dx * bpp >> 3; | |
925 | dx = 0; | |
926 | } | |
927 | ||
1da177e4 | 928 | if (area->sx <= area->dx) { |
3cbe9cff | 929 | /* -X */ |
1da177e4 LT |
930 | blitcmd |= BIT(14); |
931 | sx += area->width - 1; | |
932 | dx += area->width - 1; | |
933 | } | |
934 | if (area->sy <= area->dy) { | |
3cbe9cff | 935 | /* -Y */ |
1da177e4 LT |
936 | blitcmd |= BIT(15); |
937 | sy += area->height - 1; | |
938 | dy += area->height - 1; | |
939 | } | |
8af1d50f | 940 | |
92744dd5 | 941 | banshee_make_room(par, 8); |
1da177e4 | 942 | |
8af1d50f KH |
943 | tdfx_outl(par, SRCFORMAT, fmt); |
944 | tdfx_outl(par, DSTFORMAT, fmt); | |
945 | tdfx_outl(par, COMMAND_2D, blitcmd); | |
946 | tdfx_outl(par, DSTSIZE, area->width | (area->height << 16)); | |
947 | tdfx_outl(par, DSTXY, dx | (dy << 16)); | |
92744dd5 KH |
948 | tdfx_outl(par, SRCBASE, srcbase); |
949 | tdfx_outl(par, DSTBASE, dstbase); | |
8af1d50f | 950 | tdfx_outl(par, LAUNCH_2D, sx | (sy << 16)); |
1da177e4 LT |
951 | } |
952 | ||
8af1d50f | 953 | static void tdfxfb_imageblit(struct fb_info *info, const struct fb_image *image) |
1da177e4 | 954 | { |
a807f618 | 955 | struct tdfx_par *par = info->par; |
8af1d50f | 956 | int size = image->height * ((image->width * image->depth + 7) >> 3); |
1da177e4 LT |
957 | int fifo_free; |
958 | int i, stride = info->fix.line_length; | |
959 | u32 bpp = info->var.bits_per_pixel; | |
8af1d50f | 960 | u32 dstfmt = stride | ((bpp + ((bpp == 8) ? 0 : 8)) << 13); |
1da177e4 LT |
961 | u8 *chardata = (u8 *) image->data; |
962 | u32 srcfmt; | |
92744dd5 KH |
963 | u32 dx = image->dx; |
964 | u32 dy = image->dy; | |
965 | u32 dstbase = 0; | |
1da177e4 LT |
966 | |
967 | if (image->depth != 1) { | |
3cbe9cff KH |
968 | #ifdef BROKEN_CODE |
969 | banshee_make_room(par, 6 + ((size + 3) >> 2)); | |
970 | srcfmt = stride | ((bpp + ((bpp == 8) ? 0 : 8)) << 13) | | |
971 | 0x400000; | |
972 | #else | |
1da177e4 | 973 | cfb_imageblit(info, image); |
3cbe9cff | 974 | #endif |
1da177e4 | 975 | return; |
92744dd5 KH |
976 | } |
977 | banshee_make_room(par, 9); | |
978 | switch (info->fix.visual) { | |
979 | case FB_VISUAL_PSEUDOCOLOR: | |
980 | tdfx_outl(par, COLORFORE, image->fg_color); | |
981 | tdfx_outl(par, COLORBACK, image->bg_color); | |
982 | break; | |
983 | case FB_VISUAL_TRUECOLOR: | |
984 | default: | |
985 | tdfx_outl(par, COLORFORE, | |
986 | par->palette[image->fg_color]); | |
987 | tdfx_outl(par, COLORBACK, | |
988 | par->palette[image->bg_color]); | |
989 | } | |
1da177e4 | 990 | #ifdef __BIG_ENDIAN |
92744dd5 | 991 | srcfmt = 0x400000 | BIT(20); |
1da177e4 | 992 | #else |
92744dd5 | 993 | srcfmt = 0x400000; |
1da177e4 | 994 | #endif |
92744dd5 KH |
995 | /* asume always image->height < 4096 */ |
996 | if (dy + image->height > 4095) { | |
997 | dstbase = stride * dy; | |
998 | dy = 0; | |
999 | } | |
1000 | /* asume always image->width < 4096 */ | |
1001 | if (dx + image->width > 4095) { | |
1002 | dstbase += dx * bpp >> 3; | |
1003 | dx = 0; | |
8af1d50f | 1004 | } |
1da177e4 | 1005 | |
92744dd5 | 1006 | tdfx_outl(par, DSTBASE, dstbase); |
8af1d50f | 1007 | tdfx_outl(par, SRCXY, 0); |
92744dd5 | 1008 | tdfx_outl(par, DSTXY, dx | (dy << 16)); |
3cbe9cff KH |
1009 | tdfx_outl(par, COMMAND_2D, |
1010 | COMMAND_2D_H2S_BITBLT | (TDFX_ROP_COPY << 24)); | |
8af1d50f KH |
1011 | tdfx_outl(par, SRCFORMAT, srcfmt); |
1012 | tdfx_outl(par, DSTFORMAT, dstfmt); | |
1013 | tdfx_outl(par, DSTSIZE, image->width | (image->height << 16)); | |
1da177e4 LT |
1014 | |
1015 | /* A count of how many free FIFO entries we've requested. | |
1016 | * When this goes negative, we need to request more. */ | |
1017 | fifo_free = 0; | |
1018 | ||
8af1d50f KH |
1019 | /* Send four bytes at a time of data */ |
1020 | for (i = (size >> 2); i > 0; i--) { | |
1021 | if (--fifo_free < 0) { | |
1022 | fifo_free = 31; | |
1023 | banshee_make_room(par, fifo_free); | |
1da177e4 | 1024 | } |
3cbe9cff | 1025 | tdfx_outl(par, LAUNCH_2D, *(u32 *)chardata); |
8af1d50f KH |
1026 | chardata += 4; |
1027 | } | |
1da177e4 | 1028 | |
8af1d50f KH |
1029 | /* Send the leftovers now */ |
1030 | banshee_make_room(par, 3); | |
4f05b53b | 1031 | switch (size % 4) { |
8af1d50f KH |
1032 | case 0: |
1033 | break; | |
1034 | case 1: | |
1035 | tdfx_outl(par, LAUNCH_2D, *chardata); | |
1036 | break; | |
1037 | case 2: | |
3cbe9cff | 1038 | tdfx_outl(par, LAUNCH_2D, *(u16 *)chardata); |
8af1d50f KH |
1039 | break; |
1040 | case 3: | |
1041 | tdfx_outl(par, LAUNCH_2D, | |
3cbe9cff | 1042 | *(u16 *)chardata | (chardata[3] << 24)); |
8af1d50f | 1043 | break; |
1da177e4 LT |
1044 | } |
1045 | } | |
1046 | #endif /* CONFIG_FB_3DFX_ACCEL */ | |
1047 | ||
1da177e4 LT |
1048 | static int tdfxfb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
1049 | { | |
a807f618 | 1050 | struct tdfx_par *par = info->par; |
90b0f085 KH |
1051 | u32 vidcfg; |
1052 | ||
1053 | if (!hwcursor) | |
1054 | return -EINVAL; /* just to force soft_cursor() call */ | |
1055 | ||
1056 | /* Too large of a cursor or wrong bpp :-( */ | |
1057 | if (cursor->image.width > 64 || | |
1058 | cursor->image.height > 64 || | |
1059 | cursor->image.depth > 1) | |
1060 | return -EINVAL; | |
1061 | ||
1062 | vidcfg = tdfx_inl(par, VIDPROCCFG); | |
1063 | if (cursor->enable) | |
1064 | tdfx_outl(par, VIDPROCCFG, vidcfg | VIDCFG_HWCURSOR_ENABLE); | |
1065 | else | |
1066 | tdfx_outl(par, VIDPROCCFG, vidcfg & ~VIDCFG_HWCURSOR_ENABLE); | |
1da177e4 LT |
1067 | |
1068 | /* | |
8af1d50f | 1069 | * If the cursor is not be changed this means either we want the |
1da177e4 | 1070 | * current cursor state (if enable is set) or we want to query what |
8af1d50f KH |
1071 | * we can do with the cursor (if enable is not set) |
1072 | */ | |
1073 | if (!cursor->set) | |
1074 | return 0; | |
1da177e4 | 1075 | |
1da177e4 | 1076 | /* fix cursor color - XFree86 forgets to restore it properly */ |
90b0f085 KH |
1077 | if (cursor->set & FB_CUR_SETCMAP) { |
1078 | struct fb_cmap cmap = info->cmap; | |
1079 | u32 bg_idx = cursor->image.bg_color; | |
1080 | u32 fg_idx = cursor->image.fg_color; | |
1da177e4 LT |
1081 | unsigned long bg_color, fg_color; |
1082 | ||
90b0f085 KH |
1083 | fg_color = (((u32)cmap.red[fg_idx] & 0xff00) << 8) | |
1084 | (((u32)cmap.green[fg_idx] & 0xff00) << 0) | | |
1085 | (((u32)cmap.blue[fg_idx] & 0xff00) >> 8); | |
1086 | bg_color = (((u32)cmap.red[bg_idx] & 0xff00) << 8) | | |
1087 | (((u32)cmap.green[bg_idx] & 0xff00) << 0) | | |
1088 | (((u32)cmap.blue[bg_idx] & 0xff00) >> 8); | |
1da177e4 LT |
1089 | banshee_make_room(par, 2); |
1090 | tdfx_outl(par, HWCURC0, bg_color); | |
1091 | tdfx_outl(par, HWCURC1, fg_color); | |
1da177e4 LT |
1092 | } |
1093 | ||
90b0f085 KH |
1094 | if (cursor->set & FB_CUR_SETPOS) { |
1095 | int x = cursor->image.dx; | |
1096 | int y = cursor->image.dy - info->var.yoffset; | |
1da177e4 | 1097 | |
1da177e4 LT |
1098 | x += 63; |
1099 | y += 63; | |
1da177e4 LT |
1100 | banshee_make_room(par, 1); |
1101 | tdfx_outl(par, HWCURLOC, (y << 16) + x); | |
1da177e4 | 1102 | } |
90b0f085 | 1103 | if (cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE)) { |
1da177e4 | 1104 | /* |
8af1d50f | 1105 | * Voodoo 3 and above cards use 2 monochrome cursor patterns. |
1da177e4 LT |
1106 | * The reason is so the card can fetch 8 words at a time |
1107 | * and are stored on chip for use for the next 8 scanlines. | |
1108 | * This reduces the number of times for access to draw the | |
1109 | * cursor for each screen refresh. | |
1110 | * Each pattern is a bitmap of 64 bit wide and 64 bit high | |
90b0f085 | 1111 | * (total of 8192 bits or 1024 bytes). The two patterns are |
1da177e4 LT |
1112 | * stored in such a way that pattern 0 always resides in the |
1113 | * lower half (least significant 64 bits) of a 128 bit word | |
1114 | * and pattern 1 the upper half. If you examine the data of | |
1115 | * the cursor image the graphics card uses then from the | |
1116 | * begining you see line one of pattern 0, line one of | |
1117 | * pattern 1, line two of pattern 0, line two of pattern 1, | |
1118 | * etc etc. The linear stride for the cursor is always 16 bytes | |
1119 | * (128 bits) which is the maximum cursor width times two for | |
1120 | * the two monochrome patterns. | |
1121 | */ | |
90b0f085 KH |
1122 | u8 __iomem *cursorbase = info->screen_base + info->fix.smem_len; |
1123 | u8 *bitmap = (u8 *)cursor->image.data; | |
1124 | u8 *mask = (u8 *)cursor->mask; | |
1125 | int i; | |
1126 | ||
1127 | fb_memset(cursorbase, 0, 1024); | |
1128 | ||
1129 | for (i = 0; i < cursor->image.height; i++) { | |
1130 | int h = 0; | |
1131 | int j = (cursor->image.width + 7) >> 3; | |
1132 | ||
1133 | for (; j > 0; j--) { | |
1134 | u8 data = *mask ^ *bitmap; | |
1135 | if (cursor->rop == ROP_COPY) | |
1136 | data = *mask & *bitmap; | |
1137 | /* Pattern 0. Copy the cursor mask to it */ | |
1138 | fb_writeb(*mask, cursorbase + h); | |
1139 | mask++; | |
1140 | /* Pattern 1. Copy the cursor bitmap to it */ | |
1141 | fb_writeb(data, cursorbase + h + 8); | |
1142 | bitmap++; | |
1143 | h++; | |
1da177e4 | 1144 | } |
90b0f085 | 1145 | cursorbase += 16; |
1da177e4 LT |
1146 | } |
1147 | } | |
1da177e4 LT |
1148 | return 0; |
1149 | } | |
1da177e4 | 1150 | |
8af1d50f KH |
1151 | static struct fb_ops tdfxfb_ops = { |
1152 | .owner = THIS_MODULE, | |
1153 | .fb_check_var = tdfxfb_check_var, | |
1154 | .fb_set_par = tdfxfb_set_par, | |
1155 | .fb_setcolreg = tdfxfb_setcolreg, | |
1156 | .fb_blank = tdfxfb_blank, | |
1157 | .fb_pan_display = tdfxfb_pan_display, | |
1158 | .fb_sync = banshee_wait_idle, | |
90b0f085 | 1159 | .fb_cursor = tdfxfb_cursor, |
8af1d50f KH |
1160 | #ifdef CONFIG_FB_3DFX_ACCEL |
1161 | .fb_fillrect = tdfxfb_fillrect, | |
1162 | .fb_copyarea = tdfxfb_copyarea, | |
1163 | .fb_imageblit = tdfxfb_imageblit, | |
1164 | #else | |
1165 | .fb_fillrect = cfb_fillrect, | |
1166 | .fb_copyarea = cfb_copyarea, | |
1167 | .fb_imageblit = cfb_imageblit, | |
1168 | #endif | |
1169 | }; | |
1170 | ||
1da177e4 LT |
1171 | /** |
1172 | * tdfxfb_probe - Device Initializiation | |
1173 | * | |
1174 | * @pdev: PCI Device to initialize | |
1175 | * @id: PCI Device ID | |
1176 | * | |
1177 | * Initializes and allocates resources for PCI device @pdev. | |
1178 | * | |
1179 | */ | |
1180 | static int __devinit tdfxfb_probe(struct pci_dev *pdev, | |
8af1d50f | 1181 | const struct pci_device_id *id) |
1da177e4 LT |
1182 | { |
1183 | struct tdfx_par *default_par; | |
1184 | struct fb_info *info; | |
a807f618 | 1185 | int err, lpitch; |
1da177e4 | 1186 | |
3cbe9cff KH |
1187 | err = pci_enable_device(pdev); |
1188 | if (err) { | |
1189 | printk(KERN_ERR "tdfxfb: Can't enable pdev: %d\n", err); | |
1da177e4 LT |
1190 | return err; |
1191 | } | |
1192 | ||
a807f618 | 1193 | info = framebuffer_alloc(sizeof(struct tdfx_par), &pdev->dev); |
1da177e4 | 1194 | |
a807f618 AD |
1195 | if (!info) |
1196 | return -ENOMEM; | |
8af1d50f | 1197 | |
1da177e4 | 1198 | default_par = info->par; |
8af1d50f | 1199 | |
1da177e4 LT |
1200 | /* Configure the default fb_fix_screeninfo first */ |
1201 | switch (pdev->device) { | |
8af1d50f KH |
1202 | case PCI_DEVICE_ID_3DFX_BANSHEE: |
1203 | strcat(tdfx_fix.id, " Banshee"); | |
1204 | default_par->max_pixclock = BANSHEE_MAX_PIXCLOCK; | |
1205 | break; | |
1206 | case PCI_DEVICE_ID_3DFX_VOODOO3: | |
1207 | strcat(tdfx_fix.id, " Voodoo3"); | |
1208 | default_par->max_pixclock = VOODOO3_MAX_PIXCLOCK; | |
1209 | break; | |
1210 | case PCI_DEVICE_ID_3DFX_VOODOO5: | |
1211 | strcat(tdfx_fix.id, " Voodoo5"); | |
1212 | default_par->max_pixclock = VOODOO5_MAX_PIXCLOCK; | |
1213 | break; | |
1da177e4 LT |
1214 | } |
1215 | ||
1216 | tdfx_fix.mmio_start = pci_resource_start(pdev, 0); | |
1217 | tdfx_fix.mmio_len = pci_resource_len(pdev, 0); | |
92744dd5 KH |
1218 | if (!request_mem_region(tdfx_fix.mmio_start, tdfx_fix.mmio_len, |
1219 | "tdfx regbase")) { | |
3cbe9cff | 1220 | printk(KERN_ERR "tdfxfb: Can't reserve regbase\n"); |
92744dd5 KH |
1221 | goto out_err; |
1222 | } | |
1223 | ||
8af1d50f KH |
1224 | default_par->regbase_virt = |
1225 | ioremap_nocache(tdfx_fix.mmio_start, tdfx_fix.mmio_len); | |
1da177e4 | 1226 | if (!default_par->regbase_virt) { |
3cbe9cff KH |
1227 | printk(KERN_ERR "fb: Can't remap %s register area.\n", |
1228 | tdfx_fix.id); | |
92744dd5 | 1229 | goto out_err_regbase; |
8af1d50f | 1230 | } |
1da177e4 LT |
1231 | |
1232 | tdfx_fix.smem_start = pci_resource_start(pdev, 1); | |
3cbe9cff KH |
1233 | tdfx_fix.smem_len = do_lfb_size(default_par, pdev->device); |
1234 | if (!tdfx_fix.smem_len) { | |
1235 | printk(KERN_ERR "fb: Can't count %s memory.\n", tdfx_fix.id); | |
92744dd5 | 1236 | goto out_err_regbase; |
1da177e4 LT |
1237 | } |
1238 | ||
92744dd5 | 1239 | if (!request_mem_region(tdfx_fix.smem_start, |
8af1d50f | 1240 | pci_resource_len(pdev, 1), "tdfx smem")) { |
3cbe9cff | 1241 | printk(KERN_ERR "tdfxfb: Can't reserve smem\n"); |
92744dd5 | 1242 | goto out_err_regbase; |
1da177e4 LT |
1243 | } |
1244 | ||
8af1d50f | 1245 | info->screen_base = ioremap_nocache(tdfx_fix.smem_start, |
1da177e4 LT |
1246 | tdfx_fix.smem_len); |
1247 | if (!info->screen_base) { | |
3cbe9cff KH |
1248 | printk(KERN_ERR "fb: Can't remap %s framebuffer.\n", |
1249 | tdfx_fix.id); | |
92744dd5 | 1250 | goto out_err_screenbase; |
1da177e4 LT |
1251 | } |
1252 | ||
1253 | default_par->iobase = pci_resource_start(pdev, 2); | |
8af1d50f | 1254 | |
1da177e4 | 1255 | if (!request_region(pci_resource_start(pdev, 2), |
8af1d50f | 1256 | pci_resource_len(pdev, 2), "tdfx iobase")) { |
3cbe9cff | 1257 | printk(KERN_ERR "tdfxfb: Can't reserve iobase\n"); |
92744dd5 | 1258 | goto out_err_screenbase; |
1da177e4 LT |
1259 | } |
1260 | ||
3cbe9cff KH |
1261 | printk(KERN_INFO "fb: %s memory = %dK\n", tdfx_fix.id, |
1262 | tdfx_fix.smem_len >> 10); | |
1da177e4 | 1263 | |
0960bd3d KH |
1264 | default_par->mtrr_handle = -1; |
1265 | if (!nomtrr) | |
1266 | default_par->mtrr_handle = | |
1267 | mtrr_add(tdfx_fix.smem_start, tdfx_fix.smem_len, | |
1268 | MTRR_TYPE_WRCOMB, 1); | |
1269 | ||
1da177e4 LT |
1270 | tdfx_fix.ypanstep = nopan ? 0 : 1; |
1271 | tdfx_fix.ywrapstep = nowrap ? 0 : 1; | |
8af1d50f | 1272 | |
1da177e4 | 1273 | info->fbops = &tdfxfb_ops; |
8af1d50f | 1274 | info->fix = tdfx_fix; |
a807f618 | 1275 | info->pseudo_palette = default_par->palette; |
1da177e4 LT |
1276 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
1277 | #ifdef CONFIG_FB_3DFX_ACCEL | |
3cbe9cff | 1278 | info->flags |= FBINFO_HWACCEL_FILLRECT | |
92744dd5 KH |
1279 | FBINFO_HWACCEL_COPYAREA | |
1280 | FBINFO_HWACCEL_IMAGEBLIT | | |
1281 | FBINFO_READS_FAST; | |
1da177e4 | 1282 | #endif |
90b0f085 KH |
1283 | /* reserve 8192 bits for cursor */ |
1284 | /* the 2.4 driver says PAGE_MASK boundary is not enough for Voodoo4 */ | |
1285 | if (hwcursor) | |
1286 | info->fix.smem_len = (info->fix.smem_len - 1024) & | |
1287 | (PAGE_MASK << 1); | |
1da177e4 LT |
1288 | |
1289 | if (!mode_option) | |
1290 | mode_option = "640x480@60"; | |
8af1d50f KH |
1291 | |
1292 | err = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8); | |
1da177e4 LT |
1293 | if (!err || err == 4) |
1294 | info->var = tdfx_var; | |
1295 | ||
1296 | /* maximize virtual vertical length */ | |
1297 | lpitch = info->var.xres_virtual * ((info->var.bits_per_pixel + 7) >> 3); | |
8af1d50f | 1298 | info->var.yres_virtual = info->fix.smem_len / lpitch; |
1da177e4 | 1299 | if (info->var.yres_virtual < info->var.yres) |
92744dd5 | 1300 | goto out_err_iobase; |
1da177e4 LT |
1301 | |
1302 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { | |
3cbe9cff | 1303 | printk(KERN_ERR "tdfxfb: Can't allocate color map\n"); |
92744dd5 | 1304 | goto out_err_iobase; |
1da177e4 LT |
1305 | } |
1306 | ||
1307 | if (register_framebuffer(info) < 0) { | |
3cbe9cff | 1308 | printk(KERN_ERR "tdfxfb: can't register framebuffer\n"); |
1da177e4 | 1309 | fb_dealloc_cmap(&info->cmap); |
92744dd5 | 1310 | goto out_err_iobase; |
1da177e4 LT |
1311 | } |
1312 | /* | |
1313 | * Our driver data | |
1314 | */ | |
1315 | pci_set_drvdata(pdev, info); | |
8af1d50f | 1316 | return 0; |
1da177e4 | 1317 | |
92744dd5 | 1318 | out_err_iobase: |
0960bd3d KH |
1319 | if (default_par->mtrr_handle >= 0) |
1320 | mtrr_del(default_par->mtrr_handle, info->fix.smem_start, | |
1321 | info->fix.smem_len); | |
92744dd5 KH |
1322 | release_mem_region(pci_resource_start(pdev, 2), |
1323 | pci_resource_len(pdev, 2)); | |
1324 | out_err_screenbase: | |
1325 | if (info->screen_base) | |
1326 | iounmap(info->screen_base); | |
1327 | release_mem_region(tdfx_fix.smem_start, pci_resource_len(pdev, 1)); | |
1328 | out_err_regbase: | |
1da177e4 LT |
1329 | /* |
1330 | * Cleanup after anything that was remapped/allocated. | |
1331 | */ | |
1332 | if (default_par->regbase_virt) | |
1333 | iounmap(default_par->regbase_virt); | |
92744dd5 KH |
1334 | release_mem_region(tdfx_fix.mmio_start, tdfx_fix.mmio_len); |
1335 | out_err: | |
1da177e4 LT |
1336 | framebuffer_release(info); |
1337 | return -ENXIO; | |
1338 | } | |
1339 | ||
1340 | #ifndef MODULE | |
0ce85eb8 | 1341 | static void __init tdfxfb_setup(char *options) |
1da177e4 | 1342 | { |
8af1d50f | 1343 | char *this_opt; |
1da177e4 LT |
1344 | |
1345 | if (!options || !*options) | |
1346 | return; | |
1347 | ||
1348 | while ((this_opt = strsep(&options, ",")) != NULL) { | |
1349 | if (!*this_opt) | |
1350 | continue; | |
8af1d50f | 1351 | if (!strcmp(this_opt, "nopan")) { |
1da177e4 | 1352 | nopan = 1; |
8af1d50f | 1353 | } else if (!strcmp(this_opt, "nowrap")) { |
1da177e4 | 1354 | nowrap = 1; |
0960bd3d KH |
1355 | } else if (!strncmp(this_opt, "hwcursor=", 9)) { |
1356 | hwcursor = simple_strtoul(this_opt + 9, NULL, 0); | |
1357 | #ifdef CONFIG_MTRR | |
1358 | } else if (!strncmp(this_opt, "nomtrr", 6)) { | |
1359 | nomtrr = 1; | |
1360 | #endif | |
1da177e4 LT |
1361 | } else { |
1362 | mode_option = this_opt; | |
1363 | } | |
1364 | } | |
1365 | } | |
1366 | #endif | |
1367 | ||
1368 | /** | |
1369 | * tdfxfb_remove - Device removal | |
1370 | * | |
1371 | * @pdev: PCI Device to cleanup | |
1372 | * | |
1373 | * Releases all resources allocated during the course of the driver's | |
1374 | * lifetime for the PCI device @pdev. | |
1375 | * | |
1376 | */ | |
1377 | static void __devexit tdfxfb_remove(struct pci_dev *pdev) | |
1378 | { | |
1379 | struct fb_info *info = pci_get_drvdata(pdev); | |
a807f618 | 1380 | struct tdfx_par *par = info->par; |
1da177e4 LT |
1381 | |
1382 | unregister_framebuffer(info); | |
0960bd3d KH |
1383 | if (par->mtrr_handle >= 0) |
1384 | mtrr_del(par->mtrr_handle, info->fix.smem_start, | |
1385 | info->fix.smem_len); | |
1da177e4 LT |
1386 | iounmap(par->regbase_virt); |
1387 | iounmap(info->screen_base); | |
1388 | ||
1389 | /* Clean up after reserved regions */ | |
1390 | release_region(pci_resource_start(pdev, 2), | |
1391 | pci_resource_len(pdev, 2)); | |
1392 | release_mem_region(pci_resource_start(pdev, 1), | |
1393 | pci_resource_len(pdev, 1)); | |
1394 | release_mem_region(pci_resource_start(pdev, 0), | |
1395 | pci_resource_len(pdev, 0)); | |
1396 | pci_set_drvdata(pdev, NULL); | |
1397 | framebuffer_release(info); | |
1398 | } | |
1399 | ||
1400 | static int __init tdfxfb_init(void) | |
1401 | { | |
1402 | #ifndef MODULE | |
1403 | char *option = NULL; | |
1404 | ||
1405 | if (fb_get_options("tdfxfb", &option)) | |
1406 | return -ENODEV; | |
1407 | ||
1408 | tdfxfb_setup(option); | |
1409 | #endif | |
8af1d50f | 1410 | return pci_register_driver(&tdfxfb_driver); |
1da177e4 LT |
1411 | } |
1412 | ||
1413 | static void __exit tdfxfb_exit(void) | |
1414 | { | |
8af1d50f | 1415 | pci_unregister_driver(&tdfxfb_driver); |
1da177e4 LT |
1416 | } |
1417 | ||
1418 | MODULE_AUTHOR("Hannu Mallat <[email protected]>"); | |
1419 | MODULE_DESCRIPTION("3Dfx framebuffer device driver"); | |
1420 | MODULE_LICENSE("GPL"); | |
8af1d50f | 1421 | |
90b0f085 KH |
1422 | module_param(hwcursor, int, 0644); |
1423 | MODULE_PARM_DESC(hwcursor, "Enable hardware cursor " | |
1424 | "(1=enable, 0=disable, default=1)"); | |
ea9014bc KH |
1425 | module_param(mode_option, charp, 0); |
1426 | MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'"); | |
0960bd3d KH |
1427 | #ifdef CONFIG_MTRR |
1428 | module_param(nomtrr, bool, 0); | |
1429 | MODULE_PARM_DESC(nomtrr, "Disable MTRR support (default: enabled)"); | |
1430 | #endif | |
90b0f085 | 1431 | |
1da177e4 LT |
1432 | module_init(tdfxfb_init); |
1433 | module_exit(tdfxfb_exit); |