1 diff -urN xc-4.0.2.orig/programs/Xserver/hw/xfree86/drivers/mga/Imakefile xc/programs/Xserver/hw/xfree86/drivers/mga/Imakefile
2 --- XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/drivers/mga/Imakefile Sat Dec 16 12:33:00 2000
3 +++ XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/drivers/mga/Imakefile Thu Feb 8 08:56:41 2001
6 MGASRCS = mga_driver.c mga_hwcurs.c /* mga_cmap.c */ mga_dac3026.c mga_dacG.c \
7 mga_storm8.c mga_storm16.c mga_storm24.c mga_storm32.c mga_arc.c \
8 - mga_dga.c mga_shadow.c mga_video.c $(DRISRCS)
9 + mga_dga.c mga_shadow.c mga_video.c mga_g450pll.c $(DRISRCS)
10 MGAOBJS = mga_driver.o mga_hwcurs.o /* mga_cmap.o */ mga_dac3026.o mga_dacG.o \
11 mga_storm8.o mga_storm16.o mga_storm24.o mga_storm32.o mga_arc.o \
12 - mga_dga.o mga_shadow.o mga_video.o $(DRIOBJS)
13 + mga_dga.o mga_shadow.o mga_video.o mga_g450pll.o $(DRIOBJS)
15 SRCS = $(MGASRCS) $(MGAHALSRCS)
16 OBJS = $(MGAOBJS) $(MGAHALOBJS)
17 diff -urN xc-4.0.2.orig/programs/Xserver/hw/xfree86/drivers/mga/mga.h xc/programs/Xserver/hw/xfree86/drivers/mga/mga.h
18 --- XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga.h Wed Dec 6 10:35:19 2000
19 +++ XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga.h Thu Feb 8 08:56:41 2001
21 void MGAInitVideo(ScreenPtr pScreen);
22 void MGAResetVideo(ScrnInfoPtr pScrn);
24 +double G450SetPLLFreq(ScrnInfoPtr pScrn, long f_out);
26 diff -urN xc-4.0.2.orig/programs/Xserver/hw/xfree86/drivers/mga/mga_dacG.c xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dacG.c
27 --- XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dacG.c Wed Dec 6 10:35:20 2000
28 +++ XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dacG.c Thu Feb 8 08:56:41 2001
30 /* The actual frequency output by the clock */
33 + if(MGAISG450(pMga)) {
34 + G450SetPLLFreq(pScrn, f_out);
38 /* Do the calculations for m, n, p and s */
39 f_pll = MGAGCalcClock( pScrn, f_out, &m, &n, &p, &s );
45 + if (MGAISG450(pMga))
48 if(pMga->Dac.maxPixelClock == 360000) { /* G400 MAX */
49 if(pMga->OverclockMem) {
52 if (mode->Flags & V_DBLSCAN)
53 pVga->CRTC[9] |= 0x80;
55 + if(MGAISG450(pMga)) {
56 + OUTREG(MGAREG_ZORG, 0);
59 MGAGSetPCLK(pScrn, mode->Clock);
65 ((i >= 0x1f) && (i <= 0x29)) ||
66 - ((i >= 0x30) && (i <= 0x37)) )
67 + ((i >= 0x30) && (i <= 0x37)) ||
69 + ((i == 0x2c) || (i == 0x2d) || (i == 0x2e) ||
70 + (i == 0x4c) || (i == 0x4d) || (i == 0x4e))))
72 outMGAdac(i, mgaReg->DacRegs[i]);
75 should be correct already */
76 optionMask = (pMga->Primary) ? OPTION1_MASK_PRIMARY : OPTION1_MASK;
78 - /* restore pci_option register */
79 - pciSetBitsLong(pMga->PciTag, PCI_OPTION_REG, optionMask,
81 - if (pMga->Chipset != PCI_CHIP_MGA1064)
82 - pciSetBitsLong(pMga->PciTag, PCI_MGA_OPTION2, OPTION2_MASK,
84 - if (pMga->Chipset == PCI_CHIP_MGAG400)
85 - pciSetBitsLong(pMga->PciTag, PCI_MGA_OPTION3, OPTION3_MASK,
87 + if (!MGAISG450(pMga)) {
88 + /* restore pci_option register */
89 + pciSetBitsLong(pMga->PciTag, PCI_OPTION_REG, optionMask,
91 + if (pMga->Chipset != PCI_CHIP_MGA1064)
92 + pciSetBitsLong(pMga->PciTag, PCI_MGA_OPTION2, OPTION2_MASK,
94 + if (pMga->Chipset == PCI_CHIP_MGAG400)
95 + pciSetBitsLong(pMga->PciTag, PCI_MGA_OPTION3, OPTION3_MASK,
100 /* restore CRTCEXT regs */
101 diff -urN xc-4.0.2.orig/programs/Xserver/hw/xfree86/drivers/mga/mga_g450pll.c xc/programs/Xserver/hw/xfree86/drivers/mga/mga_g450pll.c
102 --- XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_g450pll.c Wed Dec 31 19:00:00 1969
103 +++ XFree86-4.0.2/xc/programs/Xserver/hw/xfree86/drivers/mga/mga_g450pll.c Thu Feb 8 08:56:41 2001
105 +/* All drivers should typically include these */
107 +#include "xf86_OSproc.h"
108 +#include "xf86_ansic.h"
110 +/* Drivers for PCI hardware need this */
111 +#include "xf86PciInfo.h"
113 +/* Drivers that need to access the PCI config space directly need this */
114 +#include "xf86Pci.h"
116 +#include "mga_bios.h"
117 +#include "mga_reg.h"
122 +#define MNP_TABLE_SIZE 64
123 +#define CLKSEL_MGA 0x0c
124 +#define PLLLOCK 0x40
126 +#define outMGAdreg(reg, val) OUTREG8(RAMDAC_OFFSET + (reg), val)
128 +#define outMGAdac(reg, val) \
129 + (outMGAdreg(MGA1064_INDEX, reg), outMGAdreg(MGA1064_DATA, val))
131 +static CARD32 G450ApplyPFactor(ScrnInfoPtr pScrn, CARD8 ucP, CARD32 *pulFIn)
135 + *pulFIn = *pulFIn / (2L << (ucP & 3));
142 +static CARD32 G450RemovePFactor(ScrnInfoPtr pScrn, CARD8 ucP, CARD32 *pulFIn)
146 + *pulFIn = *pulFIn * (2L << (ucP & 3));
153 +static CARD32 G450CalculVCO(ScrnInfoPtr pScrn, CARD32 ulMNP, CARD32 *pulF)
155 + CARD8 ucM, ucN, ucP;
157 + ucM = (CARD8)((ulMNP >> 16) & 0xff);
158 + ucN = (CARD8)((ulMNP >> 8) & 0xff);
159 + ucP = (CARD8)(ulMNP & 0x03);
161 + *pulF = (27000 * (2 * (ucN + 2)) + ((ucM + 1) >> 1)) / (ucM + 1);
167 +static CARD32 G450CalculDeltaFreq(ScrnInfoPtr pScrn, CARD32 ulF1,
168 + CARD32 ulF2, CARD32 *pulDelta)
172 + *pulDelta = ((ulF1 - ulF2) * 1000) / ulF1;
176 + *pulDelta = ((ulF2 - ulF1) * 1000) / ulF1;
185 +static CARD32 G450FindNextPLLParam(ScrnInfoPtr pScrn, CARD32 ulFout,
188 + CARD8 ucM, ucN, ucP, ucS;
189 + CARD32 ulVCO, ulVCOMin;
191 + ucM = (CARD8)((*pulPLLMNP >> 16) & 0xff);
192 + ucN = (CARD8)((*pulPLLMNP >> 8) & 0xff);
193 + ucP = (CARD8)(*pulPLLMNP & 0x43);
197 + if(ulVCOMin >= (255L * 8000))
202 + if((ucM == 9) && (ucP & 0x40))
204 + *pulPLLMNP = 0xffffffff;
205 + } else if (ucM == 9)
224 + G450RemovePFactor(pScrn, ucP, &ulVCO);
226 + if(ulVCO < ulVCOMin)
228 + *pulPLLMNP = 0xffffffff;
231 + if(*pulPLLMNP != 0xffffffff)
233 + ucN = (CARD8)(((ulVCO * (ucM+1) + 27000)/(27000 * 2)) - 2);
236 + if(ulVCO < 1300000) ucS = 4;
237 + if(ulVCO < 1100000) ucS = 3;
238 + if(ulVCO < 900000) ucS = 2;
239 + if(ulVCO < 700000) ucS = 1;
240 + if(ulVCO < 550000) ucS = 0;
242 + ucP |= (CARD8)(ucS << 3);
244 + *pulPLLMNP &= 0xff000000;
245 + *pulPLLMNP |= (CARD32)ucM << 16;
246 + *pulPLLMNP |= (CARD32)ucN << 8;
247 + *pulPLLMNP |= (CARD32)ucP;
254 +static CARD32 G450FindFirstPLLParam(ScrnInfoPtr pScrn, CARD32 ulFout,
261 + /* Default value */
262 + ulVCOMax = 1300000;
264 + if(ulFout > (ulVCOMax/2))
273 + G450RemovePFactor(pScrn, ucP, &ulVCO);
274 + while(ucP && (ulVCO > ulVCOMax))
278 + G450RemovePFactor(pScrn, ucP, &ulVCO);
282 + if(ulVCO > ulVCOMax)
284 + *pulPLLMNP = 0xffffffff;
288 + /* Pixel clock: 1 */
289 + *pulPLLMNP = (1 << 24) + 0xff0000 + ucP;
290 + G450FindNextPLLParam(pScrn, ulFout, pulPLLMNP);
298 +static CARD32 G450WriteMNP(ScrnInfoPtr pScrn, CARD32 ulMNP)
300 + MGAPtr pMga = MGAPTR(pScrn);
303 + outMGAdac(MGA1064_PIX_PLLC_M, (CARD8)(ulMNP >> 16));
304 + outMGAdac(MGA1064_PIX_PLLC_N, (CARD8)(ulMNP >> 8));
305 + outMGAdac(MGA1064_PIX_PLLC_P, (CARD8) ulMNP);
306 + OUTREG8(0x3c00, 0x4f);
311 +static CARD32 G450CompareMNP(ScrnInfoPtr pScrn, CARD32 ulFout, CARD32 ulMNP1,
312 + CARD32 ulMNP2, long *pulResult)
314 + CARD32 ulFreq, ulDelta1, ulDelta2;
316 + G450CalculVCO(pScrn, ulMNP1, &ulFreq);
317 + G450ApplyPFactor(pScrn, (CARD8) ulMNP1, &ulFreq);
318 + G450CalculDeltaFreq(pScrn, ulFout, ulFreq, &ulDelta1);
320 + G450CalculVCO(pScrn, ulMNP2, &ulFreq);
321 + G450ApplyPFactor(pScrn, (CARD8) ulMNP2, &ulFreq);
322 + G450CalculDeltaFreq(pScrn, ulFout, ulFreq, &ulDelta2);
324 + if(ulDelta1 < ulDelta2)
328 + else if(ulDelta1 > ulDelta2)
337 + if((ulDelta1 <= 5) && (ulDelta2 <= 5))
339 + if((ulMNP1 & 0xff0000) < (ulMNP2 & 0xff0000))
343 + else if((ulMNP1 & 0xff0000) > (ulMNP2 & 0xff0000))
353 +static CARD32 G450IsPllLocked(ScrnInfoPtr pScrn, Bool *lpbLocked)
355 + CARD32 ulFallBackCounter, ulLockCount, ulCount;
358 + MGAPtr pMga = MGAPTR(pScrn);
361 + OUTREG8(0x3c00, 0x4f);
363 + ulFallBackCounter = 0;
367 + ucPLLStatus = INREG8(0x3c0a);
368 + ulFallBackCounter++;
369 + } while(!(ucPLLStatus & PLLLOCK) && (ulFallBackCounter < 1000));
372 + if(ulFallBackCounter < 1000)
374 + for(ulCount = 0; ulCount < 100; ulCount++)
376 + ucPLLStatus = INREG8(0x3c0a);
377 + if(ucPLLStatus & PLLLOCK)
384 + *lpbLocked = ulLockCount >= 90;
390 +double G450SetPLLFreq(ScrnInfoPtr pScrn, long f_out)
392 + Bool bFoundValidPLL;
398 + CARD32 ulMNPTable[MNP_TABLE_SIZE];
401 + long lCompareResult;
403 + MGAPtr pMga = MGAPTR(pScrn);
405 + G450FindFirstPLLParam(pScrn, f_out, &ulMNP);
406 + ulMNPTable[0] = ulMNP;
407 + G450FindNextPLLParam(pScrn, f_out, &ulMNP);
409 + while(ulMNP != 0xffffffff)
414 + bSkipValue = FALSE;
415 + if(ulMaxIndex == MNP_TABLE_SIZE)
417 + G450CompareMNP(pScrn, f_out, ulMNP, ulMNPTable[MNP_TABLE_SIZE - 1],
420 + if(lCompareResult > 0)
432 + for(ulIndex = ulMaxIndex; !bSkipValue && (ulIndex > 0); ulIndex--)
434 + G450CompareMNP(pScrn, f_out, ulMNP, ulMNPTable[ulIndex - 1],
437 + if(lCompareResult < 0)
439 + ulMNPTable[ulIndex] = ulMNPTable[ulIndex - 1];
446 + ulMNPTable[ulIndex] = ulMNP;
450 + G450FindNextPLLParam(pScrn, f_out, &ulMNP);
453 + bFoundValidPLL = FALSE;
456 + /* For pixel pll */
457 + ucMisc = INREG8(0x1FCC);
458 + OUTREG8(0x1fc2, (CARD8)(ucMisc | CLKSEL_MGA));
460 + for(ulIndex = 0; !bFoundValidPLL && (ulIndex < ulMaxIndex); ulIndex++)
462 + ulTryMNP = ulMNPTable[ulIndex];
464 + for(ucS = 0; !bFoundValidPLL && (ucS < 0x40); ucS += 8)
466 + ulTryMNP &= 0xffffffc7;
467 + ulTryMNP |= (CARD32)ucS;
470 + if((ulMNPTable[ulIndex] & 0xff00) < 0x300 ||
471 + (ulMNPTable[ulIndex] & 0xff00) > 0x7a00)
478 + G450WriteMNP(pScrn, ulTryMNP - 0x300);
479 + G450IsPllLocked(pScrn, &bLocked);
484 + G450WriteMNP(pScrn, ulTryMNP + 0x300);
485 + G450IsPllLocked(pScrn, &bLocked);
490 + G450WriteMNP(pScrn, ulTryMNP - 0x200);
491 + G450IsPllLocked(pScrn, &bLocked);
496 + G450WriteMNP(pScrn, ulTryMNP + 0x200);
497 + G450IsPllLocked(pScrn, &bLocked);
502 + G450WriteMNP(pScrn, ulTryMNP - 0x100);
503 + G450IsPllLocked(pScrn, &bLocked);
508 + G450WriteMNP(pScrn, ulTryMNP + 0x100);
509 + G450IsPllLocked(pScrn, &bLocked);
514 + G450WriteMNP(pScrn, ulTryMNP);
515 + G450IsPllLocked(pScrn, &bLocked);
519 + G450WriteMNP(pScrn, ulTryMNP);
520 + G450IsPllLocked(pScrn, &bLocked);
523 + ulMNP = ulMNPTable[ulIndex];
530 + bFoundValidPLL = TRUE;
535 + if(!bFoundValidPLL)
539 + G450WriteMNP(pScrn, ulMNP);
543 + G450WriteMNP(pScrn, ulMNPTable[0]);