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