Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame^] | 1 | /* $XConsortium: nv_driver.c /main/3 1996/10/28 05:13:37 kaleb $ */ |
| 2 | /* |
| 3 | * Copyright 1996-1997 David J. McKay |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in |
| 13 | * all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * DAVID J. MCKAY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF |
| 20 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | * SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * GPL licensing note -- nVidia is allowing a liberal interpretation of |
| 26 | * the documentation restriction above, to merely say that this nVidia's |
| 27 | * copyright and disclaimer should be included with all code derived |
| 28 | * from this source. -- Jeff Garzik <jgarzik@pobox.com>, 01/Nov/99 |
| 29 | */ |
| 30 | |
| 31 | /* Hacked together from mga driver and 3.3.4 NVIDIA driver by Jarno Paananen |
| 32 | <jpaana@s2.org> */ |
| 33 | |
| 34 | /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_setup.c,v 1.18 2002/08/0 |
| 35 | 5 20:47:06 mvojkovi Exp $ */ |
| 36 | |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/pci.h> |
| 39 | #include <linux/pci_ids.h> |
| 40 | #include "nv_type.h" |
| 41 | #include "rivafb.h" |
| 42 | #include "nvreg.h" |
| 43 | |
| 44 | |
| 45 | #ifndef CONFIG_PCI /* sanity check */ |
| 46 | #error This driver requires PCI support. |
| 47 | #endif |
| 48 | |
| 49 | #define PFX "rivafb: " |
| 50 | |
| 51 | static inline unsigned char MISCin(struct riva_par *par) |
| 52 | { |
| 53 | return (VGA_RD08(par->riva.PVIO, 0x3cc)); |
| 54 | } |
| 55 | |
| 56 | static Bool |
| 57 | riva_is_connected(struct riva_par *par, Bool second) |
| 58 | { |
| 59 | volatile U032 __iomem *PRAMDAC = par->riva.PRAMDAC0; |
| 60 | U032 reg52C, reg608; |
| 61 | Bool present; |
| 62 | |
| 63 | if(second) PRAMDAC += 0x800; |
| 64 | |
| 65 | reg52C = NV_RD32(PRAMDAC, 0x052C); |
| 66 | reg608 = NV_RD32(PRAMDAC, 0x0608); |
| 67 | |
| 68 | NV_WR32(PRAMDAC, 0x0608, reg608 & ~0x00010000); |
| 69 | |
| 70 | NV_WR32(PRAMDAC, 0x052C, reg52C & 0x0000FEEE); |
| 71 | mdelay(1); |
| 72 | NV_WR32(PRAMDAC, 0x052C, NV_RD32(PRAMDAC, 0x052C) | 1); |
| 73 | |
| 74 | NV_WR32(par->riva.PRAMDAC0, 0x0610, 0x94050140); |
| 75 | NV_WR32(par->riva.PRAMDAC0, 0x0608, 0x00001000); |
| 76 | |
| 77 | mdelay(1); |
| 78 | |
| 79 | present = (NV_RD32(PRAMDAC, 0x0608) & (1 << 28)) ? TRUE : FALSE; |
| 80 | |
| 81 | NV_WR32(par->riva.PRAMDAC0, 0x0608, |
| 82 | NV_RD32(par->riva.PRAMDAC0, 0x0608) & 0x0000EFFF); |
| 83 | |
| 84 | NV_WR32(PRAMDAC, 0x052C, reg52C); |
| 85 | NV_WR32(PRAMDAC, 0x0608, reg608); |
| 86 | |
| 87 | return present; |
| 88 | } |
| 89 | |
| 90 | static void |
| 91 | riva_override_CRTC(struct riva_par *par) |
| 92 | { |
| 93 | printk(KERN_INFO PFX |
| 94 | "Detected CRTC controller %i being used\n", |
| 95 | par->SecondCRTC ? 1 : 0); |
| 96 | |
| 97 | if(par->forceCRTC != -1) { |
| 98 | printk(KERN_INFO PFX |
| 99 | "Forcing usage of CRTC %i\n", par->forceCRTC); |
| 100 | par->SecondCRTC = par->forceCRTC; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static void |
| 105 | riva_is_second(struct riva_par *par) |
| 106 | { |
| 107 | if (par->FlatPanel == 1) { |
| 108 | switch(par->Chipset & 0xffff) { |
| 109 | case 0x0174: |
| 110 | case 0x0175: |
| 111 | case 0x0176: |
| 112 | case 0x0177: |
| 113 | case 0x0179: |
| 114 | case 0x017C: |
| 115 | case 0x017D: |
| 116 | case 0x0186: |
| 117 | case 0x0187: |
| 118 | /* this might not be a good default for the chips below */ |
| 119 | case 0x0286: |
| 120 | case 0x028C: |
| 121 | case 0x0316: |
| 122 | case 0x0317: |
| 123 | case 0x031A: |
| 124 | case 0x031B: |
| 125 | case 0x031C: |
| 126 | case 0x031D: |
| 127 | case 0x031E: |
| 128 | case 0x031F: |
| 129 | case 0x0324: |
| 130 | case 0x0325: |
| 131 | case 0x0328: |
| 132 | case 0x0329: |
| 133 | case 0x032C: |
| 134 | case 0x032D: |
| 135 | par->SecondCRTC = TRUE; |
| 136 | break; |
| 137 | default: |
| 138 | par->SecondCRTC = FALSE; |
| 139 | break; |
| 140 | } |
| 141 | } else { |
| 142 | if(riva_is_connected(par, 0)) { |
| 143 | |
| 144 | if (NV_RD32(par->riva.PRAMDAC0, 0x0000052C) & 0x100) |
| 145 | par->SecondCRTC = TRUE; |
| 146 | else |
| 147 | par->SecondCRTC = FALSE; |
| 148 | } else |
| 149 | if (riva_is_connected(par, 1)) { |
| 150 | if(NV_RD32(par->riva.PRAMDAC0, 0x0000252C) & 0x100) |
| 151 | par->SecondCRTC = TRUE; |
| 152 | else |
| 153 | par->SecondCRTC = FALSE; |
| 154 | } else /* default */ |
| 155 | par->SecondCRTC = FALSE; |
| 156 | } |
| 157 | riva_override_CRTC(par); |
| 158 | } |
| 159 | |
| 160 | unsigned long riva_get_memlen(struct riva_par *par) |
| 161 | { |
| 162 | RIVA_HW_INST *chip = &par->riva; |
| 163 | unsigned long memlen = 0; |
| 164 | unsigned int chipset = par->Chipset; |
| 165 | struct pci_dev* dev; |
| 166 | int amt; |
| 167 | |
| 168 | switch (chip->Architecture) { |
| 169 | case NV_ARCH_03: |
| 170 | if (NV_RD32(chip->PFB, 0x00000000) & 0x00000020) { |
| 171 | if (((NV_RD32(chip->PMC, 0x00000000) & 0xF0) == 0x20) |
| 172 | && ((NV_RD32(chip->PMC, 0x00000000)&0x0F)>=0x02)) { |
| 173 | /* |
| 174 | * SDRAM 128 ZX. |
| 175 | */ |
| 176 | switch (NV_RD32(chip->PFB,0x00000000) & 0x03) { |
| 177 | case 2: |
| 178 | memlen = 1024 * 4; |
| 179 | break; |
| 180 | case 1: |
| 181 | memlen = 1024 * 2; |
| 182 | break; |
| 183 | default: |
| 184 | memlen = 1024 * 8; |
| 185 | break; |
| 186 | } |
| 187 | } else { |
| 188 | memlen = 1024 * 8; |
| 189 | } |
| 190 | } else { |
| 191 | /* |
| 192 | * SGRAM 128. |
| 193 | */ |
| 194 | switch (NV_RD32(chip->PFB, 0x00000000) & 0x00000003) { |
| 195 | case 0: |
| 196 | memlen = 1024 * 8; |
| 197 | break; |
| 198 | case 2: |
| 199 | memlen = 1024 * 4; |
| 200 | break; |
| 201 | default: |
| 202 | memlen = 1024 * 2; |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | break; |
| 207 | case NV_ARCH_04: |
| 208 | if (NV_RD32(chip->PFB, 0x00000000) & 0x00000100) { |
| 209 | memlen = ((NV_RD32(chip->PFB, 0x00000000)>>12)&0x0F) * |
| 210 | 1024 * 2 + 1024 * 2; |
| 211 | } else { |
| 212 | switch (NV_RD32(chip->PFB, 0x00000000) & 0x00000003) { |
| 213 | case 0: |
| 214 | memlen = 1024 * 32; |
| 215 | break; |
| 216 | case 1: |
| 217 | memlen = 1024 * 4; |
| 218 | break; |
| 219 | case 2: |
| 220 | memlen = 1024 * 8; |
| 221 | break; |
| 222 | case 3: |
| 223 | default: |
| 224 | memlen = 1024 * 16; |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | break; |
| 229 | case NV_ARCH_10: |
| 230 | case NV_ARCH_20: |
| 231 | case NV_ARCH_30: |
| 232 | if(chipset == NV_CHIP_IGEFORCE2) { |
| 233 | |
| 234 | dev = pci_find_slot(0, 1); |
| 235 | pci_read_config_dword(dev, 0x7C, &amt); |
| 236 | memlen = (((amt >> 6) & 31) + 1) * 1024; |
| 237 | } else if (chipset == NV_CHIP_0x01F0) { |
| 238 | dev = pci_find_slot(0, 1); |
| 239 | pci_read_config_dword(dev, 0x84, &amt); |
| 240 | memlen = (((amt >> 4) & 127) + 1) * 1024; |
| 241 | } else { |
| 242 | switch ((NV_RD32(chip->PFB, 0x0000020C) >> 20) & |
| 243 | 0x000000FF){ |
| 244 | case 0x02: |
| 245 | memlen = 1024 * 2; |
| 246 | break; |
| 247 | case 0x04: |
| 248 | memlen = 1024 * 4; |
| 249 | break; |
| 250 | case 0x08: |
| 251 | memlen = 1024 * 8; |
| 252 | break; |
| 253 | case 0x10: |
| 254 | memlen = 1024 * 16; |
| 255 | break; |
| 256 | case 0x20: |
| 257 | memlen = 1024 * 32; |
| 258 | break; |
| 259 | case 0x40: |
| 260 | memlen = 1024 * 64; |
| 261 | break; |
| 262 | case 0x80: |
| 263 | memlen = 1024 * 128; |
| 264 | break; |
| 265 | default: |
| 266 | memlen = 1024 * 16; |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | break; |
| 271 | } |
| 272 | return memlen; |
| 273 | } |
| 274 | |
| 275 | unsigned long riva_get_maxdclk(struct riva_par *par) |
| 276 | { |
| 277 | RIVA_HW_INST *chip = &par->riva; |
| 278 | unsigned long dclk = 0; |
| 279 | |
| 280 | switch (chip->Architecture) { |
| 281 | case NV_ARCH_03: |
| 282 | if (NV_RD32(chip->PFB, 0x00000000) & 0x00000020) { |
| 283 | if (((NV_RD32(chip->PMC, 0x00000000) & 0xF0) == 0x20) |
| 284 | && ((NV_RD32(chip->PMC,0x00000000)&0x0F) >= 0x02)) { |
| 285 | /* |
| 286 | * SDRAM 128 ZX. |
| 287 | */ |
| 288 | dclk = 800000; |
| 289 | } else { |
| 290 | dclk = 1000000; |
| 291 | } |
| 292 | } else { |
| 293 | /* |
| 294 | * SGRAM 128. |
| 295 | */ |
| 296 | dclk = 1000000; |
| 297 | } |
| 298 | break; |
| 299 | case NV_ARCH_04: |
| 300 | case NV_ARCH_10: |
| 301 | case NV_ARCH_20: |
| 302 | case NV_ARCH_30: |
| 303 | switch ((NV_RD32(chip->PFB, 0x00000000) >> 3) & 0x00000003) { |
| 304 | case 3: |
| 305 | dclk = 800000; |
| 306 | break; |
| 307 | default: |
| 308 | dclk = 1000000; |
| 309 | break; |
| 310 | } |
| 311 | break; |
| 312 | } |
| 313 | return dclk; |
| 314 | } |
| 315 | |
| 316 | void |
| 317 | riva_common_setup(struct riva_par *par) |
| 318 | { |
| 319 | par->riva.EnableIRQ = 0; |
| 320 | par->riva.PRAMDAC0 = |
| 321 | (volatile U032 __iomem *)(par->ctrl_base + 0x00680000); |
| 322 | par->riva.PFB = |
| 323 | (volatile U032 __iomem *)(par->ctrl_base + 0x00100000); |
| 324 | par->riva.PFIFO = |
| 325 | (volatile U032 __iomem *)(par->ctrl_base + 0x00002000); |
| 326 | par->riva.PGRAPH = |
| 327 | (volatile U032 __iomem *)(par->ctrl_base + 0x00400000); |
| 328 | par->riva.PEXTDEV = |
| 329 | (volatile U032 __iomem *)(par->ctrl_base + 0x00101000); |
| 330 | par->riva.PTIMER = |
| 331 | (volatile U032 __iomem *)(par->ctrl_base + 0x00009000); |
| 332 | par->riva.PMC = |
| 333 | (volatile U032 __iomem *)(par->ctrl_base + 0x00000000); |
| 334 | par->riva.FIFO = |
| 335 | (volatile U032 __iomem *)(par->ctrl_base + 0x00800000); |
| 336 | par->riva.PCIO0 = par->ctrl_base + 0x00601000; |
| 337 | par->riva.PDIO0 = par->ctrl_base + 0x00681000; |
| 338 | par->riva.PVIO = par->ctrl_base + 0x000C0000; |
| 339 | |
| 340 | par->riva.IO = (MISCin(par) & 0x01) ? 0x3D0 : 0x3B0; |
| 341 | |
| 342 | if (par->FlatPanel == -1) { |
| 343 | switch (par->Chipset & 0xffff) { |
| 344 | case 0x0112: /* known laptop chips */ |
| 345 | case 0x0174: |
| 346 | case 0x0175: |
| 347 | case 0x0176: |
| 348 | case 0x0177: |
| 349 | case 0x0179: |
| 350 | case 0x017C: |
| 351 | case 0x017D: |
| 352 | case 0x0186: |
| 353 | case 0x0187: |
| 354 | case 0x0286: |
| 355 | case 0x028C: |
| 356 | case 0x0316: |
| 357 | case 0x0317: |
| 358 | case 0x031A: |
| 359 | case 0x031B: |
| 360 | case 0x031C: |
| 361 | case 0x031D: |
| 362 | case 0x031E: |
| 363 | case 0x031F: |
| 364 | case 0x0324: |
| 365 | case 0x0325: |
| 366 | case 0x0328: |
| 367 | case 0x0329: |
| 368 | case 0x032C: |
| 369 | case 0x032D: |
| 370 | printk(KERN_INFO PFX |
| 371 | "On a laptop. Assuming Digital Flat Panel\n"); |
| 372 | par->FlatPanel = 1; |
| 373 | break; |
| 374 | default: |
| 375 | break; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | switch (par->Chipset & 0x0ff0) { |
| 380 | case 0x0110: |
| 381 | if (par->Chipset == NV_CHIP_GEFORCE2_GO) |
| 382 | par->SecondCRTC = TRUE; |
| 383 | #if defined(__powerpc__) |
| 384 | if (par->FlatPanel == 1) |
| 385 | par->SecondCRTC = TRUE; |
| 386 | #endif |
| 387 | riva_override_CRTC(par); |
| 388 | break; |
| 389 | case 0x0170: |
| 390 | case 0x0180: |
| 391 | case 0x01F0: |
| 392 | case 0x0250: |
| 393 | case 0x0280: |
| 394 | case 0x0300: |
| 395 | case 0x0310: |
| 396 | case 0x0320: |
| 397 | case 0x0330: |
| 398 | case 0x0340: |
| 399 | riva_is_second(par); |
| 400 | break; |
| 401 | default: |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | if (par->SecondCRTC) { |
| 406 | par->riva.PCIO = par->riva.PCIO0 + 0x2000; |
| 407 | par->riva.PCRTC = par->riva.PCRTC0 + 0x800; |
| 408 | par->riva.PRAMDAC = par->riva.PRAMDAC0 + 0x800; |
| 409 | par->riva.PDIO = par->riva.PDIO0 + 0x2000; |
| 410 | } else { |
| 411 | par->riva.PCIO = par->riva.PCIO0; |
| 412 | par->riva.PCRTC = par->riva.PCRTC0; |
| 413 | par->riva.PRAMDAC = par->riva.PRAMDAC0; |
| 414 | par->riva.PDIO = par->riva.PDIO0; |
| 415 | } |
| 416 | |
| 417 | if (par->FlatPanel == -1) { |
| 418 | /* Fix me, need x86 DDC code */ |
| 419 | par->FlatPanel = 0; |
| 420 | } |
| 421 | par->riva.flatPanel = (par->FlatPanel > 0) ? TRUE : FALSE; |
| 422 | |
| 423 | RivaGetConfig(&par->riva, par->Chipset); |
| 424 | } |
| 425 | |