Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/savagefb.c -- S3 Savage Framebuffer Driver |
| 3 | * |
| 4 | * Copyright (c) 2001-2002 Denis Oliver Kropp <dok@directfb.org> |
| 5 | * Sven Neumann <neo@directfb.org> |
| 6 | * |
| 7 | * |
| 8 | * Card specific code is based on XFree86's savage driver. |
| 9 | * Framebuffer framework code is based on code of cyber2000fb and tdfxfb. |
| 10 | * |
| 11 | * This file is subject to the terms and conditions of the GNU General |
| 12 | * Public License. See the file COPYING in the main directory of this |
| 13 | * archive for more details. |
| 14 | * |
| 15 | * 0.4.0 (neo) |
| 16 | * - hardware accelerated clear and move |
| 17 | * |
| 18 | * 0.3.2 (dok) |
| 19 | * - wait for vertical retrace before writing to cr67 |
| 20 | * at the beginning of savagefb_set_par |
| 21 | * - use synchronization registers cr23 and cr26 |
| 22 | * |
| 23 | * 0.3.1 (dok) |
| 24 | * - reset 3D engine |
| 25 | * - don't return alpha bits for 32bit format |
| 26 | * |
| 27 | * 0.3.0 (dok) |
| 28 | * - added WaitIdle functions for all Savage types |
| 29 | * - do WaitIdle before mode switching |
| 30 | * - code cleanup |
| 31 | * |
| 32 | * 0.2.0 (dok) |
| 33 | * - first working version |
| 34 | * |
| 35 | * |
| 36 | * TODO |
| 37 | * - clock validations in decode_var |
| 38 | * |
| 39 | * BUGS |
| 40 | * - white margin on bootup |
| 41 | * |
| 42 | */ |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <linux/module.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/errno.h> |
| 47 | #include <linux/string.h> |
| 48 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/slab.h> |
| 50 | #include <linux/delay.h> |
| 51 | #include <linux/fb.h> |
| 52 | #include <linux/pci.h> |
| 53 | #include <linux/init.h> |
| 54 | #include <linux/console.h> |
| 55 | |
| 56 | #include <asm/io.h> |
| 57 | #include <asm/irq.h> |
| 58 | #include <asm/pgtable.h> |
| 59 | #include <asm/system.h> |
| 60 | #include <asm/uaccess.h> |
| 61 | |
| 62 | #ifdef CONFIG_MTRR |
| 63 | #include <asm/mtrr.h> |
| 64 | #endif |
| 65 | |
| 66 | #include "savagefb.h" |
| 67 | |
| 68 | |
| 69 | #define SAVAGEFB_VERSION "0.4.0_2.6" |
| 70 | |
| 71 | /* --------------------------------------------------------------------- */ |
| 72 | |
| 73 | |
Jean Delvare | 3e42f0b | 2006-04-18 22:22:09 -0700 | [diff] [blame] | 74 | static char *mode_option __devinitdata = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | #ifdef MODULE |
| 77 | |
| 78 | MODULE_AUTHOR("(c) 2001-2002 Denis Oliver Kropp <dok@directfb.org>"); |
| 79 | MODULE_LICENSE("GPL"); |
| 80 | MODULE_DESCRIPTION("FBDev driver for S3 Savage PCI/AGP Chips"); |
| 81 | |
| 82 | #endif |
| 83 | |
| 84 | |
| 85 | /* --------------------------------------------------------------------- */ |
| 86 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 87 | static void vgaHWSeqReset(struct savagefb_par *par, int start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
| 89 | if (start) |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 90 | VGAwSEQ(0x00, 0x01, par); /* Synchronous Reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | else |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 92 | VGAwSEQ(0x00, 0x03, par); /* End Reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 95 | static void vgaHWProtect(struct savagefb_par *par, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | unsigned char tmp; |
| 98 | |
| 99 | if (on) { |
| 100 | /* |
| 101 | * Turn off screen and disable sequencer. |
| 102 | */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 103 | tmp = VGArSEQ(0x01, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 105 | vgaHWSeqReset(par, 1); /* start synchronous reset */ |
| 106 | VGAwSEQ(0x01, tmp | 0x20, par);/* disable the display */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 108 | VGAenablePalette(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } else { |
| 110 | /* |
| 111 | * Reenable sequencer, then turn on screen. |
| 112 | */ |
| 113 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 114 | tmp = VGArSEQ(0x01, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 116 | VGAwSEQ(0x01, tmp & ~0x20, par);/* reenable display */ |
| 117 | vgaHWSeqReset(par, 0); /* clear synchronous reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 119 | VGAdisablePalette(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 123 | static void vgaHWRestore(struct savagefb_par *par, struct savage_reg *reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | int i; |
| 126 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 127 | VGAwMISC(reg->MiscOutReg, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | for (i = 1; i < 5; i++) |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 130 | VGAwSEQ(i, reg->Sequencer[i], par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 or |
| 133 | CRTC[17] */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 134 | VGAwCR(17, reg->CRTC[17] & ~0x80, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | for (i = 0; i < 25; i++) |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 137 | VGAwCR(i, reg->CRTC[i], par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | for (i = 0; i < 9; i++) |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 140 | VGAwGR(i, reg->Graphics[i], par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 142 | VGAenablePalette(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | for (i = 0; i < 21; i++) |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 145 | VGAwATTR(i, reg->Attribute[i], par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 147 | VGAdisablePalette(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 150 | static void vgaHWInit(struct fb_var_screeninfo *var, |
| 151 | struct savagefb_par *par, |
| 152 | struct xtimings *timings, |
| 153 | struct savage_reg *reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 155 | reg->MiscOutReg = 0x23; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | if (!(timings->sync & FB_SYNC_HOR_HIGH_ACT)) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 158 | reg->MiscOutReg |= 0x40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | if (!(timings->sync & FB_SYNC_VERT_HIGH_ACT)) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 161 | reg->MiscOutReg |= 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | /* |
| 164 | * Time Sequencer |
| 165 | */ |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 166 | reg->Sequencer[0x00] = 0x00; |
| 167 | reg->Sequencer[0x01] = 0x01; |
| 168 | reg->Sequencer[0x02] = 0x0F; |
| 169 | reg->Sequencer[0x03] = 0x00; /* Font select */ |
| 170 | reg->Sequencer[0x04] = 0x0E; /* Misc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * CRTC Controller |
| 174 | */ |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 175 | reg->CRTC[0x00] = (timings->HTotal >> 3) - 5; |
| 176 | reg->CRTC[0x01] = (timings->HDisplay >> 3) - 1; |
| 177 | reg->CRTC[0x02] = (timings->HSyncStart >> 3) - 1; |
| 178 | reg->CRTC[0x03] = (((timings->HSyncEnd >> 3) - 1) & 0x1f) | 0x80; |
| 179 | reg->CRTC[0x04] = (timings->HSyncStart >> 3); |
| 180 | reg->CRTC[0x05] = ((((timings->HSyncEnd >> 3) - 1) & 0x20) << 2) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | (((timings->HSyncEnd >> 3)) & 0x1f); |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 182 | reg->CRTC[0x06] = (timings->VTotal - 2) & 0xFF; |
| 183 | reg->CRTC[0x07] = (((timings->VTotal - 2) & 0x100) >> 8) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | (((timings->VDisplay - 1) & 0x100) >> 7) | |
| 185 | ((timings->VSyncStart & 0x100) >> 6) | |
| 186 | (((timings->VSyncStart - 1) & 0x100) >> 5) | |
| 187 | 0x10 | |
| 188 | (((timings->VTotal - 2) & 0x200) >> 4) | |
| 189 | (((timings->VDisplay - 1) & 0x200) >> 3) | |
| 190 | ((timings->VSyncStart & 0x200) >> 2); |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 191 | reg->CRTC[0x08] = 0x00; |
| 192 | reg->CRTC[0x09] = (((timings->VSyncStart - 1) & 0x200) >> 4) | 0x40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | if (timings->dblscan) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 195 | reg->CRTC[0x09] |= 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 197 | reg->CRTC[0x0a] = 0x00; |
| 198 | reg->CRTC[0x0b] = 0x00; |
| 199 | reg->CRTC[0x0c] = 0x00; |
| 200 | reg->CRTC[0x0d] = 0x00; |
| 201 | reg->CRTC[0x0e] = 0x00; |
| 202 | reg->CRTC[0x0f] = 0x00; |
| 203 | reg->CRTC[0x10] = timings->VSyncStart & 0xff; |
| 204 | reg->CRTC[0x11] = (timings->VSyncEnd & 0x0f) | 0x20; |
| 205 | reg->CRTC[0x12] = (timings->VDisplay - 1) & 0xff; |
| 206 | reg->CRTC[0x13] = var->xres_virtual >> 4; |
| 207 | reg->CRTC[0x14] = 0x00; |
| 208 | reg->CRTC[0x15] = (timings->VSyncStart - 1) & 0xff; |
| 209 | reg->CRTC[0x16] = (timings->VSyncEnd - 1) & 0xff; |
| 210 | reg->CRTC[0x17] = 0xc3; |
| 211 | reg->CRTC[0x18] = 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * are these unnecessary? |
| 215 | * vgaHWHBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN|KGA_ENABLE_ON_ZERO); |
| 216 | * vgaHWVBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN|KGA_ENABLE_ON_ZERO); |
| 217 | */ |
| 218 | |
| 219 | /* |
| 220 | * Graphics Display Controller |
| 221 | */ |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 222 | reg->Graphics[0x00] = 0x00; |
| 223 | reg->Graphics[0x01] = 0x00; |
| 224 | reg->Graphics[0x02] = 0x00; |
| 225 | reg->Graphics[0x03] = 0x00; |
| 226 | reg->Graphics[0x04] = 0x00; |
| 227 | reg->Graphics[0x05] = 0x40; |
| 228 | reg->Graphics[0x06] = 0x05; /* only map 64k VGA memory !!!! */ |
| 229 | reg->Graphics[0x07] = 0x0F; |
| 230 | reg->Graphics[0x08] = 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 233 | reg->Attribute[0x00] = 0x00; /* standard colormap translation */ |
| 234 | reg->Attribute[0x01] = 0x01; |
| 235 | reg->Attribute[0x02] = 0x02; |
| 236 | reg->Attribute[0x03] = 0x03; |
| 237 | reg->Attribute[0x04] = 0x04; |
| 238 | reg->Attribute[0x05] = 0x05; |
| 239 | reg->Attribute[0x06] = 0x06; |
| 240 | reg->Attribute[0x07] = 0x07; |
| 241 | reg->Attribute[0x08] = 0x08; |
| 242 | reg->Attribute[0x09] = 0x09; |
| 243 | reg->Attribute[0x0a] = 0x0A; |
| 244 | reg->Attribute[0x0b] = 0x0B; |
| 245 | reg->Attribute[0x0c] = 0x0C; |
| 246 | reg->Attribute[0x0d] = 0x0D; |
| 247 | reg->Attribute[0x0e] = 0x0E; |
| 248 | reg->Attribute[0x0f] = 0x0F; |
| 249 | reg->Attribute[0x10] = 0x41; |
| 250 | reg->Attribute[0x11] = 0xFF; |
| 251 | reg->Attribute[0x12] = 0x0F; |
| 252 | reg->Attribute[0x13] = 0x00; |
| 253 | reg->Attribute[0x14] = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /* -------------------- Hardware specific routines ------------------------- */ |
| 257 | |
| 258 | /* |
| 259 | * Hardware Acceleration for SavageFB |
| 260 | */ |
| 261 | |
| 262 | /* Wait for fifo space */ |
| 263 | static void |
| 264 | savage3D_waitfifo(struct savagefb_par *par, int space) |
| 265 | { |
| 266 | int slots = MAXFIFO - space; |
| 267 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 268 | while ((savage_in32(0x48C00, par) & 0x0000ffff) > slots); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | static void |
| 272 | savage4_waitfifo(struct savagefb_par *par, int space) |
| 273 | { |
| 274 | int slots = MAXFIFO - space; |
| 275 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 276 | while ((savage_in32(0x48C60, par) & 0x001fffff) > slots); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static void |
| 280 | savage2000_waitfifo(struct savagefb_par *par, int space) |
| 281 | { |
| 282 | int slots = MAXFIFO - space; |
| 283 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 284 | while ((savage_in32(0x48C60, par) & 0x0000ffff) > slots); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* Wait for idle accelerator */ |
| 288 | static void |
| 289 | savage3D_waitidle(struct savagefb_par *par) |
| 290 | { |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 291 | while ((savage_in32(0x48C00, par) & 0x0008ffff) != 0x80000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static void |
| 295 | savage4_waitidle(struct savagefb_par *par) |
| 296 | { |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 297 | while ((savage_in32(0x48C60, par) & 0x00a00000) != 0x00a00000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static void |
| 301 | savage2000_waitidle(struct savagefb_par *par) |
| 302 | { |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 303 | while ((savage_in32(0x48C60, par) & 0x009fffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 306 | #ifdef CONFIG_FB_SAVAGE_ACCEL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | static void |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 308 | SavageSetup2DEngine(struct savagefb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
| 310 | unsigned long GlobalBitmapDescriptor; |
| 311 | |
| 312 | GlobalBitmapDescriptor = 1 | 8 | BCI_BD_BW_DISABLE; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 313 | BCI_BD_SET_BPP(GlobalBitmapDescriptor, par->depth); |
| 314 | BCI_BD_SET_STRIDE(GlobalBitmapDescriptor, par->vwidth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | switch(par->chip) { |
| 317 | case S3_SAVAGE3D: |
| 318 | case S3_SAVAGE_MX: |
| 319 | /* Disable BCI */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 320 | savage_out32(0x48C18, savage_in32(0x48C18, par) & 0x3FF0, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | /* Setup BCI command overflow buffer */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 322 | savage_out32(0x48C14, |
| 323 | (par->cob_offset >> 11) | (par->cob_index << 29), |
| 324 | par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | /* Program shadow status update. */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 326 | savage_out32(0x48C10, 0x78207220, par); |
| 327 | savage_out32(0x48C0C, 0, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | /* Enable BCI and command overflow buffer */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 329 | savage_out32(0x48C18, savage_in32(0x48C18, par) | 0x0C, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | break; |
| 331 | case S3_SAVAGE4: |
| 332 | case S3_PROSAVAGE: |
| 333 | case S3_SUPERSAVAGE: |
| 334 | /* Disable BCI */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 335 | savage_out32(0x48C18, savage_in32(0x48C18, par) & 0x3FF0, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | /* Program shadow status update */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 337 | savage_out32(0x48C10, 0x00700040, par); |
| 338 | savage_out32(0x48C0C, 0, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /* Enable BCI without the COB */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 340 | savage_out32(0x48C18, savage_in32(0x48C18, par) | 0x08, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | break; |
| 342 | case S3_SAVAGE2000: |
| 343 | /* Disable BCI */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 344 | savage_out32(0x48C18, 0, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | /* Setup BCI command overflow buffer */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 346 | savage_out32(0x48C18, |
| 347 | (par->cob_offset >> 7) | (par->cob_index), |
| 348 | par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | /* Disable shadow status update */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 350 | savage_out32(0x48A30, 0, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | /* Enable BCI and command overflow buffer */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 352 | savage_out32(0x48C18, savage_in32(0x48C18, par) | 0x00280000, |
| 353 | par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | break; |
| 355 | default: |
| 356 | break; |
| 357 | } |
| 358 | /* Turn on 16-bit register access. */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 359 | vga_out8(0x3d4, 0x31, par); |
| 360 | vga_out8(0x3d5, 0x0c, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | /* Set stride to use GBD. */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 363 | vga_out8(0x3d4, 0x50, par); |
| 364 | vga_out8(0x3d5, vga_in8(0x3d5, par) | 0xC1, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | /* Enable 2D engine. */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 367 | vga_out8(0x3d4, 0x40, par); |
| 368 | vga_out8(0x3d5, 0x01, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 370 | savage_out32(MONO_PAT_0, ~0, par); |
| 371 | savage_out32(MONO_PAT_1, ~0, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | /* Setup plane masks */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 374 | savage_out32(0x8128, ~0, par); /* enable all write planes */ |
| 375 | savage_out32(0x812C, ~0, par); /* enable all read planes */ |
| 376 | savage_out16(0x8134, 0x27, par); |
| 377 | savage_out16(0x8136, 0x07, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | /* Now set the GBD */ |
| 380 | par->bci_ptr = 0; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 381 | par->SavageWaitFifo(par, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 383 | BCI_SEND(BCI_CMD_SETREG | (1 << 16) | BCI_GBD1); |
| 384 | BCI_SEND(0); |
| 385 | BCI_SEND(BCI_CMD_SETREG | (1 << 16) | BCI_GBD2); |
| 386 | BCI_SEND(GlobalBitmapDescriptor); |
Antonino A. Daplas | 5b60046 | 2007-03-16 13:38:18 -0800 | [diff] [blame] | 387 | |
| 388 | /* |
| 389 | * I don't know why, sending this twice fixes the intial black screen, |
| 390 | * prevents X from crashing at least in Toshiba laptops with SavageIX. |
| 391 | * --Tony |
| 392 | */ |
| 393 | par->bci_ptr = 0; |
| 394 | par->SavageWaitFifo(par, 4); |
| 395 | |
| 396 | BCI_SEND(BCI_CMD_SETREG | (1 << 16) | BCI_GBD1); |
| 397 | BCI_SEND(0); |
| 398 | BCI_SEND(BCI_CMD_SETREG | (1 << 16) | BCI_GBD2); |
| 399 | BCI_SEND(GlobalBitmapDescriptor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 402 | static void savagefb_set_clip(struct fb_info *info) |
| 403 | { |
| 404 | struct savagefb_par *par = info->par; |
| 405 | int cmd; |
| 406 | |
| 407 | cmd = BCI_CMD_NOP | BCI_CMD_CLIP_NEW; |
| 408 | par->bci_ptr = 0; |
| 409 | par->SavageWaitFifo(par,3); |
| 410 | BCI_SEND(cmd); |
| 411 | BCI_SEND(BCI_CLIP_TL(0, 0)); |
| 412 | BCI_SEND(BCI_CLIP_BR(0xfff, 0xfff)); |
| 413 | } |
| 414 | #else |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 415 | static void SavageSetup2DEngine(struct savagefb_par *par) {} |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 416 | |
| 417 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | static void SavageCalcClock(long freq, int min_m, int min_n1, int max_n1, |
| 420 | int min_n2, int max_n2, long freq_min, |
| 421 | long freq_max, unsigned int *mdiv, |
| 422 | unsigned int *ndiv, unsigned int *r) |
| 423 | { |
| 424 | long diff, best_diff; |
| 425 | unsigned int m; |
| 426 | unsigned char n1, n2, best_n1=16+2, best_n2=2, best_m=125+2; |
| 427 | |
| 428 | if (freq < freq_min / (1 << max_n2)) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 429 | printk(KERN_ERR "invalid frequency %ld Khz\n", freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | freq = freq_min / (1 << max_n2); |
| 431 | } |
| 432 | if (freq > freq_max / (1 << min_n2)) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 433 | printk(KERN_ERR "invalid frequency %ld Khz\n", freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | freq = freq_max / (1 << min_n2); |
| 435 | } |
| 436 | |
| 437 | /* work out suitable timings */ |
| 438 | best_diff = freq; |
| 439 | |
| 440 | for (n2=min_n2; n2<=max_n2; n2++) { |
| 441 | for (n1=min_n1+2; n1<=max_n1+2; n1++) { |
| 442 | m = (freq * n1 * (1 << n2) + HALF_BASE_FREQ) / |
| 443 | BASE_FREQ; |
| 444 | if (m < min_m+2 || m > 127+2) |
| 445 | continue; |
| 446 | if ((m * BASE_FREQ >= freq_min * n1) && |
| 447 | (m * BASE_FREQ <= freq_max * n1)) { |
| 448 | diff = freq * (1 << n2) * n1 - BASE_FREQ * m; |
| 449 | if (diff < 0) |
| 450 | diff = -diff; |
| 451 | if (diff < best_diff) { |
| 452 | best_diff = diff; |
| 453 | best_m = m; |
| 454 | best_n1 = n1; |
| 455 | best_n2 = n2; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | *ndiv = best_n1 - 2; |
| 462 | *r = best_n2; |
| 463 | *mdiv = best_m - 2; |
| 464 | } |
| 465 | |
| 466 | static int common_calc_clock(long freq, int min_m, int min_n1, int max_n1, |
| 467 | int min_n2, int max_n2, long freq_min, |
| 468 | long freq_max, unsigned char *mdiv, |
| 469 | unsigned char *ndiv) |
| 470 | { |
| 471 | long diff, best_diff; |
| 472 | unsigned int m; |
| 473 | unsigned char n1, n2; |
| 474 | unsigned char best_n1 = 16+2, best_n2 = 2, best_m = 125+2; |
| 475 | |
| 476 | best_diff = freq; |
| 477 | |
| 478 | for (n2 = min_n2; n2 <= max_n2; n2++) { |
| 479 | for (n1 = min_n1+2; n1 <= max_n1+2; n1++) { |
| 480 | m = (freq * n1 * (1 << n2) + HALF_BASE_FREQ) / |
| 481 | BASE_FREQ; |
| 482 | if (m < min_m + 2 || m > 127+2) |
| 483 | continue; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 484 | if ((m * BASE_FREQ >= freq_min * n1) && |
| 485 | (m * BASE_FREQ <= freq_max * n1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | diff = freq * (1 << n2) * n1 - BASE_FREQ * m; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 487 | if (diff < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | diff = -diff; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 489 | if (diff < best_diff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | best_diff = diff; |
| 491 | best_m = m; |
| 492 | best_n1 = n1; |
| 493 | best_n2 = n2; |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 499 | if (max_n1 == 63) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | *ndiv = (best_n1 - 2) | (best_n2 << 6); |
| 501 | else |
| 502 | *ndiv = (best_n1 - 2) | (best_n2 << 5); |
| 503 | |
| 504 | *mdiv = best_m - 2; |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | #ifdef SAVAGEFB_DEBUG |
| 510 | /* This function is used to debug, it prints out the contents of s3 regs */ |
| 511 | |
Antonino A. Daplas | d8ad7e0 | 2007-03-16 13:38:18 -0800 | [diff] [blame] | 512 | static void SavagePrintRegs(struct savagefb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
| 514 | unsigned char i; |
| 515 | int vgaCRIndex = 0x3d4; |
| 516 | int vgaCRReg = 0x3d5; |
| 517 | |
| 518 | printk(KERN_DEBUG "SR x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE " |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 519 | "xF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 521 | for (i = 0; i < 0x70; i++) { |
| 522 | if (!(i % 16)) |
| 523 | printk(KERN_DEBUG "\nSR%xx ", i >> 4); |
| 524 | vga_out8(0x3c4, i, par); |
| 525 | printk(KERN_DEBUG " %02x", vga_in8(0x3c5, par)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | printk(KERN_DEBUG "\n\nCR x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC " |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 529 | "xD xE xF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 531 | for (i = 0; i < 0xB7; i++) { |
| 532 | if (!(i % 16)) |
| 533 | printk(KERN_DEBUG "\nCR%xx ", i >> 4); |
| 534 | vga_out8(vgaCRIndex, i, par); |
| 535 | printk(KERN_DEBUG " %02x", vga_in8(vgaCRReg, par)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | printk(KERN_DEBUG "\n\n"); |
| 539 | } |
| 540 | #endif |
| 541 | |
| 542 | /* --------------------------------------------------------------------- */ |
| 543 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 544 | static void savage_get_default_par(struct savagefb_par *par, struct savage_reg *reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
| 546 | unsigned char cr3a, cr53, cr66; |
| 547 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 548 | vga_out16(0x3d4, 0x4838, par); |
| 549 | vga_out16(0x3d4, 0xa039, par); |
| 550 | vga_out16(0x3c4, 0x0608, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 552 | vga_out8(0x3d4, 0x66, par); |
| 553 | cr66 = vga_in8(0x3d5, par); |
| 554 | vga_out8(0x3d5, cr66 | 0x80, par); |
| 555 | vga_out8(0x3d4, 0x3a, par); |
| 556 | cr3a = vga_in8(0x3d5, par); |
| 557 | vga_out8(0x3d5, cr3a | 0x80, par); |
| 558 | vga_out8(0x3d4, 0x53, par); |
| 559 | cr53 = vga_in8(0x3d5, par); |
| 560 | vga_out8(0x3d5, cr53 & 0x7f, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 562 | vga_out8(0x3d4, 0x66, par); |
| 563 | vga_out8(0x3d5, cr66, par); |
| 564 | vga_out8(0x3d4, 0x3a, par); |
| 565 | vga_out8(0x3d5, cr3a, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 567 | vga_out8(0x3d4, 0x66, par); |
| 568 | vga_out8(0x3d5, cr66, par); |
| 569 | vga_out8(0x3d4, 0x3a, par); |
| 570 | vga_out8(0x3d5, cr3a, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | /* unlock extended seq regs */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 573 | vga_out8(0x3c4, 0x08, par); |
| 574 | reg->SR08 = vga_in8(0x3c5, par); |
| 575 | vga_out8(0x3c5, 0x06, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | /* now save all the extended regs we need */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 578 | vga_out8(0x3d4, 0x31, par); |
| 579 | reg->CR31 = vga_in8(0x3d5, par); |
| 580 | vga_out8(0x3d4, 0x32, par); |
| 581 | reg->CR32 = vga_in8(0x3d5, par); |
| 582 | vga_out8(0x3d4, 0x34, par); |
| 583 | reg->CR34 = vga_in8(0x3d5, par); |
| 584 | vga_out8(0x3d4, 0x36, par); |
| 585 | reg->CR36 = vga_in8(0x3d5, par); |
| 586 | vga_out8(0x3d4, 0x3a, par); |
| 587 | reg->CR3A = vga_in8(0x3d5, par); |
| 588 | vga_out8(0x3d4, 0x40, par); |
| 589 | reg->CR40 = vga_in8(0x3d5, par); |
| 590 | vga_out8(0x3d4, 0x42, par); |
| 591 | reg->CR42 = vga_in8(0x3d5, par); |
| 592 | vga_out8(0x3d4, 0x45, par); |
| 593 | reg->CR45 = vga_in8(0x3d5, par); |
| 594 | vga_out8(0x3d4, 0x50, par); |
| 595 | reg->CR50 = vga_in8(0x3d5, par); |
| 596 | vga_out8(0x3d4, 0x51, par); |
| 597 | reg->CR51 = vga_in8(0x3d5, par); |
| 598 | vga_out8(0x3d4, 0x53, par); |
| 599 | reg->CR53 = vga_in8(0x3d5, par); |
| 600 | vga_out8(0x3d4, 0x58, par); |
| 601 | reg->CR58 = vga_in8(0x3d5, par); |
| 602 | vga_out8(0x3d4, 0x60, par); |
| 603 | reg->CR60 = vga_in8(0x3d5, par); |
| 604 | vga_out8(0x3d4, 0x66, par); |
| 605 | reg->CR66 = vga_in8(0x3d5, par); |
| 606 | vga_out8(0x3d4, 0x67, par); |
| 607 | reg->CR67 = vga_in8(0x3d5, par); |
| 608 | vga_out8(0x3d4, 0x68, par); |
| 609 | reg->CR68 = vga_in8(0x3d5, par); |
| 610 | vga_out8(0x3d4, 0x69, par); |
| 611 | reg->CR69 = vga_in8(0x3d5, par); |
| 612 | vga_out8(0x3d4, 0x6f, par); |
| 613 | reg->CR6F = vga_in8(0x3d5, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 615 | vga_out8(0x3d4, 0x33, par); |
| 616 | reg->CR33 = vga_in8(0x3d5, par); |
| 617 | vga_out8(0x3d4, 0x86, par); |
| 618 | reg->CR86 = vga_in8(0x3d5, par); |
| 619 | vga_out8(0x3d4, 0x88, par); |
| 620 | reg->CR88 = vga_in8(0x3d5, par); |
| 621 | vga_out8(0x3d4, 0x90, par); |
| 622 | reg->CR90 = vga_in8(0x3d5, par); |
| 623 | vga_out8(0x3d4, 0x91, par); |
| 624 | reg->CR91 = vga_in8(0x3d5, par); |
| 625 | vga_out8(0x3d4, 0xb0, par); |
| 626 | reg->CRB0 = vga_in8(0x3d5, par) | 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | /* extended mode timing regs */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 629 | vga_out8(0x3d4, 0x3b, par); |
| 630 | reg->CR3B = vga_in8(0x3d5, par); |
| 631 | vga_out8(0x3d4, 0x3c, par); |
| 632 | reg->CR3C = vga_in8(0x3d5, par); |
| 633 | vga_out8(0x3d4, 0x43, par); |
| 634 | reg->CR43 = vga_in8(0x3d5, par); |
| 635 | vga_out8(0x3d4, 0x5d, par); |
| 636 | reg->CR5D = vga_in8(0x3d5, par); |
| 637 | vga_out8(0x3d4, 0x5e, par); |
| 638 | reg->CR5E = vga_in8(0x3d5, par); |
| 639 | vga_out8(0x3d4, 0x65, par); |
| 640 | reg->CR65 = vga_in8(0x3d5, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
| 642 | /* save seq extended regs for DCLK PLL programming */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 643 | vga_out8(0x3c4, 0x0e, par); |
| 644 | reg->SR0E = vga_in8(0x3c5, par); |
| 645 | vga_out8(0x3c4, 0x0f, par); |
| 646 | reg->SR0F = vga_in8(0x3c5, par); |
| 647 | vga_out8(0x3c4, 0x10, par); |
| 648 | reg->SR10 = vga_in8(0x3c5, par); |
| 649 | vga_out8(0x3c4, 0x11, par); |
| 650 | reg->SR11 = vga_in8(0x3c5, par); |
| 651 | vga_out8(0x3c4, 0x12, par); |
| 652 | reg->SR12 = vga_in8(0x3c5, par); |
| 653 | vga_out8(0x3c4, 0x13, par); |
| 654 | reg->SR13 = vga_in8(0x3c5, par); |
| 655 | vga_out8(0x3c4, 0x29, par); |
| 656 | reg->SR29 = vga_in8(0x3c5, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 658 | vga_out8(0x3c4, 0x15, par); |
| 659 | reg->SR15 = vga_in8(0x3c5, par); |
| 660 | vga_out8(0x3c4, 0x30, par); |
| 661 | reg->SR30 = vga_in8(0x3c5, par); |
| 662 | vga_out8(0x3c4, 0x18, par); |
| 663 | reg->SR18 = vga_in8(0x3c5, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
| 665 | /* Save flat panel expansion regsters. */ |
| 666 | if (par->chip == S3_SAVAGE_MX) { |
| 667 | int i; |
| 668 | |
| 669 | for (i = 0; i < 8; i++) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 670 | vga_out8(0x3c4, 0x54+i, par); |
| 671 | reg->SR54[i] = vga_in8(0x3c5, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 675 | vga_out8(0x3d4, 0x66, par); |
| 676 | cr66 = vga_in8(0x3d5, par); |
| 677 | vga_out8(0x3d5, cr66 | 0x80, par); |
| 678 | vga_out8(0x3d4, 0x3a, par); |
| 679 | cr3a = vga_in8(0x3d5, par); |
| 680 | vga_out8(0x3d5, cr3a | 0x80, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | /* now save MIU regs */ |
| 683 | if (par->chip != S3_SAVAGE_MX) { |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 684 | reg->MMPR0 = savage_in32(FIFO_CONTROL_REG, par); |
| 685 | reg->MMPR1 = savage_in32(MIU_CONTROL_REG, par); |
| 686 | reg->MMPR2 = savage_in32(STREAMS_TIMEOUT_REG, par); |
| 687 | reg->MMPR3 = savage_in32(MISC_TIMEOUT_REG, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 690 | vga_out8(0x3d4, 0x3a, par); |
| 691 | vga_out8(0x3d5, cr3a, par); |
| 692 | vga_out8(0x3d4, 0x66, par); |
| 693 | vga_out8(0x3d5, cr66, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 696 | static void savage_set_default_par(struct savagefb_par *par, |
| 697 | struct savage_reg *reg) |
| 698 | { |
| 699 | unsigned char cr3a, cr53, cr66; |
| 700 | |
| 701 | vga_out16(0x3d4, 0x4838, par); |
| 702 | vga_out16(0x3d4, 0xa039, par); |
| 703 | vga_out16(0x3c4, 0x0608, par); |
| 704 | |
| 705 | vga_out8(0x3d4, 0x66, par); |
| 706 | cr66 = vga_in8(0x3d5, par); |
| 707 | vga_out8(0x3d5, cr66 | 0x80, par); |
| 708 | vga_out8(0x3d4, 0x3a, par); |
| 709 | cr3a = vga_in8(0x3d5, par); |
| 710 | vga_out8(0x3d5, cr3a | 0x80, par); |
| 711 | vga_out8(0x3d4, 0x53, par); |
| 712 | cr53 = vga_in8(0x3d5, par); |
| 713 | vga_out8(0x3d5, cr53 & 0x7f, par); |
| 714 | |
| 715 | vga_out8(0x3d4, 0x66, par); |
| 716 | vga_out8(0x3d5, cr66, par); |
| 717 | vga_out8(0x3d4, 0x3a, par); |
| 718 | vga_out8(0x3d5, cr3a, par); |
| 719 | |
| 720 | vga_out8(0x3d4, 0x66, par); |
| 721 | vga_out8(0x3d5, cr66, par); |
| 722 | vga_out8(0x3d4, 0x3a, par); |
| 723 | vga_out8(0x3d5, cr3a, par); |
| 724 | |
| 725 | /* unlock extended seq regs */ |
| 726 | vga_out8(0x3c4, 0x08, par); |
| 727 | vga_out8(0x3c5, reg->SR08, par); |
| 728 | vga_out8(0x3c5, 0x06, par); |
| 729 | |
| 730 | /* now restore all the extended regs we need */ |
| 731 | vga_out8(0x3d4, 0x31, par); |
| 732 | vga_out8(0x3d5, reg->CR31, par); |
| 733 | vga_out8(0x3d4, 0x32, par); |
| 734 | vga_out8(0x3d5, reg->CR32, par); |
| 735 | vga_out8(0x3d4, 0x34, par); |
| 736 | vga_out8(0x3d5, reg->CR34, par); |
| 737 | vga_out8(0x3d4, 0x36, par); |
| 738 | vga_out8(0x3d5,reg->CR36, par); |
| 739 | vga_out8(0x3d4, 0x3a, par); |
| 740 | vga_out8(0x3d5, reg->CR3A, par); |
| 741 | vga_out8(0x3d4, 0x40, par); |
| 742 | vga_out8(0x3d5, reg->CR40, par); |
| 743 | vga_out8(0x3d4, 0x42, par); |
| 744 | vga_out8(0x3d5, reg->CR42, par); |
| 745 | vga_out8(0x3d4, 0x45, par); |
| 746 | vga_out8(0x3d5, reg->CR45, par); |
| 747 | vga_out8(0x3d4, 0x50, par); |
| 748 | vga_out8(0x3d5, reg->CR50, par); |
| 749 | vga_out8(0x3d4, 0x51, par); |
| 750 | vga_out8(0x3d5, reg->CR51, par); |
| 751 | vga_out8(0x3d4, 0x53, par); |
| 752 | vga_out8(0x3d5, reg->CR53, par); |
| 753 | vga_out8(0x3d4, 0x58, par); |
| 754 | vga_out8(0x3d5, reg->CR58, par); |
| 755 | vga_out8(0x3d4, 0x60, par); |
| 756 | vga_out8(0x3d5, reg->CR60, par); |
| 757 | vga_out8(0x3d4, 0x66, par); |
| 758 | vga_out8(0x3d5, reg->CR66, par); |
| 759 | vga_out8(0x3d4, 0x67, par); |
| 760 | vga_out8(0x3d5, reg->CR67, par); |
| 761 | vga_out8(0x3d4, 0x68, par); |
| 762 | vga_out8(0x3d5, reg->CR68, par); |
| 763 | vga_out8(0x3d4, 0x69, par); |
| 764 | vga_out8(0x3d5, reg->CR69, par); |
| 765 | vga_out8(0x3d4, 0x6f, par); |
| 766 | vga_out8(0x3d5, reg->CR6F, par); |
| 767 | |
| 768 | vga_out8(0x3d4, 0x33, par); |
| 769 | vga_out8(0x3d5, reg->CR33, par); |
| 770 | vga_out8(0x3d4, 0x86, par); |
| 771 | vga_out8(0x3d5, reg->CR86, par); |
| 772 | vga_out8(0x3d4, 0x88, par); |
| 773 | vga_out8(0x3d5, reg->CR88, par); |
| 774 | vga_out8(0x3d4, 0x90, par); |
| 775 | vga_out8(0x3d5, reg->CR90, par); |
| 776 | vga_out8(0x3d4, 0x91, par); |
| 777 | vga_out8(0x3d5, reg->CR91, par); |
| 778 | vga_out8(0x3d4, 0xb0, par); |
| 779 | vga_out8(0x3d5, reg->CRB0, par); |
| 780 | |
| 781 | /* extended mode timing regs */ |
| 782 | vga_out8(0x3d4, 0x3b, par); |
| 783 | vga_out8(0x3d5, reg->CR3B, par); |
| 784 | vga_out8(0x3d4, 0x3c, par); |
| 785 | vga_out8(0x3d5, reg->CR3C, par); |
| 786 | vga_out8(0x3d4, 0x43, par); |
| 787 | vga_out8(0x3d5, reg->CR43, par); |
| 788 | vga_out8(0x3d4, 0x5d, par); |
| 789 | vga_out8(0x3d5, reg->CR5D, par); |
| 790 | vga_out8(0x3d4, 0x5e, par); |
| 791 | vga_out8(0x3d5, reg->CR5E, par); |
| 792 | vga_out8(0x3d4, 0x65, par); |
| 793 | vga_out8(0x3d5, reg->CR65, par); |
| 794 | |
| 795 | /* save seq extended regs for DCLK PLL programming */ |
| 796 | vga_out8(0x3c4, 0x0e, par); |
| 797 | vga_out8(0x3c5, reg->SR0E, par); |
| 798 | vga_out8(0x3c4, 0x0f, par); |
| 799 | vga_out8(0x3c5, reg->SR0F, par); |
| 800 | vga_out8(0x3c4, 0x10, par); |
| 801 | vga_out8(0x3c5, reg->SR10, par); |
| 802 | vga_out8(0x3c4, 0x11, par); |
| 803 | vga_out8(0x3c5, reg->SR11, par); |
| 804 | vga_out8(0x3c4, 0x12, par); |
| 805 | vga_out8(0x3c5, reg->SR12, par); |
| 806 | vga_out8(0x3c4, 0x13, par); |
| 807 | vga_out8(0x3c5, reg->SR13, par); |
| 808 | vga_out8(0x3c4, 0x29, par); |
| 809 | vga_out8(0x3c5, reg->SR29, par); |
| 810 | |
| 811 | vga_out8(0x3c4, 0x15, par); |
| 812 | vga_out8(0x3c5, reg->SR15, par); |
| 813 | vga_out8(0x3c4, 0x30, par); |
| 814 | vga_out8(0x3c5, reg->SR30, par); |
| 815 | vga_out8(0x3c4, 0x18, par); |
| 816 | vga_out8(0x3c5, reg->SR18, par); |
| 817 | |
| 818 | /* Save flat panel expansion regsters. */ |
| 819 | if (par->chip == S3_SAVAGE_MX) { |
| 820 | int i; |
| 821 | |
| 822 | for (i = 0; i < 8; i++) { |
| 823 | vga_out8(0x3c4, 0x54+i, par); |
| 824 | vga_out8(0x3c5, reg->SR54[i], par); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | vga_out8(0x3d4, 0x66, par); |
| 829 | cr66 = vga_in8(0x3d5, par); |
| 830 | vga_out8(0x3d5, cr66 | 0x80, par); |
| 831 | vga_out8(0x3d4, 0x3a, par); |
| 832 | cr3a = vga_in8(0x3d5, par); |
| 833 | vga_out8(0x3d5, cr3a | 0x80, par); |
| 834 | |
| 835 | /* now save MIU regs */ |
| 836 | if (par->chip != S3_SAVAGE_MX) { |
| 837 | savage_out32(FIFO_CONTROL_REG, reg->MMPR0, par); |
| 838 | savage_out32(MIU_CONTROL_REG, reg->MMPR1, par); |
| 839 | savage_out32(STREAMS_TIMEOUT_REG, reg->MMPR2, par); |
| 840 | savage_out32(MISC_TIMEOUT_REG, reg->MMPR3, par); |
| 841 | } |
| 842 | |
| 843 | vga_out8(0x3d4, 0x3a, par); |
| 844 | vga_out8(0x3d5, cr3a, par); |
| 845 | vga_out8(0x3d4, 0x66, par); |
| 846 | vga_out8(0x3d5, cr66, par); |
| 847 | } |
| 848 | |
Geert Uytterhoeven | 9791d76 | 2007-02-12 00:55:19 -0800 | [diff] [blame] | 849 | static void savage_update_var(struct fb_var_screeninfo *var, |
| 850 | const struct fb_videomode *modedb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | { |
| 852 | var->xres = var->xres_virtual = modedb->xres; |
| 853 | var->yres = modedb->yres; |
| 854 | if (var->yres_virtual < var->yres) |
| 855 | var->yres_virtual = var->yres; |
| 856 | var->xoffset = var->yoffset = 0; |
| 857 | var->pixclock = modedb->pixclock; |
| 858 | var->left_margin = modedb->left_margin; |
| 859 | var->right_margin = modedb->right_margin; |
| 860 | var->upper_margin = modedb->upper_margin; |
| 861 | var->lower_margin = modedb->lower_margin; |
| 862 | var->hsync_len = modedb->hsync_len; |
| 863 | var->vsync_len = modedb->vsync_len; |
| 864 | var->sync = modedb->sync; |
| 865 | var->vmode = modedb->vmode; |
| 866 | } |
| 867 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 868 | static int savagefb_check_var(struct fb_var_screeninfo *var, |
| 869 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 871 | struct savagefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | int memlen, vramlen, mode_valid = 0; |
| 873 | |
| 874 | DBG("savagefb_check_var"); |
| 875 | |
| 876 | var->transp.offset = 0; |
| 877 | var->transp.length = 0; |
| 878 | switch (var->bits_per_pixel) { |
| 879 | case 8: |
| 880 | var->red.offset = var->green.offset = |
| 881 | var->blue.offset = 0; |
| 882 | var->red.length = var->green.length = |
| 883 | var->blue.length = var->bits_per_pixel; |
| 884 | break; |
| 885 | case 16: |
| 886 | var->red.offset = 11; |
| 887 | var->red.length = 5; |
| 888 | var->green.offset = 5; |
| 889 | var->green.length = 6; |
| 890 | var->blue.offset = 0; |
| 891 | var->blue.length = 5; |
| 892 | break; |
| 893 | case 32: |
| 894 | var->transp.offset = 24; |
| 895 | var->transp.length = 8; |
| 896 | var->red.offset = 16; |
| 897 | var->red.length = 8; |
| 898 | var->green.offset = 8; |
| 899 | var->green.length = 8; |
| 900 | var->blue.offset = 0; |
| 901 | var->blue.length = 8; |
| 902 | break; |
| 903 | |
| 904 | default: |
| 905 | return -EINVAL; |
| 906 | } |
| 907 | |
| 908 | if (!info->monspecs.hfmax || !info->monspecs.vfmax || |
| 909 | !info->monspecs.dclkmax || !fb_validate_mode(var, info)) |
| 910 | mode_valid = 1; |
| 911 | |
| 912 | /* calculate modeline if supported by monitor */ |
| 913 | if (!mode_valid && info->monspecs.gtf) { |
| 914 | if (!fb_get_mode(FB_MAXTIMINGS, 0, var, info)) |
| 915 | mode_valid = 1; |
| 916 | } |
| 917 | |
| 918 | if (!mode_valid) { |
Geert Uytterhoeven | 9791d76 | 2007-02-12 00:55:19 -0800 | [diff] [blame] | 919 | const struct fb_videomode *mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
| 921 | mode = fb_find_best_mode(var, &info->modelist); |
| 922 | if (mode) { |
| 923 | savage_update_var(var, mode); |
| 924 | mode_valid = 1; |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | if (!mode_valid && info->monspecs.modedb_len) |
| 929 | return -EINVAL; |
| 930 | |
| 931 | /* Is the mode larger than the LCD panel? */ |
| 932 | if (par->SavagePanelWidth && |
| 933 | (var->xres > par->SavagePanelWidth || |
| 934 | var->yres > par->SavagePanelHeight)) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 935 | printk(KERN_INFO "Mode (%dx%d) larger than the LCD panel " |
| 936 | "(%dx%d)\n", var->xres, var->yres, |
| 937 | par->SavagePanelWidth, |
| 938 | par->SavagePanelHeight); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | return -1; |
| 940 | } |
| 941 | |
| 942 | if (var->yres_virtual < var->yres) |
| 943 | var->yres_virtual = var->yres; |
| 944 | if (var->xres_virtual < var->xres) |
| 945 | var->xres_virtual = var->xres; |
| 946 | |
| 947 | vramlen = info->fix.smem_len; |
| 948 | |
| 949 | memlen = var->xres_virtual * var->bits_per_pixel * |
| 950 | var->yres_virtual / 8; |
| 951 | if (memlen > vramlen) { |
| 952 | var->yres_virtual = vramlen * 8 / |
| 953 | (var->xres_virtual * var->bits_per_pixel); |
| 954 | memlen = var->xres_virtual * var->bits_per_pixel * |
| 955 | var->yres_virtual / 8; |
| 956 | } |
| 957 | |
| 958 | /* we must round yres/xres down, we already rounded y/xres_virtual up |
| 959 | if it was possible. We should return -EINVAL, but I disagree */ |
| 960 | if (var->yres_virtual < var->yres) |
| 961 | var->yres = var->yres_virtual; |
| 962 | if (var->xres_virtual < var->xres) |
| 963 | var->xres = var->xres_virtual; |
| 964 | if (var->xoffset + var->xres > var->xres_virtual) |
| 965 | var->xoffset = var->xres_virtual - var->xres; |
| 966 | if (var->yoffset + var->yres > var->yres_virtual) |
| 967 | var->yoffset = var->yres_virtual - var->yres; |
| 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 973 | static int savagefb_decode_var(struct fb_var_screeninfo *var, |
| 974 | struct savagefb_par *par, |
| 975 | struct savage_reg *reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | { |
| 977 | struct xtimings timings; |
| 978 | int width, dclk, i, j; /*, refresh; */ |
| 979 | unsigned int m, n, r; |
| 980 | unsigned char tmp = 0; |
| 981 | unsigned int pixclock = var->pixclock; |
| 982 | |
| 983 | DBG("savagefb_decode_var"); |
| 984 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 985 | memset(&timings, 0, sizeof(timings)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | |
| 987 | if (!pixclock) pixclock = 10000; /* 10ns = 100MHz */ |
| 988 | timings.Clock = 1000000000 / pixclock; |
| 989 | if (timings.Clock < 1) timings.Clock = 1; |
| 990 | timings.dblscan = var->vmode & FB_VMODE_DOUBLE; |
| 991 | timings.interlaced = var->vmode & FB_VMODE_INTERLACED; |
| 992 | timings.HDisplay = var->xres; |
| 993 | timings.HSyncStart = timings.HDisplay + var->right_margin; |
| 994 | timings.HSyncEnd = timings.HSyncStart + var->hsync_len; |
| 995 | timings.HTotal = timings.HSyncEnd + var->left_margin; |
| 996 | timings.VDisplay = var->yres; |
| 997 | timings.VSyncStart = timings.VDisplay + var->lower_margin; |
| 998 | timings.VSyncEnd = timings.VSyncStart + var->vsync_len; |
| 999 | timings.VTotal = timings.VSyncEnd + var->upper_margin; |
| 1000 | timings.sync = var->sync; |
| 1001 | |
| 1002 | |
| 1003 | par->depth = var->bits_per_pixel; |
| 1004 | par->vwidth = var->xres_virtual; |
| 1005 | |
| 1006 | if (var->bits_per_pixel == 16 && par->chip == S3_SAVAGE3D) { |
| 1007 | timings.HDisplay *= 2; |
| 1008 | timings.HSyncStart *= 2; |
| 1009 | timings.HSyncEnd *= 2; |
| 1010 | timings.HTotal *= 2; |
| 1011 | } |
| 1012 | |
| 1013 | /* |
| 1014 | * This will allocate the datastructure and initialize all of the |
| 1015 | * generic VGA registers. |
| 1016 | */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1017 | vgaHWInit(var, par, &timings, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
| 1019 | /* We need to set CR67 whether or not we use the BIOS. */ |
| 1020 | |
| 1021 | dclk = timings.Clock; |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1022 | reg->CR67 = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1024 | switch(var->bits_per_pixel) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | case 8: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1026 | if ((par->chip == S3_SAVAGE2000) && (dclk >= 230000)) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1027 | reg->CR67 = 0x10; /* 8bpp, 2 pixels/clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1029 | reg->CR67 = 0x00; /* 8bpp, 1 pixel/clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | break; |
| 1031 | case 15: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1032 | if (S3_SAVAGE_MOBILE_SERIES(par->chip) || |
| 1033 | ((par->chip == S3_SAVAGE2000) && (dclk >= 230000))) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1034 | reg->CR67 = 0x30; /* 15bpp, 2 pixel/clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1036 | reg->CR67 = 0x20; /* 15bpp, 1 pixels/clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | break; |
| 1038 | case 16: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1039 | if (S3_SAVAGE_MOBILE_SERIES(par->chip) || |
| 1040 | ((par->chip == S3_SAVAGE2000) && (dclk >= 230000))) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1041 | reg->CR67 = 0x50; /* 16bpp, 2 pixel/clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1043 | reg->CR67 = 0x40; /* 16bpp, 1 pixels/clock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | break; |
| 1045 | case 24: |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1046 | reg->CR67 = 0x70; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | break; |
| 1048 | case 32: |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1049 | reg->CR67 = 0xd0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | break; |
| 1051 | } |
| 1052 | |
| 1053 | /* |
| 1054 | * Either BIOS use is disabled, or we failed to find a suitable |
| 1055 | * match. Fall back to traditional register-crunching. |
| 1056 | */ |
| 1057 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1058 | vga_out8(0x3d4, 0x3a, par); |
| 1059 | tmp = vga_in8(0x3d5, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | if (1 /*FIXME:psav->pci_burst*/) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1061 | reg->CR3A = (tmp & 0x7f) | 0x15; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1063 | reg->CR3A = tmp | 0x95; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1065 | reg->CR53 = 0x00; |
| 1066 | reg->CR31 = 0x8c; |
| 1067 | reg->CR66 = 0x89; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1069 | vga_out8(0x3d4, 0x58, par); |
| 1070 | reg->CR58 = vga_in8(0x3d5, par) & 0x80; |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1071 | reg->CR58 |= 0x13; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1073 | reg->SR15 = 0x03 | 0x80; |
| 1074 | reg->SR18 = 0x00; |
| 1075 | reg->CR43 = reg->CR45 = reg->CR65 = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1077 | vga_out8(0x3d4, 0x40, par); |
| 1078 | reg->CR40 = vga_in8(0x3d5, par) & ~0x01; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1080 | reg->MMPR0 = 0x010400; |
| 1081 | reg->MMPR1 = 0x00; |
| 1082 | reg->MMPR2 = 0x0808; |
| 1083 | reg->MMPR3 = 0x08080810; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1085 | SavageCalcClock(dclk, 1, 1, 127, 0, 4, 180000, 360000, &m, &n, &r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | /* m = 107; n = 4; r = 2; */ |
| 1087 | |
| 1088 | if (par->MCLK <= 0) { |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1089 | reg->SR10 = 255; |
| 1090 | reg->SR11 = 255; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | } else { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1092 | common_calc_clock(par->MCLK, 1, 1, 31, 0, 3, 135000, 270000, |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1093 | ®->SR11, ®->SR10); |
| 1094 | /* reg->SR10 = 80; // MCLK == 286000 */ |
| 1095 | /* reg->SR11 = 125; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1098 | reg->SR12 = (r << 6) | (n & 0x3f); |
| 1099 | reg->SR13 = m & 0xff; |
| 1100 | reg->SR29 = (r & 4) | (m & 0x100) >> 5 | (n & 0x40) >> 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
| 1102 | if (var->bits_per_pixel < 24) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1103 | reg->MMPR0 -= 0x8000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1105 | reg->MMPR0 -= 0x4000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
| 1107 | if (timings.interlaced) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1108 | reg->CR42 = 0x20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1110 | reg->CR42 = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1112 | reg->CR34 = 0x10; /* display fifo */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | |
| 1114 | i = ((((timings.HTotal >> 3) - 5) & 0x100) >> 8) | |
| 1115 | ((((timings.HDisplay >> 3) - 1) & 0x100) >> 7) | |
| 1116 | ((((timings.HSyncStart >> 3) - 1) & 0x100) >> 6) | |
| 1117 | ((timings.HSyncStart & 0x800) >> 7); |
| 1118 | |
| 1119 | if ((timings.HSyncEnd >> 3) - (timings.HSyncStart >> 3) > 64) |
| 1120 | i |= 0x08; |
| 1121 | if ((timings.HSyncEnd >> 3) - (timings.HSyncStart >> 3) > 32) |
| 1122 | i |= 0x20; |
| 1123 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1124 | j = (reg->CRTC[0] + ((i & 0x01) << 8) + |
| 1125 | reg->CRTC[4] + ((i & 0x10) << 4) + 1) / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1127 | if (j - (reg->CRTC[4] + ((i & 0x10) << 4)) < 4) { |
| 1128 | if (reg->CRTC[4] + ((i & 0x10) << 4) + 4 <= |
| 1129 | reg->CRTC[0] + ((i & 0x01) << 8)) |
| 1130 | j = reg->CRTC[4] + ((i & 0x10) << 4) + 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1132 | j = reg->CRTC[0] + ((i & 0x01) << 8) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1135 | reg->CR3B = j & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | i |= (j & 0x100) >> 2; |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1137 | reg->CR3C = (reg->CRTC[0] + ((i & 0x01) << 8)) / 2; |
| 1138 | reg->CR5D = i; |
| 1139 | reg->CR5E = (((timings.VTotal - 2) & 0x400) >> 10) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | (((timings.VDisplay - 1) & 0x400) >> 9) | |
| 1141 | (((timings.VSyncStart) & 0x400) >> 8) | |
| 1142 | (((timings.VSyncStart) & 0x400) >> 6) | 0x40; |
| 1143 | width = (var->xres_virtual * ((var->bits_per_pixel+7) / 8)) >> 3; |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1144 | reg->CR91 = reg->CRTC[19] = 0xff & width; |
| 1145 | reg->CR51 = (0x300 & width) >> 4; |
| 1146 | reg->CR90 = 0x80 | (width >> 8); |
| 1147 | reg->MiscOutReg |= 0x0c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
| 1149 | /* Set frame buffer description. */ |
| 1150 | |
| 1151 | if (var->bits_per_pixel <= 8) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1152 | reg->CR50 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | else if (var->bits_per_pixel <= 16) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1154 | reg->CR50 = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1156 | reg->CR50 = 0x30; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
| 1158 | if (var->xres_virtual <= 640) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1159 | reg->CR50 |= 0x40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | else if (var->xres_virtual == 800) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1161 | reg->CR50 |= 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | else if (var->xres_virtual == 1024) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1163 | reg->CR50 |= 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | else if (var->xres_virtual == 1152) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1165 | reg->CR50 |= 0x01; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | else if (var->xres_virtual == 1280) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1167 | reg->CR50 |= 0xc0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | else if (var->xres_virtual == 1600) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1169 | reg->CR50 |= 0x81; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1171 | reg->CR50 |= 0xc1; /* Use GBD */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1173 | if (par->chip == S3_SAVAGE2000) |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1174 | reg->CR33 = 0x08; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | else |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1176 | reg->CR33 = 0x20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1178 | reg->CRTC[0x17] = 0xeb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1180 | reg->CR67 |= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1182 | vga_out8(0x3d4, 0x36, par); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1183 | reg->CR36 = vga_in8(0x3d5, par); |
| 1184 | vga_out8(0x3d4, 0x68, par); |
| 1185 | reg->CR68 = vga_in8(0x3d5, par); |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1186 | reg->CR69 = 0; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1187 | vga_out8(0x3d4, 0x6f, par); |
| 1188 | reg->CR6F = vga_in8(0x3d5, par); |
| 1189 | vga_out8(0x3d4, 0x86, par); |
| 1190 | reg->CR86 = vga_in8(0x3d5, par); |
| 1191 | vga_out8(0x3d4, 0x88, par); |
| 1192 | reg->CR88 = vga_in8(0x3d5, par) | 0x08; |
| 1193 | vga_out8(0x3d4, 0xb0, par); |
| 1194 | reg->CRB0 = vga_in8(0x3d5, par) | 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | /* --------------------------------------------------------------------- */ |
| 1200 | |
| 1201 | /* |
| 1202 | * Set a single color register. Return != 0 for invalid regno. |
| 1203 | */ |
| 1204 | static int savagefb_setcolreg(unsigned regno, |
| 1205 | unsigned red, |
| 1206 | unsigned green, |
| 1207 | unsigned blue, |
| 1208 | unsigned transp, |
| 1209 | struct fb_info *info) |
| 1210 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 1211 | struct savagefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
| 1213 | if (regno >= NR_PALETTE) |
| 1214 | return -EINVAL; |
| 1215 | |
| 1216 | par->palette[regno].red = red; |
| 1217 | par->palette[regno].green = green; |
| 1218 | par->palette[regno].blue = blue; |
| 1219 | par->palette[regno].transp = transp; |
| 1220 | |
| 1221 | switch (info->var.bits_per_pixel) { |
| 1222 | case 8: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1223 | vga_out8(0x3c8, regno, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1225 | vga_out8(0x3c9, red >> 10, par); |
| 1226 | vga_out8(0x3c9, green >> 10, par); |
| 1227 | vga_out8(0x3c9, blue >> 10, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | break; |
| 1229 | |
| 1230 | case 16: |
| 1231 | if (regno < 16) |
| 1232 | ((u32 *)info->pseudo_palette)[regno] = |
| 1233 | ((red & 0xf800) ) | |
| 1234 | ((green & 0xfc00) >> 5) | |
| 1235 | ((blue & 0xf800) >> 11); |
| 1236 | break; |
| 1237 | |
| 1238 | case 24: |
| 1239 | if (regno < 16) |
| 1240 | ((u32 *)info->pseudo_palette)[regno] = |
| 1241 | ((red & 0xff00) << 8) | |
| 1242 | ((green & 0xff00) ) | |
| 1243 | ((blue & 0xff00) >> 8); |
| 1244 | break; |
| 1245 | case 32: |
| 1246 | if (regno < 16) |
| 1247 | ((u32 *)info->pseudo_palette)[regno] = |
| 1248 | ((transp & 0xff00) << 16) | |
| 1249 | ((red & 0xff00) << 8) | |
| 1250 | ((green & 0xff00) ) | |
| 1251 | ((blue & 0xff00) >> 8); |
| 1252 | break; |
| 1253 | |
| 1254 | default: |
| 1255 | return 1; |
| 1256 | } |
| 1257 | |
| 1258 | return 0; |
| 1259 | } |
| 1260 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1261 | static void savagefb_set_par_int(struct savagefb_par *par, struct savage_reg *reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | { |
| 1263 | unsigned char tmp, cr3a, cr66, cr67; |
| 1264 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1265 | DBG("savagefb_set_par_int"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1267 | par->SavageWaitIdle(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1269 | vga_out8(0x3c2, 0x23, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1271 | vga_out16(0x3d4, 0x4838, par); |
| 1272 | vga_out16(0x3d4, 0xa539, par); |
| 1273 | vga_out16(0x3c4, 0x0608, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1275 | vgaHWProtect(par, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | |
| 1277 | /* |
| 1278 | * Some Savage/MX and /IX systems go nuts when trying to exit the |
| 1279 | * server after WindowMaker has displayed a gradient background. I |
| 1280 | * haven't been able to find what causes it, but a non-destructive |
| 1281 | * switch to mode 3 here seems to eliminate the issue. |
| 1282 | */ |
| 1283 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1284 | VerticalRetraceWait(par); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1285 | vga_out8(0x3d4, 0x67, par); |
| 1286 | cr67 = vga_in8(0x3d5, par); |
| 1287 | vga_out8(0x3d5, cr67/*par->CR67*/ & ~0x0c, par); /* no STREAMS yet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1289 | vga_out8(0x3d4, 0x23, par); |
| 1290 | vga_out8(0x3d5, 0x00, par); |
| 1291 | vga_out8(0x3d4, 0x26, par); |
| 1292 | vga_out8(0x3d5, 0x00, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
| 1294 | /* restore extended regs */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1295 | vga_out8(0x3d4, 0x66, par); |
| 1296 | vga_out8(0x3d5, reg->CR66, par); |
| 1297 | vga_out8(0x3d4, 0x3a, par); |
| 1298 | vga_out8(0x3d5, reg->CR3A, par); |
| 1299 | vga_out8(0x3d4, 0x31, par); |
| 1300 | vga_out8(0x3d5, reg->CR31, par); |
| 1301 | vga_out8(0x3d4, 0x32, par); |
| 1302 | vga_out8(0x3d5, reg->CR32, par); |
| 1303 | vga_out8(0x3d4, 0x58, par); |
| 1304 | vga_out8(0x3d5, reg->CR58, par); |
| 1305 | vga_out8(0x3d4, 0x53, par); |
| 1306 | vga_out8(0x3d5, reg->CR53 & 0x7f, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1308 | vga_out16(0x3c4, 0x0608, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
| 1310 | /* Restore DCLK registers. */ |
| 1311 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1312 | vga_out8(0x3c4, 0x0e, par); |
| 1313 | vga_out8(0x3c5, reg->SR0E, par); |
| 1314 | vga_out8(0x3c4, 0x0f, par); |
| 1315 | vga_out8(0x3c5, reg->SR0F, par); |
| 1316 | vga_out8(0x3c4, 0x29, par); |
| 1317 | vga_out8(0x3c5, reg->SR29, par); |
| 1318 | vga_out8(0x3c4, 0x15, par); |
| 1319 | vga_out8(0x3c5, reg->SR15, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | |
| 1321 | /* Restore flat panel expansion regsters. */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1322 | if (par->chip == S3_SAVAGE_MX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | int i; |
| 1324 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1325 | for (i = 0; i < 8; i++) { |
| 1326 | vga_out8(0x3c4, 0x54+i, par); |
| 1327 | vga_out8(0x3c5, reg->SR54[i], par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1331 | vgaHWRestore (par, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
| 1333 | /* extended mode timing registers */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1334 | vga_out8(0x3d4, 0x53, par); |
| 1335 | vga_out8(0x3d5, reg->CR53, par); |
| 1336 | vga_out8(0x3d4, 0x5d, par); |
| 1337 | vga_out8(0x3d5, reg->CR5D, par); |
| 1338 | vga_out8(0x3d4, 0x5e, par); |
| 1339 | vga_out8(0x3d5, reg->CR5E, par); |
| 1340 | vga_out8(0x3d4, 0x3b, par); |
| 1341 | vga_out8(0x3d5, reg->CR3B, par); |
| 1342 | vga_out8(0x3d4, 0x3c, par); |
| 1343 | vga_out8(0x3d5, reg->CR3C, par); |
| 1344 | vga_out8(0x3d4, 0x43, par); |
| 1345 | vga_out8(0x3d5, reg->CR43, par); |
| 1346 | vga_out8(0x3d4, 0x65, par); |
| 1347 | vga_out8(0x3d5, reg->CR65, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | |
| 1349 | /* restore the desired video mode with cr67 */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1350 | vga_out8(0x3d4, 0x67, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | /* following part not present in X11 driver */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1352 | cr67 = vga_in8(0x3d5, par) & 0xf; |
| 1353 | vga_out8(0x3d5, 0x50 | cr67, par); |
| 1354 | udelay(10000); |
| 1355 | vga_out8(0x3d4, 0x67, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | /* end of part */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1357 | vga_out8(0x3d5, reg->CR67 & ~0x0c, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
| 1359 | /* other mode timing and extended regs */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1360 | vga_out8(0x3d4, 0x34, par); |
| 1361 | vga_out8(0x3d5, reg->CR34, par); |
| 1362 | vga_out8(0x3d4, 0x40, par); |
| 1363 | vga_out8(0x3d5, reg->CR40, par); |
| 1364 | vga_out8(0x3d4, 0x42, par); |
| 1365 | vga_out8(0x3d5, reg->CR42, par); |
| 1366 | vga_out8(0x3d4, 0x45, par); |
| 1367 | vga_out8(0x3d5, reg->CR45, par); |
| 1368 | vga_out8(0x3d4, 0x50, par); |
| 1369 | vga_out8(0x3d5, reg->CR50, par); |
| 1370 | vga_out8(0x3d4, 0x51, par); |
| 1371 | vga_out8(0x3d5, reg->CR51, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
| 1373 | /* memory timings */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1374 | vga_out8(0x3d4, 0x36, par); |
| 1375 | vga_out8(0x3d5, reg->CR36, par); |
| 1376 | vga_out8(0x3d4, 0x60, par); |
| 1377 | vga_out8(0x3d5, reg->CR60, par); |
| 1378 | vga_out8(0x3d4, 0x68, par); |
| 1379 | vga_out8(0x3d5, reg->CR68, par); |
| 1380 | vga_out8(0x3d4, 0x69, par); |
| 1381 | vga_out8(0x3d5, reg->CR69, par); |
| 1382 | vga_out8(0x3d4, 0x6f, par); |
| 1383 | vga_out8(0x3d5, reg->CR6F, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1385 | vga_out8(0x3d4, 0x33, par); |
| 1386 | vga_out8(0x3d5, reg->CR33, par); |
| 1387 | vga_out8(0x3d4, 0x86, par); |
| 1388 | vga_out8(0x3d5, reg->CR86, par); |
| 1389 | vga_out8(0x3d4, 0x88, par); |
| 1390 | vga_out8(0x3d5, reg->CR88, par); |
| 1391 | vga_out8(0x3d4, 0x90, par); |
| 1392 | vga_out8(0x3d5, reg->CR90, par); |
| 1393 | vga_out8(0x3d4, 0x91, par); |
| 1394 | vga_out8(0x3d5, reg->CR91, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
| 1396 | if (par->chip == S3_SAVAGE4) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1397 | vga_out8(0x3d4, 0xb0, par); |
| 1398 | vga_out8(0x3d5, reg->CRB0, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1401 | vga_out8(0x3d4, 0x32, par); |
| 1402 | vga_out8(0x3d5, reg->CR32, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
| 1404 | /* unlock extended seq regs */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1405 | vga_out8(0x3c4, 0x08, par); |
| 1406 | vga_out8(0x3c5, 0x06, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | |
| 1408 | /* Restore extended sequencer regs for MCLK. SR10 == 255 indicates |
| 1409 | * that we should leave the default SR10 and SR11 values there. |
| 1410 | */ |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 1411 | if (reg->SR10 != 255) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1412 | vga_out8(0x3c4, 0x10, par); |
| 1413 | vga_out8(0x3c5, reg->SR10, par); |
| 1414 | vga_out8(0x3c4, 0x11, par); |
| 1415 | vga_out8(0x3c5, reg->SR11, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | /* restore extended seq regs for dclk */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1419 | vga_out8(0x3c4, 0x0e, par); |
| 1420 | vga_out8(0x3c5, reg->SR0E, par); |
| 1421 | vga_out8(0x3c4, 0x0f, par); |
| 1422 | vga_out8(0x3c5, reg->SR0F, par); |
| 1423 | vga_out8(0x3c4, 0x12, par); |
| 1424 | vga_out8(0x3c5, reg->SR12, par); |
| 1425 | vga_out8(0x3c4, 0x13, par); |
| 1426 | vga_out8(0x3c5, reg->SR13, par); |
| 1427 | vga_out8(0x3c4, 0x29, par); |
| 1428 | vga_out8(0x3c5, reg->SR29, par); |
| 1429 | vga_out8(0x3c4, 0x18, par); |
| 1430 | vga_out8(0x3c5, reg->SR18, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
| 1432 | /* load new m, n pll values for dclk & mclk */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1433 | vga_out8(0x3c4, 0x15, par); |
| 1434 | tmp = vga_in8(0x3c5, par) & ~0x21; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1436 | vga_out8(0x3c5, tmp | 0x03, par); |
| 1437 | vga_out8(0x3c5, tmp | 0x23, par); |
| 1438 | vga_out8(0x3c5, tmp | 0x03, par); |
| 1439 | vga_out8(0x3c5, reg->SR15, par); |
| 1440 | udelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1442 | vga_out8(0x3c4, 0x30, par); |
| 1443 | vga_out8(0x3c5, reg->SR30, par); |
| 1444 | vga_out8(0x3c4, 0x08, par); |
| 1445 | vga_out8(0x3c5, reg->SR08, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
| 1447 | /* now write out cr67 in full, possibly starting STREAMS */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1448 | VerticalRetraceWait(par); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1449 | vga_out8(0x3d4, 0x67, par); |
| 1450 | vga_out8(0x3d5, reg->CR67, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1452 | vga_out8(0x3d4, 0x66, par); |
| 1453 | cr66 = vga_in8(0x3d5, par); |
| 1454 | vga_out8(0x3d5, cr66 | 0x80, par); |
| 1455 | vga_out8(0x3d4, 0x3a, par); |
| 1456 | cr3a = vga_in8(0x3d5, par); |
| 1457 | vga_out8(0x3d5, cr3a | 0x80, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
| 1459 | if (par->chip != S3_SAVAGE_MX) { |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1460 | VerticalRetraceWait(par); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1461 | savage_out32(FIFO_CONTROL_REG, reg->MMPR0, par); |
| 1462 | par->SavageWaitIdle(par); |
| 1463 | savage_out32(MIU_CONTROL_REG, reg->MMPR1, par); |
| 1464 | par->SavageWaitIdle(par); |
| 1465 | savage_out32(STREAMS_TIMEOUT_REG, reg->MMPR2, par); |
| 1466 | par->SavageWaitIdle(par); |
| 1467 | savage_out32(MISC_TIMEOUT_REG, reg->MMPR3, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1470 | vga_out8(0x3d4, 0x66, par); |
| 1471 | vga_out8(0x3d5, cr66, par); |
| 1472 | vga_out8(0x3d4, 0x3a, par); |
| 1473 | vga_out8(0x3d5, cr3a, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1475 | SavageSetup2DEngine(par); |
| 1476 | vgaHWProtect(par, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1479 | static void savagefb_update_start(struct savagefb_par *par, |
| 1480 | struct fb_var_screeninfo *var) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | { |
| 1482 | int base; |
| 1483 | |
| 1484 | base = ((var->yoffset * var->xres_virtual + (var->xoffset & ~1)) |
| 1485 | * ((var->bits_per_pixel+7) / 8)) >> 2; |
| 1486 | |
| 1487 | /* now program the start address registers */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1488 | vga_out16(0x3d4, (base & 0x00ff00) | 0x0c, par); |
| 1489 | vga_out16(0x3d4, ((base & 0x00ff) << 8) | 0x0d, par); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1490 | vga_out8(0x3d4, 0x69, par); |
| 1491 | vga_out8(0x3d5, (base & 0x7f0000) >> 16, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | |
| 1495 | static void savagefb_set_fix(struct fb_info *info) |
| 1496 | { |
| 1497 | info->fix.line_length = info->var.xres_virtual * |
| 1498 | info->var.bits_per_pixel / 8; |
| 1499 | |
Antonino A. Daplas | 6d83b0b | 2005-11-08 21:39:05 -0800 | [diff] [blame] | 1500 | if (info->var.bits_per_pixel == 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | info->fix.visual = FB_VISUAL_PSEUDOCOLOR; |
Antonino A. Daplas | 6d83b0b | 2005-11-08 21:39:05 -0800 | [diff] [blame] | 1502 | info->fix.xpanstep = 4; |
| 1503 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
Antonino A. Daplas | 6d83b0b | 2005-11-08 21:39:05 -0800 | [diff] [blame] | 1505 | info->fix.xpanstep = 2; |
| 1506 | } |
| 1507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1510 | static int savagefb_set_par(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 1512 | struct savagefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | struct fb_var_screeninfo *var = &info->var; |
| 1514 | int err; |
| 1515 | |
| 1516 | DBG("savagefb_set_par"); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1517 | err = savagefb_decode_var(var, par, &par->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | if (err) |
| 1519 | return err; |
| 1520 | |
| 1521 | if (par->dacSpeedBpp <= 0) { |
| 1522 | if (var->bits_per_pixel > 24) |
| 1523 | par->dacSpeedBpp = par->clock[3]; |
| 1524 | else if (var->bits_per_pixel >= 24) |
| 1525 | par->dacSpeedBpp = par->clock[2]; |
| 1526 | else if ((var->bits_per_pixel > 8) && (var->bits_per_pixel < 24)) |
| 1527 | par->dacSpeedBpp = par->clock[1]; |
| 1528 | else if (var->bits_per_pixel <= 8) |
| 1529 | par->dacSpeedBpp = par->clock[0]; |
| 1530 | } |
| 1531 | |
| 1532 | /* Set ramdac limits */ |
| 1533 | par->maxClock = par->dacSpeedBpp; |
| 1534 | par->minClock = 10000; |
| 1535 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1536 | savagefb_set_par_int(par, &par->state); |
| 1537 | fb_set_cmap(&info->cmap, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | savagefb_set_fix(info); |
| 1539 | savagefb_set_clip(info); |
| 1540 | |
Antonino A. Daplas | d8ad7e0 | 2007-03-16 13:38:18 -0800 | [diff] [blame] | 1541 | SavagePrintRegs(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | return 0; |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | * Pan or Wrap the Display |
| 1547 | */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1548 | static int savagefb_pan_display(struct fb_var_screeninfo *var, |
| 1549 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 1551 | struct savagefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1553 | savagefb_update_start(par, var); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | return 0; |
| 1555 | } |
| 1556 | |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1557 | static int savagefb_blank(int blank, struct fb_info *info) |
| 1558 | { |
| 1559 | struct savagefb_par *par = info->par; |
| 1560 | u8 sr8 = 0, srd = 0; |
| 1561 | |
| 1562 | if (par->display_type == DISP_CRT) { |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1563 | vga_out8(0x3c4, 0x08, par); |
| 1564 | sr8 = vga_in8(0x3c5, par); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1565 | sr8 |= 0x06; |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1566 | vga_out8(0x3c5, sr8, par); |
| 1567 | vga_out8(0x3c4, 0x0d, par); |
| 1568 | srd = vga_in8(0x3c5, par); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1569 | srd &= 0x03; |
| 1570 | |
| 1571 | switch (blank) { |
| 1572 | case FB_BLANK_UNBLANK: |
| 1573 | case FB_BLANK_NORMAL: |
| 1574 | break; |
| 1575 | case FB_BLANK_VSYNC_SUSPEND: |
| 1576 | srd |= 0x10; |
| 1577 | break; |
| 1578 | case FB_BLANK_HSYNC_SUSPEND: |
| 1579 | srd |= 0x40; |
| 1580 | break; |
| 1581 | case FB_BLANK_POWERDOWN: |
| 1582 | srd |= 0x50; |
| 1583 | break; |
| 1584 | } |
| 1585 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1586 | vga_out8(0x3c4, 0x0d, par); |
| 1587 | vga_out8(0x3c5, srd, par); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | if (par->display_type == DISP_LCD || |
| 1591 | par->display_type == DISP_DFP) { |
| 1592 | switch(blank) { |
| 1593 | case FB_BLANK_UNBLANK: |
| 1594 | case FB_BLANK_NORMAL: |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1595 | vga_out8(0x3c4, 0x31, par); /* SR31 bit 4 - FP enable */ |
| 1596 | vga_out8(0x3c5, vga_in8(0x3c5, par) | 0x10, par); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1597 | break; |
| 1598 | case FB_BLANK_VSYNC_SUSPEND: |
| 1599 | case FB_BLANK_HSYNC_SUSPEND: |
| 1600 | case FB_BLANK_POWERDOWN: |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1601 | vga_out8(0x3c4, 0x31, par); /* SR31 bit 4 - FP enable */ |
| 1602 | vga_out8(0x3c5, vga_in8(0x3c5, par) & ~0x10, par); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1603 | break; |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | return (blank == FB_BLANK_NORMAL) ? 1 : 0; |
| 1608 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 1610 | static void savagefb_save_state(struct fb_info *info) |
| 1611 | { |
| 1612 | struct savagefb_par *par = info->par; |
| 1613 | |
| 1614 | savage_get_default_par(par, &par->save); |
| 1615 | } |
| 1616 | |
| 1617 | static void savagefb_restore_state(struct fb_info *info) |
| 1618 | { |
| 1619 | struct savagefb_par *par = info->par; |
| 1620 | |
| 1621 | savagefb_blank(FB_BLANK_POWERDOWN, info); |
| 1622 | savage_set_default_par(par, &par->save); |
| 1623 | savagefb_blank(FB_BLANK_UNBLANK, info); |
| 1624 | } |
| 1625 | |
Antonino A. Daplas | 22d832e | 2007-05-08 00:38:36 -0700 | [diff] [blame] | 1626 | static int savagefb_open(struct fb_info *info, int user) |
| 1627 | { |
| 1628 | struct savagefb_par *par = info->par; |
| 1629 | |
| 1630 | mutex_lock(&par->open_lock); |
| 1631 | |
| 1632 | if (!par->open_count) { |
| 1633 | memset(&par->vgastate, 0, sizeof(par->vgastate)); |
| 1634 | par->vgastate.flags = VGA_SAVE_CMAP | VGA_SAVE_FONTS | |
| 1635 | VGA_SAVE_MODE; |
| 1636 | par->vgastate.vgabase = par->mmio.vbase + 0x8000; |
| 1637 | save_vga(&par->vgastate); |
| 1638 | savage_get_default_par(par, &par->initial); |
| 1639 | } |
| 1640 | |
| 1641 | par->open_count++; |
| 1642 | mutex_unlock(&par->open_lock); |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | static int savagefb_release(struct fb_info *info, int user) |
| 1647 | { |
| 1648 | struct savagefb_par *par = info->par; |
| 1649 | |
| 1650 | mutex_lock(&par->open_lock); |
| 1651 | |
| 1652 | if (par->open_count == 1) { |
| 1653 | savage_set_default_par(par, &par->initial); |
| 1654 | restore_vga(&par->vgastate); |
| 1655 | } |
| 1656 | |
| 1657 | par->open_count--; |
| 1658 | mutex_unlock(&par->open_lock); |
| 1659 | return 0; |
| 1660 | } |
| 1661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | static struct fb_ops savagefb_ops = { |
| 1663 | .owner = THIS_MODULE, |
Antonino A. Daplas | 22d832e | 2007-05-08 00:38:36 -0700 | [diff] [blame] | 1664 | .fb_open = savagefb_open, |
| 1665 | .fb_release = savagefb_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | .fb_check_var = savagefb_check_var, |
| 1667 | .fb_set_par = savagefb_set_par, |
| 1668 | .fb_setcolreg = savagefb_setcolreg, |
| 1669 | .fb_pan_display = savagefb_pan_display, |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1670 | .fb_blank = savagefb_blank, |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 1671 | .fb_save_state = savagefb_save_state, |
| 1672 | .fb_restore_state = savagefb_restore_state, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | #if defined(CONFIG_FB_SAVAGE_ACCEL) |
| 1674 | .fb_fillrect = savagefb_fillrect, |
| 1675 | .fb_copyarea = savagefb_copyarea, |
| 1676 | .fb_imageblit = savagefb_imageblit, |
| 1677 | .fb_sync = savagefb_sync, |
| 1678 | #else |
| 1679 | .fb_fillrect = cfb_fillrect, |
| 1680 | .fb_copyarea = cfb_copyarea, |
| 1681 | .fb_imageblit = cfb_imageblit, |
| 1682 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | }; |
| 1684 | |
| 1685 | /* --------------------------------------------------------------------- */ |
| 1686 | |
| 1687 | static struct fb_var_screeninfo __devinitdata savagefb_var800x600x8 = { |
| 1688 | .accel_flags = FB_ACCELF_TEXT, |
| 1689 | .xres = 800, |
| 1690 | .yres = 600, |
| 1691 | .xres_virtual = 800, |
| 1692 | .yres_virtual = 600, |
| 1693 | .bits_per_pixel = 8, |
| 1694 | .pixclock = 25000, |
| 1695 | .left_margin = 88, |
| 1696 | .right_margin = 40, |
| 1697 | .upper_margin = 23, |
| 1698 | .lower_margin = 1, |
| 1699 | .hsync_len = 128, |
| 1700 | .vsync_len = 4, |
| 1701 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 1702 | .vmode = FB_VMODE_NONINTERLACED |
| 1703 | }; |
| 1704 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1705 | static void savage_enable_mmio(struct savagefb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | { |
| 1707 | unsigned char val; |
| 1708 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1709 | DBG("savage_enable_mmio\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1711 | val = vga_in8(0x3c3, par); |
| 1712 | vga_out8(0x3c3, val | 0x01, par); |
| 1713 | val = vga_in8(0x3cc, par); |
| 1714 | vga_out8(0x3c2, val | 0x01, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | |
| 1716 | if (par->chip >= S3_SAVAGE4) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1717 | vga_out8(0x3d4, 0x40, par); |
| 1718 | val = vga_in8(0x3d5, par); |
| 1719 | vga_out8(0x3d5, val | 1, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1724 | static void savage_disable_mmio(struct savagefb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | { |
| 1726 | unsigned char val; |
| 1727 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1728 | DBG("savage_disable_mmio\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1730 | if (par->chip >= S3_SAVAGE4) { |
| 1731 | vga_out8(0x3d4, 0x40, par); |
| 1732 | val = vga_in8(0x3d5, par); |
| 1733 | vga_out8(0x3d5, val | 1, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1738 | static int __devinit savage_map_mmio(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 1740 | struct savagefb_par *par = info->par; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1741 | DBG("savage_map_mmio"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1743 | if (S3_SAVAGE3D_SERIES(par->chip)) |
| 1744 | par->mmio.pbase = pci_resource_start(par->pcidev, 0) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | SAVAGE_NEWMMIO_REGBASE_S3; |
| 1746 | else |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1747 | par->mmio.pbase = pci_resource_start(par->pcidev, 0) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | SAVAGE_NEWMMIO_REGBASE_S4; |
| 1749 | |
| 1750 | par->mmio.len = SAVAGE_NEWMMIO_REGSIZE; |
| 1751 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1752 | par->mmio.vbase = ioremap(par->mmio.pbase, par->mmio.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | if (!par->mmio.vbase) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1754 | printk("savagefb: unable to map memory mapped IO\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | return -ENOMEM; |
| 1756 | } else |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1757 | printk(KERN_INFO "savagefb: mapped io at %p\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | par->mmio.vbase); |
| 1759 | |
| 1760 | info->fix.mmio_start = par->mmio.pbase; |
| 1761 | info->fix.mmio_len = par->mmio.len; |
| 1762 | |
Al Viro | 0d3e8fe | 2005-04-26 07:43:41 -0700 | [diff] [blame] | 1763 | par->bci_base = (u32 __iomem *)(par->mmio.vbase + BCI_BUFFER_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | par->bci_ptr = 0; |
| 1765 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1766 | savage_enable_mmio(par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1771 | static void savage_unmap_mmio(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 1773 | struct savagefb_par *par = info->par; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1774 | DBG("savage_unmap_mmio"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | |
| 1776 | savage_disable_mmio(par); |
| 1777 | |
| 1778 | if (par->mmio.vbase) { |
Al Viro | 0d3e8fe | 2005-04-26 07:43:41 -0700 | [diff] [blame] | 1779 | iounmap(par->mmio.vbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | par->mmio.vbase = NULL; |
| 1781 | } |
| 1782 | } |
| 1783 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1784 | static int __devinit savage_map_video(struct fb_info *info, |
| 1785 | int video_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 1787 | struct savagefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | int resource; |
| 1789 | |
| 1790 | DBG("savage_map_video"); |
| 1791 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1792 | if (S3_SAVAGE3D_SERIES(par->chip)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | resource = 0; |
| 1794 | else |
| 1795 | resource = 1; |
| 1796 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1797 | par->video.pbase = pci_resource_start(par->pcidev, resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | par->video.len = video_len; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1799 | par->video.vbase = ioremap(par->video.pbase, par->video.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | |
| 1801 | if (!par->video.vbase) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1802 | printk("savagefb: unable to map screen memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | return -ENOMEM; |
| 1804 | } else |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1805 | printk(KERN_INFO "savagefb: mapped framebuffer at %p, " |
| 1806 | "pbase == %x\n", par->video.vbase, par->video.pbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | |
| 1808 | info->fix.smem_start = par->video.pbase; |
| 1809 | info->fix.smem_len = par->video.len - par->cob_size; |
| 1810 | info->screen_base = par->video.vbase; |
| 1811 | |
| 1812 | #ifdef CONFIG_MTRR |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1813 | par->video.mtrr = mtrr_add(par->video.pbase, video_len, |
| 1814 | MTRR_TYPE_WRCOMB, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | #endif |
| 1816 | |
| 1817 | /* Clear framebuffer, it's all white in memory after boot */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1818 | memset_io(par->video.vbase, 0, par->video.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | |
| 1820 | return 0; |
| 1821 | } |
| 1822 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1823 | static void savage_unmap_video(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 1825 | struct savagefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
| 1827 | DBG("savage_unmap_video"); |
| 1828 | |
| 1829 | if (par->video.vbase) { |
| 1830 | #ifdef CONFIG_MTRR |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1831 | mtrr_del(par->video.mtrr, par->video.pbase, par->video.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | #endif |
| 1833 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1834 | iounmap(par->video.vbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | par->video.vbase = NULL; |
| 1836 | info->screen_base = NULL; |
| 1837 | } |
| 1838 | } |
| 1839 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1840 | static int savage_init_hw(struct savagefb_par *par) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | { |
| 1842 | unsigned char config1, m, n, n1, n2, sr8, cr3f, cr66 = 0, tmp; |
| 1843 | |
| 1844 | static unsigned char RamSavage3D[] = { 8, 4, 4, 2 }; |
| 1845 | static unsigned char RamSavage4[] = { 2, 4, 8, 12, 16, 32, 64, 32 }; |
| 1846 | static unsigned char RamSavageMX[] = { 2, 8, 4, 16, 8, 16, 4, 16 }; |
| 1847 | static unsigned char RamSavageNB[] = { 0, 2, 4, 8, 16, 32, 2, 2 }; |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1848 | int videoRam, videoRambytes, dvi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
| 1850 | DBG("savage_init_hw"); |
| 1851 | |
| 1852 | /* unprotect CRTC[0-7] */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1853 | vga_out8(0x3d4, 0x11, par); |
| 1854 | tmp = vga_in8(0x3d5, par); |
| 1855 | vga_out8(0x3d5, tmp & 0x7f, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | |
| 1857 | /* unlock extended regs */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1858 | vga_out16(0x3d4, 0x4838, par); |
| 1859 | vga_out16(0x3d4, 0xa039, par); |
| 1860 | vga_out16(0x3c4, 0x0608, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1862 | vga_out8(0x3d4, 0x40, par); |
| 1863 | tmp = vga_in8(0x3d5, par); |
| 1864 | vga_out8(0x3d5, tmp & ~0x01, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | |
| 1866 | /* unlock sys regs */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1867 | vga_out8(0x3d4, 0x38, par); |
| 1868 | vga_out8(0x3d5, 0x48, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | |
| 1870 | /* Unlock system registers. */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1871 | vga_out16(0x3d4, 0x4838, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | |
| 1873 | /* Next go on to detect amount of installed ram */ |
| 1874 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1875 | vga_out8(0x3d4, 0x36, par); /* for register CR36 (CONFG_REG1), */ |
| 1876 | config1 = vga_in8(0x3d5, par); /* get amount of vram installed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | |
| 1878 | /* Compute the amount of video memory and offscreen memory. */ |
| 1879 | |
| 1880 | switch (par->chip) { |
| 1881 | case S3_SAVAGE3D: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1882 | videoRam = RamSavage3D[(config1 & 0xC0) >> 6 ] * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | break; |
| 1884 | |
| 1885 | case S3_SAVAGE4: |
| 1886 | /* |
| 1887 | * The Savage4 has one ugly special case to consider. On |
| 1888 | * systems with 4 banks of 2Mx32 SDRAM, the BIOS says 4MB |
| 1889 | * when it really means 8MB. Why do it the same when you |
| 1890 | * can do it different... |
| 1891 | */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1892 | vga_out8(0x3d4, 0x68, par); /* memory control 1 */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1893 | if ((vga_in8(0x3d5, par) & 0xC0) == (0x01 << 6)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | RamSavage4[1] = 8; |
| 1895 | |
| 1896 | /*FALLTHROUGH*/ |
| 1897 | |
| 1898 | case S3_SAVAGE2000: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1899 | videoRam = RamSavage4[(config1 & 0xE0) >> 5] * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | break; |
| 1901 | |
| 1902 | case S3_SAVAGE_MX: |
| 1903 | case S3_SUPERSAVAGE: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1904 | videoRam = RamSavageMX[(config1 & 0x0E) >> 1] * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | break; |
| 1906 | |
| 1907 | case S3_PROSAVAGE: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1908 | videoRam = RamSavageNB[(config1 & 0xE0) >> 5] * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | break; |
| 1910 | |
| 1911 | default: |
| 1912 | /* How did we get here? */ |
| 1913 | videoRam = 0; |
| 1914 | break; |
| 1915 | } |
| 1916 | |
| 1917 | videoRambytes = videoRam * 1024; |
| 1918 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1919 | printk(KERN_INFO "savagefb: probed videoram: %dk\n", videoRam); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
| 1921 | /* reset graphics engine to avoid memory corruption */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1922 | vga_out8(0x3d4, 0x66, par); |
| 1923 | cr66 = vga_in8(0x3d5, par); |
| 1924 | vga_out8(0x3d5, cr66 | 0x02, par); |
| 1925 | udelay(10000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1927 | vga_out8(0x3d4, 0x66, par); |
| 1928 | vga_out8(0x3d5, cr66 & ~0x02, par); /* clear reset flag */ |
| 1929 | udelay(10000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
| 1931 | |
| 1932 | /* |
| 1933 | * reset memory interface, 3D engine, AGP master, PCI master, |
| 1934 | * master engine unit, motion compensation/LPB |
| 1935 | */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1936 | vga_out8(0x3d4, 0x3f, par); |
| 1937 | cr3f = vga_in8(0x3d5, par); |
| 1938 | vga_out8(0x3d5, cr3f | 0x08, par); |
| 1939 | udelay(10000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1941 | vga_out8(0x3d4, 0x3f, par); |
| 1942 | vga_out8(0x3d5, cr3f & ~0x08, par); /* clear reset flags */ |
| 1943 | udelay(10000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | |
| 1945 | /* Savage ramdac speeds */ |
| 1946 | par->numClocks = 4; |
| 1947 | par->clock[0] = 250000; |
| 1948 | par->clock[1] = 250000; |
| 1949 | par->clock[2] = 220000; |
| 1950 | par->clock[3] = 220000; |
| 1951 | |
| 1952 | /* detect current mclk */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1953 | vga_out8(0x3c4, 0x08, par); |
| 1954 | sr8 = vga_in8(0x3c5, par); |
| 1955 | vga_out8(0x3c5, 0x06, par); |
| 1956 | vga_out8(0x3c4, 0x10, par); |
| 1957 | n = vga_in8(0x3c5, par); |
| 1958 | vga_out8(0x3c4, 0x11, par); |
| 1959 | m = vga_in8(0x3c5, par); |
| 1960 | vga_out8(0x3c4, 0x08, par); |
| 1961 | vga_out8(0x3c5, sr8, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | m &= 0x7f; |
| 1963 | n1 = n & 0x1f; |
| 1964 | n2 = (n >> 5) & 0x03; |
| 1965 | par->MCLK = ((1431818 * (m+2)) / (n1+2) / (1 << n2) + 50) / 100; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1966 | printk(KERN_INFO "savagefb: Detected current MCLK value of %d kHz\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | par->MCLK); |
| 1968 | |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1969 | /* check for DVI/flat panel */ |
| 1970 | dvi = 0; |
| 1971 | |
| 1972 | if (par->chip == S3_SAVAGE4) { |
| 1973 | unsigned char sr30 = 0x00; |
| 1974 | |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1975 | vga_out8(0x3c4, 0x30, par); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1976 | /* clear bit 1 */ |
Antonino A. Daplas | 1cc650c | 2005-11-07 01:00:41 -0800 | [diff] [blame] | 1977 | vga_out8(0x3c5, vga_in8(0x3c5, par) & ~0x02, par); |
| 1978 | sr30 = vga_in8(0x3c5, par); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1979 | if (sr30 & 0x02 /*0x04 */) { |
| 1980 | dvi = 1; |
| 1981 | printk("savagefb: Digital Flat Panel Detected\n"); |
| 1982 | } |
| 1983 | } |
| 1984 | |
Antonino A. Daplas | 7b6a186 | 2005-09-15 20:58:57 +0800 | [diff] [blame] | 1985 | if (S3_SAVAGE_MOBILE_SERIES(par->chip) && !par->crtonly) |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 1986 | par->display_type = DISP_LCD; |
| 1987 | else if (dvi || (par->chip == S3_SAVAGE4 && par->dvi)) |
| 1988 | par->display_type = DISP_DFP; |
| 1989 | else |
| 1990 | par->display_type = DISP_CRT; |
| 1991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | /* Check LCD panel parrmation */ |
| 1993 | |
Antonino A. Daplas | 7b6a186 | 2005-09-15 20:58:57 +0800 | [diff] [blame] | 1994 | if (par->display_type == DISP_LCD) { |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1995 | unsigned char cr6b = VGArCR(0x6b, par); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 1997 | int panelX = (VGArSEQ(0x61, par) + |
| 1998 | ((VGArSEQ(0x66, par) & 0x02) << 7) + 1) * 8; |
| 1999 | int panelY = (VGArSEQ(0x69, par) + |
| 2000 | ((VGArSEQ(0x6e, par) & 0x70) << 4) + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | |
| 2002 | char * sTechnology = "Unknown"; |
| 2003 | |
| 2004 | /* OK, I admit it. I don't know how to limit the max dot clock |
| 2005 | * for LCD panels of various sizes. I thought I copied the |
| 2006 | * formula from the BIOS, but many users have parrmed me of |
| 2007 | * my folly. |
| 2008 | * |
| 2009 | * Instead, I'll abandon any attempt to automatically limit the |
| 2010 | * clock, and add an LCDClock option to XF86Config. Some day, |
| 2011 | * I should come back to this. |
| 2012 | */ |
| 2013 | |
| 2014 | enum ACTIVE_DISPLAYS { /* These are the bits in CR6B */ |
| 2015 | ActiveCRT = 0x01, |
| 2016 | ActiveLCD = 0x02, |
| 2017 | ActiveTV = 0x04, |
| 2018 | ActiveCRT2 = 0x20, |
| 2019 | ActiveDUO = 0x80 |
| 2020 | }; |
| 2021 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2022 | if ((VGArSEQ(0x39, par) & 0x03) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | sTechnology = "TFT"; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2024 | } else if ((VGArSEQ(0x30, par) & 0x01) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | sTechnology = "DSTN"; |
| 2026 | } else { |
| 2027 | sTechnology = "STN"; |
| 2028 | } |
| 2029 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2030 | printk(KERN_INFO "savagefb: %dx%d %s LCD panel detected %s\n", |
| 2031 | panelX, panelY, sTechnology, |
| 2032 | cr6b & ActiveLCD ? "and active" : "but not active"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2034 | if (cr6b & ActiveLCD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | /* |
| 2036 | * If the LCD is active and panel expansion is enabled, |
| 2037 | * we probably want to kill the HW cursor. |
| 2038 | */ |
| 2039 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2040 | printk(KERN_INFO "savagefb: Limiting video mode to " |
| 2041 | "%dx%d\n", panelX, panelY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | |
| 2043 | par->SavagePanelWidth = panelX; |
| 2044 | par->SavagePanelHeight = panelY; |
| 2045 | |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2046 | } else |
| 2047 | par->display_type = DISP_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2050 | savage_get_default_par(par, &par->state); |
Antonino A. Daplas | 2356614 | 2006-06-26 00:26:23 -0700 | [diff] [blame] | 2051 | par->save = par->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2053 | if (S3_SAVAGE4_SERIES(par->chip)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | /* |
| 2055 | * The Savage4 and ProSavage have COB coherency bugs which |
| 2056 | * render the buffer useless. We disable it. |
| 2057 | */ |
| 2058 | par->cob_index = 2; |
| 2059 | par->cob_size = 0x8000 << par->cob_index; |
| 2060 | par->cob_offset = videoRambytes; |
| 2061 | } else { |
| 2062 | /* We use 128kB for the COB on all chips. */ |
| 2063 | |
| 2064 | par->cob_index = 7; |
| 2065 | par->cob_size = 0x400 << par->cob_index; |
| 2066 | par->cob_offset = videoRambytes - par->cob_size; |
| 2067 | } |
| 2068 | |
| 2069 | return videoRambytes; |
| 2070 | } |
| 2071 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2072 | static int __devinit savage_init_fb_info(struct fb_info *info, |
| 2073 | struct pci_dev *dev, |
| 2074 | const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 2076 | struct savagefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | int err = 0; |
| 2078 | |
| 2079 | par->pcidev = dev; |
| 2080 | |
| 2081 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 2082 | info->fix.type_aux = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | info->fix.ypanstep = 1; |
| 2084 | info->fix.ywrapstep = 0; |
| 2085 | info->fix.accel = id->driver_data; |
| 2086 | |
| 2087 | switch (info->fix.accel) { |
| 2088 | case FB_ACCEL_SUPERSAVAGE: |
| 2089 | par->chip = S3_SUPERSAVAGE; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2090 | snprintf(info->fix.id, 16, "SuperSavage"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | break; |
| 2092 | case FB_ACCEL_SAVAGE4: |
| 2093 | par->chip = S3_SAVAGE4; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2094 | snprintf(info->fix.id, 16, "Savage4"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | break; |
| 2096 | case FB_ACCEL_SAVAGE3D: |
| 2097 | par->chip = S3_SAVAGE3D; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2098 | snprintf(info->fix.id, 16, "Savage3D"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | break; |
| 2100 | case FB_ACCEL_SAVAGE3D_MV: |
| 2101 | par->chip = S3_SAVAGE3D; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2102 | snprintf(info->fix.id, 16, "Savage3D-MV"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | break; |
| 2104 | case FB_ACCEL_SAVAGE2000: |
| 2105 | par->chip = S3_SAVAGE2000; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2106 | snprintf(info->fix.id, 16, "Savage2000"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | break; |
| 2108 | case FB_ACCEL_SAVAGE_MX_MV: |
| 2109 | par->chip = S3_SAVAGE_MX; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2110 | snprintf(info->fix.id, 16, "Savage/MX-MV"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | break; |
| 2112 | case FB_ACCEL_SAVAGE_MX: |
| 2113 | par->chip = S3_SAVAGE_MX; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2114 | snprintf(info->fix.id, 16, "Savage/MX"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | break; |
| 2116 | case FB_ACCEL_SAVAGE_IX_MV: |
| 2117 | par->chip = S3_SAVAGE_MX; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2118 | snprintf(info->fix.id, 16, "Savage/IX-MV"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | break; |
| 2120 | case FB_ACCEL_SAVAGE_IX: |
| 2121 | par->chip = S3_SAVAGE_MX; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2122 | snprintf(info->fix.id, 16, "Savage/IX"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | break; |
| 2124 | case FB_ACCEL_PROSAVAGE_PM: |
| 2125 | par->chip = S3_PROSAVAGE; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2126 | snprintf(info->fix.id, 16, "ProSavagePM"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | break; |
| 2128 | case FB_ACCEL_PROSAVAGE_KM: |
| 2129 | par->chip = S3_PROSAVAGE; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2130 | snprintf(info->fix.id, 16, "ProSavageKM"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | break; |
| 2132 | case FB_ACCEL_S3TWISTER_P: |
Antonino A. Daplas | 7b6a186 | 2005-09-15 20:58:57 +0800 | [diff] [blame] | 2133 | par->chip = S3_PROSAVAGE; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2134 | snprintf(info->fix.id, 16, "TwisterP"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | break; |
| 2136 | case FB_ACCEL_S3TWISTER_K: |
Antonino A. Daplas | 7b6a186 | 2005-09-15 20:58:57 +0800 | [diff] [blame] | 2137 | par->chip = S3_PROSAVAGE; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2138 | snprintf(info->fix.id, 16, "TwisterK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | break; |
| 2140 | case FB_ACCEL_PROSAVAGE_DDR: |
Antonino A. Daplas | 7b6a186 | 2005-09-15 20:58:57 +0800 | [diff] [blame] | 2141 | par->chip = S3_PROSAVAGE; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2142 | snprintf(info->fix.id, 16, "ProSavageDDR"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | break; |
| 2144 | case FB_ACCEL_PROSAVAGE_DDRK: |
| 2145 | par->chip = S3_PROSAVAGE; |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2146 | snprintf(info->fix.id, 16, "ProSavage8"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | break; |
| 2148 | } |
| 2149 | |
| 2150 | if (S3_SAVAGE3D_SERIES(par->chip)) { |
| 2151 | par->SavageWaitIdle = savage3D_waitidle; |
| 2152 | par->SavageWaitFifo = savage3D_waitfifo; |
| 2153 | } else if (S3_SAVAGE4_SERIES(par->chip) || |
| 2154 | S3_SUPERSAVAGE == par->chip) { |
| 2155 | par->SavageWaitIdle = savage4_waitidle; |
| 2156 | par->SavageWaitFifo = savage4_waitfifo; |
| 2157 | } else { |
| 2158 | par->SavageWaitIdle = savage2000_waitidle; |
| 2159 | par->SavageWaitFifo = savage2000_waitfifo; |
| 2160 | } |
| 2161 | |
| 2162 | info->var.nonstd = 0; |
| 2163 | info->var.activate = FB_ACTIVATE_NOW; |
| 2164 | info->var.width = -1; |
| 2165 | info->var.height = -1; |
| 2166 | info->var.accel_flags = 0; |
| 2167 | |
| 2168 | info->fbops = &savagefb_ops; |
| 2169 | info->flags = FBINFO_DEFAULT | |
| 2170 | FBINFO_HWACCEL_YPAN | |
| 2171 | FBINFO_HWACCEL_XPAN; |
| 2172 | |
| 2173 | info->pseudo_palette = par->pseudo_palette; |
| 2174 | |
| 2175 | #if defined(CONFIG_FB_SAVAGE_ACCEL) |
| 2176 | /* FIFO size + padding for commands */ |
| 2177 | info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL); |
| 2178 | |
| 2179 | err = -ENOMEM; |
| 2180 | if (info->pixmap.addr) { |
| 2181 | memset(info->pixmap.addr, 0, 8*1024); |
| 2182 | info->pixmap.size = 8*1024; |
| 2183 | info->pixmap.scan_align = 4; |
| 2184 | info->pixmap.buf_align = 4; |
James Simmons | 58a6064 | 2005-06-21 17:17:08 -0700 | [diff] [blame] | 2185 | info->pixmap.access_align = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2187 | err = fb_alloc_cmap(&info->cmap, NR_PALETTE, 0); |
Olaf Hering | 6062bfa | 2005-09-09 13:04:55 -0700 | [diff] [blame] | 2188 | if (!err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | info->flags |= FBINFO_HWACCEL_COPYAREA | |
| 2190 | FBINFO_HWACCEL_FILLRECT | |
| 2191 | FBINFO_HWACCEL_IMAGEBLIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | } |
| 2193 | #endif |
| 2194 | return err; |
| 2195 | } |
| 2196 | |
| 2197 | /* --------------------------------------------------------------------- */ |
| 2198 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2199 | static int __devinit savagefb_probe(struct pci_dev* dev, |
| 2200 | const struct pci_device_id* id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | { |
| 2202 | struct fb_info *info; |
| 2203 | struct savagefb_par *par; |
| 2204 | u_int h_sync, v_sync; |
| 2205 | int err, lpitch; |
| 2206 | int video_len; |
| 2207 | |
| 2208 | DBG("savagefb_probe"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | |
| 2210 | info = framebuffer_alloc(sizeof(struct savagefb_par), &dev->dev); |
| 2211 | if (!info) |
| 2212 | return -ENOMEM; |
| 2213 | par = info->par; |
Antonino A. Daplas | 22d832e | 2007-05-08 00:38:36 -0700 | [diff] [blame] | 2214 | mutex_init(&par->open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | err = pci_enable_device(dev); |
| 2216 | if (err) |
| 2217 | goto failed_enable; |
| 2218 | |
Olaf Hering | 6062bfa | 2005-09-09 13:04:55 -0700 | [diff] [blame] | 2219 | if ((err = pci_request_regions(dev, "savagefb"))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | printk(KERN_ERR "cannot request PCI regions\n"); |
| 2221 | goto failed_enable; |
| 2222 | } |
| 2223 | |
| 2224 | err = -ENOMEM; |
| 2225 | |
Olaf Hering | 6062bfa | 2005-09-09 13:04:55 -0700 | [diff] [blame] | 2226 | if ((err = savage_init_fb_info(info, dev, id))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | goto failed_init; |
| 2228 | |
| 2229 | err = savage_map_mmio(info); |
| 2230 | if (err) |
| 2231 | goto failed_mmio; |
| 2232 | |
| 2233 | video_len = savage_init_hw(par); |
Olaf Hering | 6062bfa | 2005-09-09 13:04:55 -0700 | [diff] [blame] | 2234 | /* FIXME: cant be negative */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | if (video_len < 0) { |
| 2236 | err = video_len; |
| 2237 | goto failed_mmio; |
| 2238 | } |
| 2239 | |
| 2240 | err = savage_map_video(info, video_len); |
| 2241 | if (err) |
| 2242 | goto failed_video; |
| 2243 | |
| 2244 | INIT_LIST_HEAD(&info->modelist); |
| 2245 | #if defined(CONFIG_FB_SAVAGE_I2C) |
| 2246 | savagefb_create_i2c_busses(info); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2247 | savagefb_probe_i2c_connector(info, &par->edid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | fb_edid_to_monspecs(par->edid, &info->monspecs); |
Antonino A. Daplas | 8d57f22 | 2006-03-11 03:27:25 -0800 | [diff] [blame] | 2249 | kfree(par->edid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | fb_videomode_to_modelist(info->monspecs.modedb, |
| 2251 | info->monspecs.modedb_len, |
| 2252 | &info->modelist); |
| 2253 | #endif |
| 2254 | info->var = savagefb_var800x600x8; |
| 2255 | |
| 2256 | if (mode_option) { |
| 2257 | fb_find_mode(&info->var, info, mode_option, |
| 2258 | info->monspecs.modedb, info->monspecs.modedb_len, |
| 2259 | NULL, 8); |
| 2260 | } else if (info->monspecs.modedb != NULL) { |
Geert Uytterhoeven | 9791d76 | 2007-02-12 00:55:19 -0800 | [diff] [blame] | 2261 | const struct fb_videomode *mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | |
Geert Uytterhoeven | 9791d76 | 2007-02-12 00:55:19 -0800 | [diff] [blame] | 2263 | mode = fb_find_best_display(&info->monspecs, &info->modelist); |
| 2264 | savage_update_var(&info->var, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | /* maximize virtual vertical length */ |
| 2268 | lpitch = info->var.xres_virtual*((info->var.bits_per_pixel + 7) >> 3); |
| 2269 | info->var.yres_virtual = info->fix.smem_len/lpitch; |
| 2270 | |
| 2271 | if (info->var.yres_virtual < info->var.yres) |
| 2272 | goto failed; |
| 2273 | |
| 2274 | #if defined(CONFIG_FB_SAVAGE_ACCEL) |
| 2275 | /* |
| 2276 | * The clipping coordinates are masked with 0xFFF, so limit our |
| 2277 | * virtual resolutions to these sizes. |
| 2278 | */ |
| 2279 | if (info->var.yres_virtual > 0x1000) |
| 2280 | info->var.yres_virtual = 0x1000; |
| 2281 | |
| 2282 | if (info->var.xres_virtual > 0x1000) |
| 2283 | info->var.xres_virtual = 0x1000; |
| 2284 | #endif |
| 2285 | savagefb_check_var(&info->var, info); |
| 2286 | savagefb_set_fix(info); |
| 2287 | |
| 2288 | /* |
| 2289 | * Calculate the hsync and vsync frequencies. Note that |
| 2290 | * we split the 1e12 constant up so that we can preserve |
| 2291 | * the precision and fit the results into 32-bit registers. |
| 2292 | * (1953125000 * 512 = 1e12) |
| 2293 | */ |
| 2294 | h_sync = 1953125000 / info->var.pixclock; |
| 2295 | h_sync = h_sync * 512 / (info->var.xres + info->var.left_margin + |
| 2296 | info->var.right_margin + |
| 2297 | info->var.hsync_len); |
| 2298 | v_sync = h_sync / (info->var.yres + info->var.upper_margin + |
| 2299 | info->var.lower_margin + info->var.vsync_len); |
| 2300 | |
| 2301 | printk(KERN_INFO "savagefb v" SAVAGEFB_VERSION ": " |
| 2302 | "%dkB VRAM, using %dx%d, %d.%03dkHz, %dHz\n", |
| 2303 | info->fix.smem_len >> 10, |
| 2304 | info->var.xres, info->var.yres, |
| 2305 | h_sync / 1000, h_sync % 1000, v_sync); |
| 2306 | |
| 2307 | |
| 2308 | fb_destroy_modedb(info->monspecs.modedb); |
| 2309 | info->monspecs.modedb = NULL; |
| 2310 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2311 | err = register_framebuffer(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | if (err < 0) |
| 2313 | goto failed; |
| 2314 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2315 | printk(KERN_INFO "fb: S3 %s frame buffer device\n", |
| 2316 | info->fix.id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | |
| 2318 | /* |
| 2319 | * Our driver data |
| 2320 | */ |
| 2321 | pci_set_drvdata(dev, info); |
| 2322 | |
| 2323 | return 0; |
| 2324 | |
| 2325 | failed: |
| 2326 | #ifdef CONFIG_FB_SAVAGE_I2C |
| 2327 | savagefb_delete_i2c_busses(info); |
| 2328 | #endif |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2329 | fb_alloc_cmap(&info->cmap, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | savage_unmap_video(info); |
| 2331 | failed_video: |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2332 | savage_unmap_mmio(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | failed_mmio: |
| 2334 | kfree(info->pixmap.addr); |
| 2335 | failed_init: |
| 2336 | pci_release_regions(dev); |
| 2337 | failed_enable: |
| 2338 | framebuffer_release(info); |
| 2339 | |
| 2340 | return err; |
| 2341 | } |
| 2342 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2343 | static void __devexit savagefb_remove(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 2345 | struct fb_info *info = pci_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | |
| 2347 | DBG("savagefb_remove"); |
| 2348 | |
| 2349 | if (info) { |
| 2350 | /* |
| 2351 | * If unregister_framebuffer fails, then |
| 2352 | * we will be leaving hooks that could cause |
| 2353 | * oopsen laying around. |
| 2354 | */ |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2355 | if (unregister_framebuffer(info)) |
| 2356 | printk(KERN_WARNING "savagefb: danger danger! " |
| 2357 | "Oopsen imminent!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | |
| 2359 | #ifdef CONFIG_FB_SAVAGE_I2C |
| 2360 | savagefb_delete_i2c_busses(info); |
| 2361 | #endif |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2362 | fb_alloc_cmap(&info->cmap, 0, 0); |
| 2363 | savage_unmap_video(info); |
| 2364 | savage_unmap_mmio(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | kfree(info->pixmap.addr); |
| 2366 | pci_release_regions(dev); |
| 2367 | framebuffer_release(info); |
| 2368 | |
| 2369 | /* |
| 2370 | * Ensure that the driver data is no longer |
| 2371 | * valid. |
| 2372 | */ |
| 2373 | pci_set_drvdata(dev, NULL); |
| 2374 | } |
| 2375 | } |
| 2376 | |
David Brownell | c78a7c2 | 2006-08-14 23:11:06 -0700 | [diff] [blame] | 2377 | static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 2379 | struct fb_info *info = pci_get_drvdata(dev); |
| 2380 | struct savagefb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | |
| 2382 | DBG("savagefb_suspend"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
David Brownell | c78a7c2 | 2006-08-14 23:11:06 -0700 | [diff] [blame] | 2384 | if (mesg.event == PM_EVENT_PRETHAW) |
| 2385 | mesg.event = PM_EVENT_FREEZE; |
| 2386 | par->pm_state = mesg.event; |
| 2387 | dev->dev.power.power_state = mesg; |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2388 | |
| 2389 | /* |
| 2390 | * For PM_EVENT_FREEZE, do not power down so the console |
| 2391 | * can remain active. |
| 2392 | */ |
David Brownell | c78a7c2 | 2006-08-14 23:11:06 -0700 | [diff] [blame] | 2393 | if (mesg.event == PM_EVENT_FREEZE) |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2394 | return 0; |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2395 | |
| 2396 | acquire_console_sem(); |
| 2397 | fb_set_suspend(info, 1); |
| 2398 | |
| 2399 | if (info->fbops->fb_sync) |
| 2400 | info->fbops->fb_sync(info); |
| 2401 | |
| 2402 | savagefb_blank(FB_BLANK_POWERDOWN, info); |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 2403 | savage_set_default_par(par, &par->save); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2404 | savage_disable_mmio(par); |
| 2405 | pci_save_state(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | pci_disable_device(dev); |
David Brownell | c78a7c2 | 2006-08-14 23:11:06 -0700 | [diff] [blame] | 2407 | pci_set_power_state(dev, pci_choose_state(dev, mesg)); |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2408 | release_console_sem(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | |
| 2410 | return 0; |
| 2411 | } |
| 2412 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2413 | static int savagefb_resume(struct pci_dev* dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | { |
Antonino A. Daplas | b8901b0 | 2006-01-09 20:53:02 -0800 | [diff] [blame] | 2415 | struct fb_info *info = pci_get_drvdata(dev); |
| 2416 | struct savagefb_par *par = info->par; |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2417 | int cur_state = par->pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | |
| 2419 | DBG("savage_resume"); |
| 2420 | |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2421 | par->pm_state = PM_EVENT_ON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2423 | /* |
| 2424 | * The adapter was not powered down coming back from a |
| 2425 | * PM_EVENT_FREEZE. |
| 2426 | */ |
| 2427 | if (cur_state == PM_EVENT_FREEZE) { |
| 2428 | pci_set_power_state(dev, PCI_D0); |
| 2429 | return 0; |
| 2430 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | |
| 2432 | acquire_console_sem(); |
| 2433 | |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2434 | pci_set_power_state(dev, PCI_D0); |
| 2435 | pci_restore_state(dev); |
| 2436 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2437 | if (pci_enable_device(dev)) |
Antonino A. Daplas | 1377671 | 2005-09-09 13:04:35 -0700 | [diff] [blame] | 2438 | DBG("err"); |
| 2439 | |
| 2440 | pci_set_master(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | savage_enable_mmio(par); |
| 2442 | savage_init_hw(par); |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 2443 | savagefb_set_par(info); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2444 | fb_set_suspend(info, 0); |
Antonino A. Daplas | f8020dc | 2006-06-26 00:26:24 -0700 | [diff] [blame] | 2445 | savagefb_blank(FB_BLANK_UNBLANK, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | release_console_sem(); |
| 2447 | |
| 2448 | return 0; |
| 2449 | } |
| 2450 | |
| 2451 | |
| 2452 | static struct pci_device_id savagefb_devices[] __devinitdata = { |
| 2453 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX128, |
| 2454 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2455 | |
| 2456 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX64, |
| 2457 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2458 | |
| 2459 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX64C, |
| 2460 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2461 | |
| 2462 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX128SDR, |
| 2463 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2464 | |
| 2465 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX128DDR, |
| 2466 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2467 | |
| 2468 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX64SDR, |
| 2469 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2470 | |
| 2471 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IX64DDR, |
| 2472 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2473 | |
| 2474 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IXCSDR, |
| 2475 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2476 | |
| 2477 | {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_IXCDDR, |
| 2478 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SUPERSAVAGE}, |
| 2479 | |
| 2480 | {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE4, |
| 2481 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE4}, |
| 2482 | |
| 2483 | {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE3D, |
| 2484 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE3D}, |
| 2485 | |
| 2486 | {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE3D_MV, |
| 2487 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE3D_MV}, |
| 2488 | |
| 2489 | {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE2000, |
| 2490 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE2000}, |
| 2491 | |
| 2492 | {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_MX_MV, |
| 2493 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_MX_MV}, |
| 2494 | |
| 2495 | {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_MX, |
| 2496 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_MX}, |
| 2497 | |
| 2498 | {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_IX_MV, |
| 2499 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_IX_MV}, |
| 2500 | |
| 2501 | {PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE_IX, |
| 2502 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_SAVAGE_IX}, |
| 2503 | |
| 2504 | {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_PM, |
| 2505 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_PM}, |
| 2506 | |
| 2507 | {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_KM, |
| 2508 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_KM}, |
| 2509 | |
| 2510 | {PCI_VENDOR_ID_S3, PCI_CHIP_S3TWISTER_P, |
| 2511 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_S3TWISTER_P}, |
| 2512 | |
| 2513 | {PCI_VENDOR_ID_S3, PCI_CHIP_S3TWISTER_K, |
| 2514 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_S3TWISTER_K}, |
| 2515 | |
| 2516 | {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_DDR, |
| 2517 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_DDR}, |
| 2518 | |
| 2519 | {PCI_VENDOR_ID_S3, PCI_CHIP_PROSAVAGE_DDRK, |
| 2520 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, FB_ACCEL_PROSAVAGE_DDRK}, |
| 2521 | |
| 2522 | {0, 0, 0, 0, 0, 0, 0} |
| 2523 | }; |
| 2524 | |
| 2525 | MODULE_DEVICE_TABLE(pci, savagefb_devices); |
| 2526 | |
| 2527 | static struct pci_driver savagefb_driver = { |
| 2528 | .name = "savagefb", |
| 2529 | .id_table = savagefb_devices, |
| 2530 | .probe = savagefb_probe, |
| 2531 | .suspend = savagefb_suspend, |
| 2532 | .resume = savagefb_resume, |
| 2533 | .remove = __devexit_p(savagefb_remove) |
| 2534 | }; |
| 2535 | |
| 2536 | /* **************************** exit-time only **************************** */ |
| 2537 | |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2538 | static void __exit savage_done(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | { |
| 2540 | DBG("savage_done"); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2541 | pci_unregister_driver(&savagefb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | |
| 2545 | /* ************************* init in-kernel code ************************** */ |
| 2546 | |
| 2547 | static int __init savagefb_setup(char *options) |
| 2548 | { |
| 2549 | #ifndef MODULE |
| 2550 | char *this_opt; |
| 2551 | |
| 2552 | if (!options || !*options) |
| 2553 | return 0; |
| 2554 | |
| 2555 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 2556 | mode_option = this_opt; |
| 2557 | } |
| 2558 | #endif /* !MODULE */ |
| 2559 | return 0; |
| 2560 | } |
| 2561 | |
| 2562 | static int __init savagefb_init(void) |
| 2563 | { |
| 2564 | char *option; |
| 2565 | |
| 2566 | DBG("savagefb_init"); |
| 2567 | |
| 2568 | if (fb_get_options("savagefb", &option)) |
| 2569 | return -ENODEV; |
| 2570 | |
| 2571 | savagefb_setup(option); |
Antonino A. Daplas | 026fbe1 | 2006-06-26 00:26:36 -0700 | [diff] [blame] | 2572 | return pci_register_driver(&savagefb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | |
| 2574 | } |
| 2575 | |
| 2576 | module_init(savagefb_init); |
| 2577 | module_exit(savage_done); |
Antonino A. Daplas | c52890c | 2005-09-09 13:09:59 -0700 | [diff] [blame] | 2578 | |
| 2579 | module_param(mode_option, charp, 0); |
| 2580 | MODULE_PARM_DESC(mode_option, "Specify initial video mode"); |