1 /* Authors: 2 Mark Watson 12/1999, 3 Apsed, 4 Rudolf Cornelissen 10/2002-1/2004 5 */ 6 7 #define MODULE_BIT 0x00008000 8 9 #include "mga_std.h" 10 11 static status_t test_ram(); 12 static status_t mil_general_powerup (void); 13 static status_t g100_general_powerup (void); 14 static status_t g200_general_powerup (void); 15 static status_t g400_general_powerup (void); 16 static status_t g450_general_powerup (void); 17 static status_t gx00_general_bios_to_powergraphics(void); 18 19 static void mga_dump_configuration_space (void) 20 { 21 #define DUMP_CFG(reg, type) if (si->ps.card_type >= type) do { \ 22 uint32 value = CFGR(reg); \ 23 MSG(("configuration_space 0x%02x %20s 0x%08x\n", \ 24 MGACFG_##reg, #reg, value)); \ 25 } while (0) 26 DUMP_CFG (DEVID, 0); 27 DUMP_CFG (DEVCTRL, 0); 28 DUMP_CFG (CLASS, 0); 29 DUMP_CFG (HEADER, 0); 30 DUMP_CFG (MGABASE2, 0); 31 DUMP_CFG (MGABASE1, 0); 32 DUMP_CFG (MGABASE3, MYST); 33 DUMP_CFG (SUBSYSIDR, MYST); 34 DUMP_CFG (ROMBASE, 0); 35 DUMP_CFG (CAP_PTR, MIL2); 36 DUMP_CFG (INTCTRL, 0); 37 DUMP_CFG (OPTION, 0); 38 DUMP_CFG (MGA_INDEX, 0); 39 DUMP_CFG (MGA_DATA, 0); 40 DUMP_CFG (SUBSYSIDW, MYST); 41 DUMP_CFG (OPTION2, G100); 42 DUMP_CFG (OPTION3, G400); 43 DUMP_CFG (OPTION4, G400); 44 DUMP_CFG (PM_IDENT, G100); 45 DUMP_CFG (PM_CSR, G100); 46 DUMP_CFG (AGP_IDENT, MIL2); 47 DUMP_CFG (AGP_STS, MIL2); 48 DUMP_CFG (AGP_CMD, MIL2); 49 #undef DUMP_CFG 50 } 51 52 status_t gx00_general_powerup() 53 { 54 status_t status; 55 uint32 card_class; 56 57 LOG(1,("POWERUP: Matrox (open)BeOS Accelerant 0.16-1 running.\n")); 58 59 /* detect card type and power it up */ 60 switch(CFGR(DEVID)) 61 { 62 case 0x051a102b: //MGA-1064 Mystic PCI 63 LOG(8,("POWERUP: Unimplemented Matrox device %08x\n",CFGR(DEVID))); 64 return B_ERROR; 65 case 0x0519102b: //MGA-2064 Millenium PCI 66 si->ps.card_type = MIL1; 67 LOG(4,("POWERUP: Detected MGA-2064 Millennium 1\n")); 68 status = mil_general_powerup(); 69 break; 70 case 0x051b102b:case 0x051f102b: //MGA-2164 Millenium 2 PCI/AGP 71 si->ps.card_type = MIL2; 72 LOG(4,("POWERUP: Detected MGA-2164 Millennium 2\n")); 73 status = mil_general_powerup(); 74 break; 75 case 0x1000102b:case 0x1001102b: //G100 76 si->ps.card_type = G100; 77 LOG(4,("POWERUP: Detected G100\n")); 78 status = g100_general_powerup(); 79 break; 80 case 0x0520102b:case 0x0521102b: //G200 81 si->ps.card_type = G200; 82 LOG(4,("POWERUP: Detected G200\n")); 83 status = g200_general_powerup(); 84 break; 85 case 0x0525102b: //G400, G400MAX or G450 86 LOG(4,("POWERUP: Detected G4")); 87 /* get classinfo to distinguish different types */ 88 card_class = CFGR(CLASS) & 0xff; 89 if (card_class & 0x80) 90 { 91 /* G450 */ 92 si->ps.card_type = G450; 93 LOG(4, ("50 revision %x\n", card_class & 0x7f)); 94 status = g450_general_powerup(); 95 } 96 else 97 { 98 /* standard G400, G400MAX */ 99 /* the only difference is the max RAMDAC speed, accounted for via pins. */ 100 si->ps.card_type = G400; 101 LOG(4, ("00 revision %x\n", card_class & 0x7f)); 102 status = g400_general_powerup(); 103 } 104 break; 105 case 0x2527102b://G550 patch from Jean-Michel Batto 106 si->ps.card_type = G450; 107 LOG(4,("POWERUP: Detected G550\n")); 108 status = g450_general_powerup(); 109 break; 110 default: 111 LOG(8,("POWERUP: Failed to detect valid card 0x%08x\n",CFGR(DEVID))); 112 return B_ERROR; 113 } 114 115 /* override memory detection if requested by user */ 116 if (si->settings.memory != 0) 117 si->ps.memory_size = si->settings.memory; 118 119 return status; 120 } 121 122 static status_t test_ram() 123 { 124 uint32 value, offset; 125 status_t result = B_OK; 126 127 /* make sure we don't corrupt the hardware cursor by using fbc.frame_buffer. */ 128 if (si->fbc.frame_buffer == NULL) 129 { 130 LOG(8,("INIT: test_ram detected NULL pointer.\n")); 131 return B_ERROR; 132 } 133 134 for (offset = 0, value = 0x55aa55aa; offset < 256; offset++) 135 { 136 /* write testpattern to cardRAM */ 137 ((uint32 *)si->fbc.frame_buffer)[offset] = value; 138 /* toggle testpattern */ 139 value = 0xffffffff - value; 140 } 141 142 for (offset = 0, value = 0x55aa55aa; offset < 256; offset++) 143 { 144 /* readback and verify testpattern from cardRAM */ 145 if (((uint32 *)si->fbc.frame_buffer)[offset] != value) result = B_ERROR; 146 /* toggle testpattern */ 147 value = 0xffffffff - value; 148 } 149 return result; 150 } 151 152 /* NOTE: 153 * This routine *has* to be done *after* SetDispplayMode has been executed, 154 * or test results will not be representative! 155 * (CAS latency is dependant on MGA setup on some (DRAM) boards) */ 156 status_t mga_set_cas_latency() 157 { 158 status_t result = B_ERROR; 159 uint8 latency = 0; 160 161 /* check current RAM access to see if we need to change anything */ 162 if (test_ram() == B_OK) 163 { 164 LOG(4,("INIT: RAM access OK.\n")); 165 return B_OK; 166 } 167 168 /* check if we read PINS at starttime so we have valid registersettings at our disposal */ 169 if (si->ps.pins_status != B_OK) 170 { 171 LOG(4,("INIT: RAM access errors; not fixable: PINS was not read from cardBIOS.\n")); 172 return B_ERROR; 173 } 174 175 /* OK. We might have a problem, try to fix it now.. */ 176 LOG(4,("INIT: RAM access errors; tuning CAS latency if prudent...\n")); 177 178 switch(si->ps.card_type) 179 { 180 case G100: 181 if (!si->ps.sdram) 182 { 183 LOG(4,("INIT: G100 SGRAM CAS tuning not permitted, aborting.\n")); 184 return B_OK; 185 } 186 /* SDRAM card */ 187 for (latency = 4; latency >= 2; latency-- ) 188 { 189 /* MCTLWTST is a write-only register! */ 190 ACCW(MCTLWTST, ((si->ps.mctlwtst_reg & 0xfffffffc) | (latency - 2))); 191 result = test_ram(); 192 if (result == B_OK) break; 193 } 194 break; 195 case G200: 196 /* fixme: implement this */ 197 LOG(4,("INIT: G200 RAM CAS tuning not implemented, aborting.\n")); 198 return B_OK; 199 break; 200 case G400: 201 case G400MAX: 202 /* fixme: implement this if needed */ 203 LOG(4,("INIT: G400/G400MAX RAM CAS tuning not implemented, aborting.\n")); 204 return B_OK; 205 break; 206 case G450: 207 case G550: 208 /* fixme: implement this if needed */ 209 LOG(4,("INIT: G450/G550 RAM CAS tuning not implemented, aborting.\n")); 210 return B_OK; 211 break; 212 default: 213 /* fixme: Millenium2 and others if needed */ 214 LOG(4,("INIT: RAM CAS tuning not implemented for this card, aborting.\n")); 215 return B_OK; 216 break; 217 } 218 if (result == B_OK) 219 LOG(4,("INIT: RAM access OK. CAS latency set to %d cycles.\n", latency)); 220 else 221 LOG(4,("INIT: RAM access not fixable. CAS latency set to %d cycles.\n", latency)); 222 223 return result; 224 } 225 226 static 227 status_t mil_general_powerup() 228 { 229 status_t result; 230 231 LOG(4, ("INIT: Millenium I/II powerup\n")); 232 if (si->settings.logmask & 0x80000000) mga_dump_configuration_space(); 233 234 /* initialize the shared_info PINS struct */ 235 result = parse_pins(); 236 if (result != B_OK) fake_pins(); 237 238 /* log the PINS struct settings */ 239 dump_pins(); 240 241 //remove this: 242 fake_pins(); 243 LOG(2, ("INIT: Using faked PINS for now:\n")); 244 dump_pins(); 245 //end remove this. 246 247 /* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */ 248 //restore this line: 249 // if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics(); 250 251 //set to powergraphics etc. 252 LOG(2, ("INIT: Skipping card coldstart!\n")); 253 mil2_dac_init(); 254 255 //ok: 256 /* disable overscan, select 0 IRE, select straight-through sync signals from CRTC */ 257 DXIW (GENCTRL, (DXIR (GENCTRL) & 0x0c)); 258 /* fixme: checkout if we need this sync inverting stuff: already done via CRTC!?! 259 | (vsync_pos? 0x00:0x02) 260 | (hsync_pos? 0x00:0x01)); */ 261 262 /* 8-bit DAC, enable DAC */ 263 DXIW(MISCCTRL, 0x0c); 264 // 265 266 VGAW_I(SEQ,1,0x00); 267 /*enable screen*/ 268 269 return B_OK; 270 } 271 272 static 273 status_t g100_general_powerup() 274 { 275 status_t result; 276 277 LOG(4, ("INIT: G100 powerup\n")); 278 if (si->settings.logmask & 0x80000000) mga_dump_configuration_space(); 279 280 /* initialize the shared_info PINS struct */ 281 result = parse_pins(); 282 if (result != B_OK) fake_pins(); 283 284 /* log the PINS struct settings */ 285 dump_pins(); 286 287 /* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */ 288 if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics(); 289 290 /*power up the PLLs,LUT,DAC*/ 291 LOG(2,("INIT: PLL/LUT/DAC powerup\n")); 292 /* turn off both displays and the hardcursor (also disables transfers) */ 293 gx00_crtc_dpms(false, false, false); 294 gx00_crtc_cursor_hide(); 295 /* G100 SGRAM and SDRAM use external pix and dac refs, do *not* activate internals! 296 * (this would create electrical shortcuts, 297 * resulting in extra chip heat and distortions visible on screen */ 298 /* set voltage reference - using DAC reference block partly */ 299 DXIW(VREFCTRL,0x03); 300 /* wait for 100ms for voltage reference to stabilize */ 301 delay(100000); 302 /* power up the SYSPLL */ 303 CFGW(OPTION,CFGR(OPTION)|0x20); 304 /* power up the PIXPLL */ 305 DXIW(PIXCLKCTRL,0x08); 306 307 /* disable pixelclock oscillations before switching on CLUT */ 308 DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) | 0x04)); 309 /* disable 15bit mode CLUT-overlay function */ 310 DXIW(GENCTRL, DXIR(GENCTRL & 0xfd)); 311 /* CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC */ 312 DXIW(MISCCTRL,0x1b); 313 snooze(250); 314 /* re-enable pixelclock oscillations */ 315 DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) & 0xfb)); 316 317 /* setup i2c bus */ 318 i2c_init(); 319 320 /*make sure card is in powergraphics mode*/ 321 VGAW_I(CRTCEXT,3,0x80); 322 323 /*set the system clocks to powergraphics speed*/ 324 LOG(2,("INIT: Setting system PLL to powergraphics speeds\n")); 325 g100_dac_set_sys_pll(); 326 327 /* 'official' RAM initialisation */ 328 LOG(2,("INIT: RAM init\n")); 329 /* disable plane write mask (needed for SDRAM): actual change needed to get it sent to RAM */ 330 ACCW(PLNWT,0x00000000); 331 ACCW(PLNWT,0xffffffff); 332 /* program memory control waitstates */ 333 ACCW(MCTLWTST,si->ps.mctlwtst_reg); 334 /* set memory configuration including: 335 * - no split framebuffer. 336 * - Mark says b14 (G200) should be done also though not defined for G100 in spec, 337 * - b3 v3_mem_type was included by Mark for memconfig setup: but looks like not defined */ 338 CFGW(OPTION,(CFGR(OPTION)&0xFFFF8FFF) | ((si->ps.v3_mem_type & 0x04) << 10)); 339 /* set memory buffer type: 340 * - Mark says: if((v3_mem_type & 0x03) == 0x03) then do not or-in bits in option2; 341 * but looks like v3_mem_type b1 is not defined, 342 * - Mark also says: place v3_mem_type b1 in option2 bit13 (if not 0x03) but b13 = reserved. */ 343 CFGW(OPTION2,(CFGR(OPTION2)&0xFFFFCFFF)|((si->ps.v3_mem_type & 0x01) << 12)); 344 /* set RAM read tap delay */ 345 CFGW(OPTION2,(CFGR(OPTION2)&0xFFFFFFF0) | ((si->ps.v3_mem_type & 0xf0) >> 4)); 346 /* wait 200uS minimum */ 347 snooze(250); 348 349 /* reset memory (MACCESS is a write only register!) */ 350 ACCW(MACCESS, 0x00000000); 351 /* select JEDEC reset method */ 352 ACCW(MACCESS, 0x00004000); 353 /* perform actual RAM reset */ 354 ACCW(MACCESS, 0x0000c000); 355 snooze(250); 356 /* start memory refresh */ 357 CFGW(OPTION,(CFGR(OPTION)&0xffe07fff) | (si->ps.option_reg & 0x001f8000)); 358 /* set memory control waitstate again AFTER the RAM reset */ 359 ACCW(MCTLWTST,si->ps.mctlwtst_reg); 360 /* end 'official' RAM initialisation. */ 361 362 /* Bus parameters: enable retries, use advanced read */ 363 CFGW(OPTION,(CFGR(OPTION)|(1<<22)|(0<<29))); 364 365 /*enable writing to crtc registers*/ 366 VGAW_I(CRTC,0x11,0); 367 368 /*turn on display one*/ 369 gx00_crtc_dpms(true, true, true); 370 371 return B_OK; 372 } 373 374 static 375 status_t g200_general_powerup() 376 { 377 status_t result; 378 379 LOG(4, ("INIT: G200 powerup\n")); 380 if (si->settings.logmask & 0x80000000) mga_dump_configuration_space(); 381 382 /* initialize the shared_info PINS struct */ 383 result = parse_pins(); 384 if (result != B_OK) fake_pins(); 385 386 /* log the PINS struct settings */ 387 dump_pins(); 388 389 /* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */ 390 if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics(); 391 392 /*power up the PLLs,LUT,DAC*/ 393 LOG(2,("INIT: PLL/LUT/DAC powerup\n")); 394 /* turn off both displays and the hardcursor (also disables transfers) */ 395 gx00_crtc_dpms(false, false, false); 396 gx00_crtc_cursor_hide(); 397 /* G200 SGRAM and SDRAM use external pix and dac refs, do *not* activate internals! 398 * (this would create electrical shortcuts, 399 * resulting in extra chip heat and distortions visible on screen */ 400 /* set voltage reference - using DAC reference block partly */ 401 DXIW(VREFCTRL,0x03); 402 /* wait for 100ms for voltage reference to stabilize */ 403 delay(100000); 404 /* power up the SYSPLL */ 405 CFGW(OPTION,CFGR(OPTION)|0x20); 406 /* power up the PIXPLL */ 407 DXIW(PIXCLKCTRL,0x08); 408 409 /* disable pixelclock oscillations before switching on CLUT */ 410 DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) | 0x04)); 411 /* disable 15bit mode CLUT-overlay function */ 412 DXIW(GENCTRL, DXIR(GENCTRL & 0xfd)); 413 /* CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC */ 414 DXIW(MISCCTRL,0x1b); 415 snooze(250); 416 /* re-enable pixelclock oscillations */ 417 DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) & 0xfb)); 418 419 /* setup i2c bus */ 420 i2c_init(); 421 422 /*make sure card is in powergraphics mode*/ 423 VGAW_I(CRTCEXT,3,0x80); 424 425 /*set the system clocks to powergraphics speed*/ 426 LOG(2,("INIT: Setting system PLL to powergraphics speeds\n")); 427 g200_dac_set_sys_pll(); 428 429 /* 'official' RAM initialisation */ 430 LOG(2,("INIT: RAM init\n")); 431 /* disable hardware plane write mask if SDRAM card */ 432 if (si->ps.sdram) CFGW(OPTION,(CFGR(OPTION) & 0xffffbfff)); 433 /* disable plane write mask (needed for SDRAM): actual change needed to get it sent to RAM */ 434 ACCW(PLNWT,0x00000000); 435 ACCW(PLNWT,0xffffffff); 436 /* program memory control waitstates */ 437 ACCW(MCTLWTST,si->ps.mctlwtst_reg); 438 /* set memory configuration including: 439 * - SDRAM / SGRAM special functions select. */ 440 CFGW(OPTION,(CFGR(OPTION)&0xFFFF83FF) | ((si->ps.v3_mem_type & 0x07) << 10)); 441 if (!si->ps.sdram) CFGW(OPTION,(CFGR(OPTION) | (0x01 << 14))); 442 /* set memory buffer type */ 443 CFGW(OPTION2,(CFGR(OPTION2)&0xFFFFCFFF)|((si->ps.v3_option2_reg & 0x03) << 12)); 444 /* set mode register opcode and streamer flow control */ 445 ACCW(MEMRDBK,(ACCR(MEMRDBK)&0x0000FFFF)|(si->ps.memrdbk_reg & 0xffff0000)); 446 /* set RAM read tap delays */ 447 ACCW(MEMRDBK,(ACCR(MEMRDBK)&0xFFFF0000)|(si->ps.memrdbk_reg & 0x0000ffff)); 448 /* wait 200uS minimum */ 449 snooze(250); 450 451 /* reset memory (MACCESS is a write only register!) */ 452 ACCW(MACCESS, 0x00000000); 453 /* perform actual RAM reset */ 454 ACCW(MACCESS, 0x00008000); 455 snooze(250); 456 /* start memory refresh */ 457 CFGW(OPTION,(CFGR(OPTION)&0xffe07fff) | (si->ps.option_reg & 0x001f8000)); 458 /* set memory control waitstate again AFTER the RAM reset */ 459 ACCW(MCTLWTST,si->ps.mctlwtst_reg); 460 /* end 'official' RAM initialisation. */ 461 462 /* Bus parameters: enable retries, use advanced read */ 463 CFGW(OPTION,(CFGR(OPTION)|(1<<22)|(0<<29))); 464 465 /*enable writing to crtc registers*/ 466 VGAW_I(CRTC,0x11,0); 467 468 /*turn on display one*/ 469 gx00_crtc_dpms(true, true, true); 470 471 return B_OK; 472 } 473 474 static 475 status_t g400_general_powerup() 476 { 477 status_t result; 478 479 LOG(4, ("INIT: G400/G400MAX powerup\n")); 480 if (si->settings.logmask & 0x80000000) mga_dump_configuration_space(); 481 482 /* initialize the shared_info PINS struct */ 483 result = parse_pins(); 484 if (result != B_OK) fake_pins(); 485 486 /* log the PINS struct settings */ 487 dump_pins(); 488 489 /* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */ 490 if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics(); 491 492 /* reset MAVEN so we know the sync polarity is at reset situation (Hpos, Vpos) */ 493 if (si->ps.secondary_tvout) 494 { 495 ACCW(RST, 0x00000002); 496 snooze(1000); 497 ACCW(RST, 0x00000000); 498 } 499 500 /*power up the PLLs,LUT,DAC*/ 501 LOG(4,("INIT: PLL/LUT/DAC powerup\n")); 502 /* turn off both displays and the hardcursor (also disables transfers) */ 503 gx00_crtc_dpms(false, false, false); 504 g400_crtc2_dpms(false, false, false); 505 gx00_crtc_cursor_hide(); 506 507 /* set voltage reference - not using DAC reference block */ 508 DXIW(VREFCTRL,0x00); 509 /* wait for 100ms for voltage reference to stabilize */ 510 delay(100000); 511 /* power up the SYSPLL */ 512 CFGW(OPTION,CFGR(OPTION)|0x20); 513 /* power up the PIXPLL */ 514 DXIW(PIXCLKCTRL,0x08); 515 516 /* disable pixelclock oscillations before switching on CLUT */ 517 DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) | 0x04)); 518 /* disable 15bit mode CLUT-overlay function */ 519 DXIW(GENCTRL, DXIR(GENCTRL & 0xfd)); 520 /* CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC */ 521 DXIW(MISCCTRL,0x9b); 522 snooze(250); 523 /* re-enable pixelclock oscillations */ 524 DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) & 0xfb)); 525 526 DXIW(MAFCDEL,0x02); /*makes CRTC2 stable! Matrox specify 8, but use 4 - grrrr!*/ 527 DXIW(PANELMODE,0x00); /*eclipse panellink*/ 528 529 /* setup i2c bus */ 530 i2c_init(); 531 532 /* make sure card is in powergraphics mode */ 533 VGAW_I(CRTCEXT,3,0x80); 534 535 /* set the system clocks to powergraphics speed */ 536 LOG(2,("INIT: Setting system PLL to powergraphics speeds\n")); 537 g400_dac_set_sys_pll(); 538 539 /* 'official' RAM initialisation */ 540 LOG(2,("INIT: RAM init\n")); 541 /* disable hardware plane write mask if SDRAM card */ 542 if (si->ps.sdram) CFGW(OPTION,(CFGR(OPTION) & 0xffffbfff)); 543 /* disable plane write mask (needed for SDRAM): actual change needed to get it sent to RAM */ 544 ACCW(PLNWT,0x00000000); 545 ACCW(PLNWT,0xffffffff); 546 /* program memory control waitstates */ 547 ACCW(MCTLWTST, si->ps.mctlwtst_reg); 548 /* set memory configuration including: 549 * - SDRAM / SGRAM special functions select. */ 550 CFGW(OPTION,(CFGR(OPTION)&0xFFFF83FF) | (si->ps.option_reg & 0x00001c00)); 551 if (!si->ps.sdram) CFGW(OPTION,(CFGR(OPTION) | (0x01 << 14))); 552 /* set mode register opcode and streamer flow control */ 553 ACCW(MEMRDBK,(ACCR(MEMRDBK)&0x0000FFFF)|(si->ps.memrdbk_reg & 0xffff0000)); 554 /* set RAM read tap delays */ 555 ACCW(MEMRDBK,(ACCR(MEMRDBK)&0xFFFF0000)|(si->ps.memrdbk_reg & 0x0000ffff)); 556 /* wait 200uS minimum */ 557 snooze(250); 558 559 /* reset memory (MACCESS is a write only register!) */ 560 ACCW(MACCESS, 0x00000000); 561 /* perform actual RAM reset */ 562 ACCW(MACCESS, 0x00008000); 563 snooze(250); 564 /* start memory refresh */ 565 CFGW(OPTION,(CFGR(OPTION)&0xffe07fff) | (si->ps.option_reg & 0x001f8000)); 566 /* set memory control waitstate again AFTER the RAM reset */ 567 ACCW(MCTLWTST,si->ps.mctlwtst_reg); 568 /* end 'official' RAM initialisation. */ 569 570 /* 'advance read' busparameter and 'memory priority' enable/disable setup */ 571 CFGW(OPTION, ((CFGR(OPTION) & 0xefbfffff) | (si->ps.option_reg & 0x10400000))); 572 573 /*enable writing to crtc registers*/ 574 VGAW_I(CRTC,0x11,0); 575 if (si->ps.secondary_head) 576 { 577 MAVW(LOCK,0x01); 578 CR2W(DATACTL,0x00000000); 579 } 580 581 /*turn on display one*/ 582 gx00_crtc_dpms(true, true, true); 583 584 return B_OK; 585 } 586 587 static 588 status_t g450_general_powerup() 589 { 590 status_t result; 591 uint32 pwr_cas[] = {0, 1, 5, 6, 7, 5, 2, 3}; 592 593 /* used for convenience: MACCESS is a write only register! */ 594 uint32 maccess = 0x00000000; 595 596 LOG(4, ("INIT: G450/G550 powerup\n")); 597 if (si->settings.logmask & 0x80000000) mga_dump_configuration_space(); 598 599 /* initialize the shared_info PINS struct */ 600 result = parse_pins(); 601 if (result != B_OK) fake_pins(); 602 603 /* log the PINS struct settings */ 604 dump_pins(); 605 606 /* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */ 607 if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics(); 608 609 /* power up the PLLs,LUT,DAC */ 610 LOG(4,("INIT: PLL/LUT/DAC powerup\n")); 611 /* disable outputs */ 612 DXIW(OUTPUTCONN,0x00); 613 /* turn off both displays and the hardcursor (also disables transfers) */ 614 gx00_crtc_dpms(false, false, false); 615 g400_crtc2_dpms(false, false, false); 616 gx00_crtc_cursor_hide(); 617 618 /* power up everything except DVI electronics (for now) */ 619 DXIW(PWRCTRL,0x1b); 620 /* set voltage reference - not using DAC reference block */ 621 DXIW(VREFCTRL,0x00); 622 /* wait for 100ms for voltage reference to stabilize */ 623 delay(100000); 624 /* power up the SYSPLL */ 625 CFGW(OPTION,CFGR(OPTION)|0x20); 626 /* power up the PIXPLL */ 627 DXIW(PIXCLKCTRL,0x08); 628 629 /* disable pixelclock oscillations before switching on CLUT */ 630 DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) | 0x04)); 631 /* disable 15bit mode CLUT-overlay function */ 632 DXIW(GENCTRL, DXIR(GENCTRL & 0xfd)); 633 /* CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC */ 634 DXIW(MISCCTRL,0x9b); 635 snooze(250); 636 637 /* re-enable pixelclock oscillations */ 638 DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) & 0xfb)); 639 640 //fixme: 641 DXIW(MAFCDEL,0x02); /*makes CRTC2 stable! Matrox specify 8, but use 4 - grrrr!*/ 642 DXIW(PANELMODE,0x00); /*eclipse panellink*/ 643 644 /* setup i2c bus */ 645 i2c_init(); 646 647 /* make sure card is in powergraphics mode */ 648 VGAW_I(CRTCEXT,3,0x80); 649 650 /* set the system clocks to powergraphics speed */ 651 LOG(2,("INIT: Setting system PLL to powergraphics speeds\n")); 652 g450_dac_set_sys_pll(); 653 654 /* 'official' RAM initialisation */ 655 LOG(2,("INIT: RAM init\n")); 656 /* stop memory refresh, and setup b9, memconfig, b13, sgram planemask function, b21 fields, 657 * and don't touch the rest */ 658 CFGW(OPTION, ((CFGR(OPTION) & 0xf8400164) | (si->ps.option_reg & 0x00207e00))); 659 /* setup b10-b15 unknown field */ 660 CFGW(OPTION2, ((CFGR(OPTION2) & 0xffff0200) | (si->ps.option2_reg & 0x0000fc00))); 661 662 /* program memory control waitstates */ 663 ACCW(MCTLWTST, si->ps.mctlwtst_reg); 664 /* program option4 b0-3 and b29-30 fields, reset the rest: stop memory clock */ 665 CFGW(OPTION4, (si->ps.option4_reg & 0x6000000f)); 666 /* set RAM read tap delays and mode register opcode / streamer flow control */ 667 ACCW(MEMRDBK, si->ps.memrdbk_reg); 668 /* b7 v5_mem_type = done by Mark Watson. fixme: still confirm! (unknown bits) */ 669 maccess = ((((uint32)si->ps.v5_mem_type) & 0x80) >> 1); 670 ACCW(MACCESS, maccess); 671 /* clear b0-1 and 3, and set b31 in option4: re-enable memory clock */ 672 CFGW(OPTION4, ((si->ps.option4_reg & 0x60000004) | 0x80000000)); 673 snooze(250); 674 675 /* if DDR RAM */ 676 if ((si->ps.v5_mem_type & 0x0060) == 0x0020) 677 { 678 /* if not 'EMRSW RAM-option' available */ 679 if (!(si->ps.v5_mem_type & 0x0100)) 680 { 681 /* clear unknown bits */ 682 maccess = 0x00000000; 683 ACCW(MACCESS, maccess); 684 /* clear b12: unknown bit */ 685 ACCW(MEMRDBK, (si->ps.memrdbk_reg & 0xffffefff)); 686 } 687 else 688 /* if not 'DLL RAM-option' available */ 689 if (!(si->ps.v5_mem_type & 0x0200)) 690 { 691 /* clear b12: unknown bit */ 692 ACCW(MEMRDBK, (si->ps.memrdbk_reg & 0xffffefff)); 693 } 694 } 695 696 /* create positive flank to generate memory reset */ 697 ACCW(MACCESS, (maccess & 0xffff7fff)); 698 ACCW(MACCESS, (maccess | 0x00008000)); 699 snooze(250); 700 701 /* start memory refresh */ 702 CFGW(OPTION,(CFGR(OPTION)&0xffe07fff) | (si->ps.option_reg & 0x001f8000)); 703 704 /* disable plane write mask (needed for SDRAM): actual change needed to get it sent to RAM */ 705 ACCW(PLNWT,0x00000000); 706 ACCW(PLNWT,0xffffffff); 707 708 /* if not 'MEMCASLT RAM-option' available */ 709 if (!(si->ps.v5_mem_type & 0x0400)) 710 { 711 /* calculate powergraphics CAS-latency from pins CAS-latency, and update register setting */ 712 ACCW(MCTLWTST, 713 ((si->ps.mctlwtst_reg & 0xfffffff8) | pwr_cas[(si->ps.mctlwtst_reg & 0x07)])); 714 715 } 716 717 /*enable writing to crtc registers*/ 718 VGAW_I(CRTC,0x11,0); 719 //fixme.. 720 if (si->ps.secondary_head) 721 { 722 //MAVW(LOCK,0x01); 723 CR2W(DATACTL,0x00000000); 724 } 725 726 /* enable primary analog output */ 727 gx50_general_output_select(); 728 729 /*turn on display one*/ 730 gx00_crtc_dpms(true, true, true); 731 732 /* enable 'straight-through' sync outputs on both analog output connectors */ 733 DXIW(SYNCCTRL,0x00); 734 735 return B_OK; 736 } 737 738 status_t gx50_general_output_select() 739 { 740 /* make sure this call is warranted */ 741 if ((si->ps.card_type != G450) && (si->ps.card_type != G550)) return B_ERROR; 742 743 /* choose primary analog outputconnector */ 744 if ((si->ps.primary_dvi) && (si->ps.secondary_head) && (si->ps.secondary_tvout)) 745 { 746 if (i2c_sec_tv_adapter() == B_OK) 747 { 748 LOG(4,("INIT: secondary TV-adapter detected, using primary connector\n")); 749 DXIW(OUTPUTCONN,0x01); 750 } 751 else 752 { 753 LOG(4,("INIT: no secondary TV-adapter detected, using secondary connector\n")); 754 DXIW(OUTPUTCONN,0x04); 755 } 756 } 757 else 758 { 759 LOG(4,("INIT: using primary connector\n")); 760 DXIW(OUTPUTCONN,0x01); 761 } 762 return B_OK; 763 } 764 765 /*connect CRTC1 to the specified DAC*/ 766 status_t gx00_general_dac_select(int dac) 767 { 768 if (!si->ps.secondary_head) 769 return B_ERROR; 770 771 /*MISCCTRL, clock src,...*/ 772 switch(dac) 773 { 774 /* G400 */ 775 case DS_CRTC1DAC_CRTC2MAVEN: 776 /* connect CRTC1 to pixPLL */ 777 DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0xc)|0x1); 778 /* connect CRTC2 to vidPLL, connect CRTC1 to internal DAC and 779 * enable CRTC2 external video timing reset signal. 780 * (Setting for MAVEN 'master mode' TVout signal generation.) */ 781 CR2W(CTL,(CR2R(CTL)&0xffe00779)|0xD0000002); 782 /* disable CRTC1 external video timing reset signal */ 783 VGAW_I(CRTCEXT,1,(VGAR_I(CRTCEXT,1)&0x77)); 784 /* select CRTC2 RGB24 MAFC mode: connects CRTC2 to MAVEN DAC */ 785 DXIW(MISCCTRL,(DXIR(MISCCTRL)&0x19)|0x82); 786 break; 787 case DS_CRTC1MAVEN_CRTC2DAC: 788 /* connect CRTC1 to vidPLL */ 789 DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0xc)|0x2); 790 /* connect CRTC2 to pixPLL and internal DAC and 791 * disable CRTC2 external video timing reset signal */ 792 CR2W(CTL,(CR2R(CTL)&0x2fe00779)|0x4|(0x1<<20)); 793 /* enable CRTC1 external video timing reset signal. 794 * note: this is nolonger used as G450/G550 cannot do TVout on CRTC1 */ 795 VGAW_I(CRTCEXT,1,(VGAR_I(CRTCEXT,1)|0x88)); 796 /* select CRTC1 RGB24 MAFC mode: connects CRTC1 to MAVEN DAC */ 797 DXIW(MISCCTRL,(DXIR(MISCCTRL)&0x19)|0x02); 798 break; 799 /* G450/G550 */ 800 case DS_CRTC1CON1_CRTC2CON2: 801 /* connect CRTC1 to pixPLL */ 802 DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0xc)|0x1); 803 /* connect CRTC2 to vidPLL, connect CRTC1 to DAC1, disable CRTC2 804 * external video timing reset signal, set CRTC2 progressive scan mode 805 * and disable TVout mode (b12). 806 * (Setting for MAVEN 'slave mode' TVout signal generation.) */ 807 //fixme: enable timing resets if TVout is used in master mode! 808 //otherwise keep it disabled. 809 CR2W(CTL,(CR2R(CTL)&0x2de00779)|0x6|(0x0<<20)); 810 /* connect DAC1 to CON1, CRTC2/'DAC2' to CON2 (monitor mode) */ 811 DXIW(OUTPUTCONN,0x09); 812 /* Select 1.5 Volt MAVEN DAC ref. for monitor mode */ 813 DXIW(GENIOCTRL, DXIR(GENIOCTRL) & ~0x40); 814 DXIW(GENIODATA, 0x00); 815 /* signal CRTC2 DPMS which connector to program */ 816 si->crossed_conns = false; 817 break; 818 //fixme: toggle PLL's below if possible: 819 // otherwise toggle PLL's for G400 2nd case? 820 case DS_CRTC1CON2_CRTC2CON1: 821 /* connect CRTC1 to pixPLL */ 822 DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0xc)|0x1); 823 /* connect CRTC2 to vidPLL and DAC1, disable CRTC2 external 824 * video timing reset signal, and set CRTC2 progressive scan mode and 825 * disable TVout mode (b12). */ 826 CR2W(CTL,(CR2R(CTL)&0x2de00779)|0x6|(0x1<<20)); 827 /* connect DAC1 to CON2 (monitor mode), CRTC2/'DAC2' to CON1 */ 828 DXIW(OUTPUTCONN,0x05); 829 /* Select 1.5 Volt MAVEN DAC ref. for monitor mode */ 830 DXIW(GENIOCTRL, DXIR(GENIOCTRL) & ~0x40); 831 DXIW(GENIODATA, 0x00); 832 /* signal CRTC2 DPMS which connector to program */ 833 si->crossed_conns = true; 834 break; 835 default: 836 return B_ERROR; 837 } 838 return B_OK; 839 } 840 841 /* basic change of card state from VGA to powergraphics -> should work from BIOS init state*/ 842 static 843 status_t gx00_general_bios_to_powergraphics() 844 { 845 LOG(2, ("INIT: Skipping card coldstart!\n")); 846 847 //set to powergraphics etc. 848 CFGW(DEVCTRL,(2|CFGR(DEVCTRL))); 849 /*enable device response (already enabled here!)*/ 850 851 VGAW_I(CRTC,0x11,0); 852 /*allow me to change CRTC*/ 853 854 VGAW_I(CRTCEXT,3,0x80); 855 /*use powergraphix (+ trash other bits, they are set later)*/ 856 857 VGAW(MISCW,0x08); 858 /*set only MGA pixel clock in MISC - I don't want to map VGA stuff under this OS*/ 859 860 switch (si->ps.card_type) 861 { 862 case G400: 863 case G400MAX: 864 /* reset MAVEN so we know the sync polarity is at reset situation (Hpos, Vpos) */ 865 if (si->ps.secondary_tvout) 866 { 867 ACCW(RST, 0x00000002); 868 snooze(1000); 869 ACCW(RST, 0x00000000); 870 } 871 /* makes CRTC2 stable! Matrox specify 8, but use 4 - grrrr! */ 872 DXIW(MAFCDEL,0x02); 873 break; 874 case G450: 875 case G550: 876 /* power up everything except DVI electronics (for now) */ 877 DXIW(PWRCTRL,0x1b); 878 /* enable 'straight-through' sync outputs on both analog output connectors */ 879 DXIW(SYNCCTRL,0x00); 880 break; 881 default: 882 break; 883 } 884 885 if (si->ps.card_type >= G100) 886 { 887 DXIW(MISCCTRL,0x9b); 888 /*CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC*/ 889 890 DXIW(MULCTRL,0x4); 891 /*RGBA direct mode*/ 892 } 893 else 894 { 895 LOG(8, ("INIT: < G100 DAC powerup badly implemented, MISC 0x%02x\n", VGAR(MISCR))); 896 } // apsed TODO MIL2 897 898 VGAW_I(SEQ,1,0x00); 899 /*enable screen*/ 900 901 return B_OK; 902 } 903 904 /* Check if mode virtual_size adheres to the cards _maximum_ contraints, and modify 905 * virtual_size to the nearest valid maximum for the mode on the card if not so. 906 * Then: check if virtual_width adheres to the cards _multiple_ constraints, and 907 * create mode slopspace if not so. 908 * We use acc multiple constraints here if we expect we can use acceleration, because 909 * acc constraints are worse than CRTC constraints. 910 * 911 * Mode slopspace is reflected in fbc->bytes_per_row BTW. */ 912 //fixme: seperate heads for real dualhead modes: 913 //CRTC1 and 2 constraints differ! 914 status_t gx00_general_validate_pic_size (display_mode *target, uint32 *bytes_per_row, bool *acc_mode) 915 { 916 /* Note: 917 * This routine assumes that the CRTC memory pitch granularity is 'smaller than', 918 * or 'equals' the acceleration engine memory pitch granularity! */ 919 920 uint32 video_pitch; 921 uint32 acc_mask, crtc_mask; 922 uint8 depth = 8; 923 924 /* determine pixel multiple based on 2D/3D engine constraints */ 925 switch (si->ps.card_type) 926 { 927 case MIL1: 928 case MIL2: 929 /* see MIL1/2 specs: 930 * these cards always use a 64bit RAMDAC (TVP3026) and interleaved memory */ 931 switch (target->space) 932 { 933 case B_CMAP8: acc_mask = 0x7f; depth = 8; break; 934 case B_RGB15: acc_mask = 0x3f; depth = 16; break; 935 case B_RGB16: acc_mask = 0x3f; depth = 16; break; 936 case B_RGB24: acc_mask = 0x7f; depth = 24; break; 937 case B_RGB32: acc_mask = 0x1f; depth = 32; break; 938 default: 939 LOG(8,("INIT: unknown color space: 0x%08x\n", target->space)); 940 return B_ERROR; 941 } 942 break; 943 default: 944 /* see G100 and up specs: 945 * these cards can do 2D as long as multiples of 32 are used. 946 * (Note: don't mix this up with adress linearisation!) */ 947 switch (target->space) 948 { 949 case B_CMAP8: depth = 8; break; 950 case B_RGB15: depth = 16; break; 951 case B_RGB16: depth = 16; break; 952 case B_RGB24: depth = 24; break; 953 case B_RGB32: depth = 32; break; 954 default: 955 LOG(8,("INIT: unknown color space: 0x%08x\n", target->space)); 956 return B_ERROR; 957 } 958 acc_mask = 0x1f; 959 break; 960 } 961 962 /* determine pixel multiple based on CRTC memory pitch constraints. 963 * (Note: Don't mix this up with CRTC timing contraints! Those are 964 * multiples of 8 for horizontal, 1 for vertical timing.) */ 965 switch (si->ps.card_type) 966 { 967 case MIL1: 968 case MIL2: 969 /* see MIL1/2 specs: 970 * these cards always use a 64bit RAMDAC and interleaved memory */ 971 switch (target->space) 972 { 973 case B_CMAP8: crtc_mask = 0x7f; break; 974 case B_RGB15: crtc_mask = 0x3f; break; 975 case B_RGB16: crtc_mask = 0x3f; break; 976 /* for B_RGB24 crtc_mask 0x7f is worst case scenario (MIL2 constraint) */ 977 case B_RGB24: crtc_mask = 0x7f; break; 978 case B_RGB32: crtc_mask = 0x1f; break; 979 default: 980 LOG(8,("INIT: unknown color space: 0x%08x\n", target->space)); 981 return B_ERROR; 982 } 983 break; 984 default: 985 /* see G100 and up specs */ 986 switch (target->space) 987 { 988 case B_CMAP8: crtc_mask = 0x0f; break; 989 case B_RGB15: crtc_mask = 0x07; break; 990 case B_RGB16: crtc_mask = 0x07; break; 991 case B_RGB24: crtc_mask = 0x0f; break; 992 case B_RGB32: crtc_mask = 0x03; break; 993 default: 994 LOG(8,("INIT: unknown color space: 0x%08x\n", target->space)); 995 return B_ERROR; 996 } 997 /* see G400 specs: CRTC2 has different constraints */ 998 /* Note: 999 * set for RGB and B_YCbCr422 modes. Other modes need larger multiples! */ 1000 if (target->flags & DUALHEAD_BITS) 1001 { 1002 switch (target->space) 1003 { 1004 case B_RGB16: crtc_mask = 0x1f; break; 1005 case B_RGB32: crtc_mask = 0x0f; break; 1006 default: 1007 LOG(8,("INIT: illegal DH color space: 0x%08x\n", target->space)); 1008 return B_ERROR; 1009 } 1010 } 1011 break; 1012 } 1013 1014 /* check if we can setup this mode with acceleration: 1015 * Max sizes need to adhere to both the acceleration engine _and_ the CRTC constraints! */ 1016 *acc_mode = true; 1017 /* check virtual_width */ 1018 switch (si->ps.card_type) 1019 { 1020 case MIL1: 1021 case MIL2: 1022 case G100: 1023 /* acc constraint: */ 1024 if (target->virtual_width > 2048) *acc_mode = false; 1025 break; 1026 default: 1027 /* G200-G550 */ 1028 /* acc constraint: */ 1029 if (target->virtual_width > 4096) *acc_mode = false; 1030 /* for 32bit mode a lower CRTC1 restriction applies! */ 1031 if ((target->space == B_RGB32_LITTLE) && (target->virtual_width > (4092 & ~acc_mask))) 1032 *acc_mode = false; 1033 break; 1034 } 1035 /* virtual_height */ 1036 if (target->virtual_height > 2048) *acc_mode = false; 1037 1038 /* now check virtual_size based on CRTC constraints, 1039 * making sure virtual_width stays within the 'mask' constraint: which is only 1040 * nessesary because of an extra constraint in MIL1/2 cards that exists here. */ 1041 { 1042 /* virtual_width */ 1043 //fixme for CRTC2 (identical on all G400+ cards): 1044 //16bit mode: max. virtual_width == 16352 (no extra mask needed); 1045 //32bit mode: max. virtual_width == 8176 (no extra mask needed); 1046 //other colordepths are unsupported on CRTC2. 1047 switch(target->space) 1048 { 1049 case B_CMAP8: 1050 if (target->virtual_width > (16368 & ~crtc_mask)) 1051 target->virtual_width = (16368 & ~crtc_mask); 1052 break; 1053 case B_RGB15_LITTLE: 1054 case B_RGB16_LITTLE: 1055 if (target->virtual_width > (8184 & ~crtc_mask)) 1056 target->virtual_width = (8184 & ~crtc_mask); 1057 break; 1058 case B_RGB24_LITTLE: 1059 if (target->virtual_width > (5456 & ~crtc_mask)) 1060 target->virtual_width = (5456 & ~crtc_mask); 1061 break; 1062 case B_RGB32_LITTLE: 1063 if (target->virtual_width > (4092 & ~crtc_mask)) 1064 target->virtual_width = (4092 & ~crtc_mask); 1065 break; 1066 } 1067 1068 /* virtual_height: The only constraint here is the cards memory size which is 1069 * checked later on in ProposeMode: virtual_height is adjusted then if needed. 1070 * 'Limiting here' to the variable size that's at least available (uint16). */ 1071 if (target->virtual_height > 65535) target->virtual_height = 65535; 1072 } 1073 1074 /* OK, now we know that virtual_width is valid, and it's needing no slopspace if 1075 * it was confined above, so we can finally calculate safely if we need slopspace 1076 * for this mode... */ 1077 if (*acc_mode) 1078 video_pitch = ((target->virtual_width + acc_mask) & ~acc_mask); 1079 else 1080 video_pitch = ((target->virtual_width + crtc_mask) & ~crtc_mask); 1081 1082 LOG(2,("INIT: memory pitch will be set to %d pixels for colorspace 0x%08x\n", 1083 video_pitch, target->space)); 1084 if (target->virtual_width != video_pitch) 1085 LOG(2,("INIT: effective mode slopspace is %d pixels\n", 1086 (video_pitch - target->virtual_width))); 1087 1088 /* now calculate bytes_per_row for this mode */ 1089 *bytes_per_row = video_pitch * (depth >> 3); 1090 1091 return B_OK; 1092 } 1093