]> git.pld-linux.org Git - packages/XFree86.git/blob - XFree86-g450.patch
- merg from rawhide.
[packages/XFree86.git] / XFree86-g450.patch
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
4 @@ -57,10 +57,10 @@
5  
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)
14  
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
20 @@ -414,4 +414,5 @@
21  void MGAInitVideo(ScreenPtr pScreen);
22  void MGAResetVideo(ScrnInfoPtr pScrn); 
23  
24 +double G450SetPLLFreq(ScrnInfoPtr pScrn, long f_out);
25  #endif
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
29 @@ -237,6 +237,11 @@
30         /* The actual frequency output by the clock */
31         double f_pll;
32  
33 +       if(MGAISG450(pMga)) {
34 +               G450SetPLLFreq(pScrn, f_out);
35 +               return;
36 +       }
37 +
38         /* Do the calculations for m, n, p and s */
39         f_pll = MGAGCalcClock( pScrn, f_out, &m, &n, &p, &s );
40  
41 @@ -338,6 +343,9 @@
42  #ifdef USEMGAHAL
43                MGA_HAL(break;);
44  #endif
45 +              if (MGAISG450(pMga))
46 +                      break;
47 +
48                if(pMga->Dac.maxPixelClock == 360000) {  /* G400 MAX */
49                    if(pMga->OverclockMem) {
50                         /* 150/200  */
51 @@ -528,6 +536,10 @@
52         if (mode->Flags & V_DBLSCAN)
53                 pVga->CRTC[9] |= 0x80;
54  
55 +       if(MGAISG450(pMga)) {
56 +               OUTREG(MGAREG_ZORG, 0);
57 +       }
58 +
59         MGAGSetPCLK(pScrn, mode->Clock);
60         );      /* MGA_NOT_HAL */
61  
62 @@ -656,7 +668,10 @@
63                 (i == 0x1b) ||
64                 (i == 0x1c) ||
65                ((i >= 0x1f) && (i <= 0x29)) ||
66 -              ((i >= 0x30) && (i <= 0x37)) )
67 +              ((i >= 0x30) && (i <= 0x37)) ||
68 +               (MGAISG450(pMga) &&
69 +                        ((i == 0x2c) || (i == 0x2d) || (i == 0x2e) ||
70 +                         (i == 0x4c) || (i == 0x4d) || (i == 0x4e))))
71                         continue; 
72             outMGAdac(i, mgaReg->DacRegs[i]);
73         }
74 @@ -665,15 +680,17 @@
75            should be correct already */
76         optionMask = (pMga->Primary) ? OPTION1_MASK_PRIMARY : OPTION1_MASK; 
77  
78 -       /* restore pci_option register */
79 -       pciSetBitsLong(pMga->PciTag, PCI_OPTION_REG, optionMask,
80 -                      mgaReg->Option);
81 -       if (pMga->Chipset != PCI_CHIP_MGA1064)
82 -               pciSetBitsLong(pMga->PciTag, PCI_MGA_OPTION2, OPTION2_MASK,
83 -                              mgaReg->Option2);
84 -       if (pMga->Chipset == PCI_CHIP_MGAG400)
85 -               pciSetBitsLong(pMga->PciTag, PCI_MGA_OPTION3, OPTION3_MASK,
86 -                              mgaReg->Option3);
87 +       if (!MGAISG450(pMga)) {
88 +               /* restore pci_option register */
89 +               pciSetBitsLong(pMga->PciTag, PCI_OPTION_REG, optionMask,
90 +                              mgaReg->Option);
91 +               if (pMga->Chipset != PCI_CHIP_MGA1064)
92 +                       pciSetBitsLong(pMga->PciTag, PCI_MGA_OPTION2, OPTION2_MASK,
93 +                                      mgaReg->Option2);
94 +               if (pMga->Chipset == PCI_CHIP_MGAG400)
95 +                       pciSetBitsLong(pMga->PciTag, PCI_MGA_OPTION3, OPTION3_MASK,
96 +                                      mgaReg->Option3);
97 +       }
98         );      /* MGA_NOT_HAL */
99  
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
104 @@ -0,0 +1,444 @@
105 +/* All drivers should typically include these */
106 +#include "xf86.h"
107 +#include "xf86_OSproc.h"
108 +#include "xf86_ansic.h" 
109 +
110 +/* Drivers for PCI hardware need this */
111 +#include "xf86PciInfo.h"
112 +
113 +/* Drivers that need to access the PCI config space directly need this */
114 +#include "xf86Pci.h"
115 +
116 +#include "mga_bios.h"
117 +#include "mga_reg.h"
118 +#include "mga.h"
119 +
120 +#define DEBUG
121 +
122 +#define MNP_TABLE_SIZE 64
123 +#define CLKSEL_MGA     0x0c
124 +#define PLLLOCK        0x40
125 +
126 +#define outMGAdreg(reg, val) OUTREG8(RAMDAC_OFFSET + (reg), val)
127 +
128 +#define outMGAdac(reg, val) \
129 +       (outMGAdreg(MGA1064_INDEX, reg), outMGAdreg(MGA1064_DATA, val))
130 +
131 +static CARD32 G450ApplyPFactor(ScrnInfoPtr pScrn, CARD8 ucP, CARD32 *pulFIn)
132 +{
133 +   if(!(ucP & 0x40))
134 +   {
135 +      *pulFIn = *pulFIn / (2L << (ucP & 3));
136 +   }
137 +
138 +   return TRUE;
139 +}
140 +
141 +
142 +static CARD32 G450RemovePFactor(ScrnInfoPtr pScrn, CARD8 ucP, CARD32 *pulFIn)
143 +{
144 +   if(!(ucP & 0x40))
145 +   {
146 +      *pulFIn = *pulFIn * (2L << (ucP & 3));
147 +   }
148 +  
149 +   return TRUE; 
150 +}
151 +
152 +
153 +static CARD32 G450CalculVCO(ScrnInfoPtr pScrn, CARD32 ulMNP, CARD32 *pulF)
154 +{
155 +   CARD8 ucM, ucN, ucP;
156 +
157 +   ucM = (CARD8)((ulMNP >> 16) & 0xff);
158 +   ucN = (CARD8)((ulMNP >>  8) & 0xff);
159 +   ucP = (CARD8)(ulMNP & 0x03);
160 +
161 +   *pulF = (27000 * (2 * (ucN + 2)) + ((ucM + 1) >> 1)) / (ucM + 1);
162 +   
163 +   return TRUE;
164 +}
165 +
166 +
167 +static CARD32 G450CalculDeltaFreq(ScrnInfoPtr pScrn, CARD32 ulF1,
168 +                                  CARD32 ulF2, CARD32 *pulDelta)
169 +{
170 +   if(ulF2 < ulF1)
171 +   {
172 +      *pulDelta = ((ulF1 - ulF2) * 1000) / ulF1;
173 +   }
174 +   else
175 +   {
176 +      *pulDelta = ((ulF2 - ulF1) * 1000) / ulF1;
177 +   }
178
179 +   return TRUE;
180 +}
181 +
182 +
183 +
184 +
185 +static CARD32 G450FindNextPLLParam(ScrnInfoPtr pScrn, CARD32 ulFout,
186 +                                   CARD32 *pulPLLMNP)
187 +{
188 +   CARD8 ucM, ucN, ucP, ucS;
189 +   CARD32 ulVCO, ulVCOMin;
190 +
191 +   ucM = (CARD8)((*pulPLLMNP >> 16) & 0xff);
192 +   ucN = (CARD8)((*pulPLLMNP >>  8) & 0xff);
193 +   ucP = (CARD8)(*pulPLLMNP &  0x43);
194 +
195 +   ulVCOMin = 256000;
196 +
197 +   if(ulVCOMin >= (255L * 8000))
198 +   {
199 +      ulVCOMin = 230000;
200 +   }
201 +   
202 +   if((ucM == 9) && (ucP & 0x40))
203 +   {
204 +      *pulPLLMNP = 0xffffffff;
205 +   } else if (ucM == 9)
206 +   {
207 +      if(ucP)
208 +      {
209 +         ucP--;
210 +      }
211 +      else
212 +      {
213 +         ucP = 0x40;
214 +      }
215 +      ucM = 0;
216 +   }
217 +   else
218 +   {
219 +      ucM++;
220 +   }
221 +
222 +   ulVCO = ulFout;
223 +
224 +   G450RemovePFactor(pScrn, ucP, &ulVCO);
225 +
226 +   if(ulVCO < ulVCOMin)
227 +   {
228 +      *pulPLLMNP = 0xffffffff;
229 +   }
230 +
231 +   if(*pulPLLMNP != 0xffffffff)
232 +   {
233 +      ucN = (CARD8)(((ulVCO * (ucM+1) + 27000)/(27000 * 2)) - 2);
234 +
235 +      ucS = 5;
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;
241 +
242 +      ucP |= (CARD8)(ucS << 3);
243 +
244 +      *pulPLLMNP &= 0xff000000;
245 +      *pulPLLMNP |= (CARD32)ucM << 16;
246 +      *pulPLLMNP |= (CARD32)ucN << 8;
247 +      *pulPLLMNP |= (CARD32)ucP;
248 +   }
249 +
250 +   return TRUE;
251 +}
252 +
253
254 +static CARD32 G450FindFirstPLLParam(ScrnInfoPtr pScrn, CARD32 ulFout, 
255 +                                    CARD32 *pulPLLMNP)
256 +{
257 +   CARD8 ucP;
258 +   CARD32 ulVCO;
259 +   CARD32 ulVCOMax;
260 +
261 +   /* Default value */
262 +   ulVCOMax = 1300000;
263 +
264 +   if(ulFout > (ulVCOMax/2))
265 +   {
266 +      ucP = 0x40;
267 +      ulVCO = ulFout;
268 +   }
269 +   else
270 +   {
271 +      ucP = 3;
272 +      ulVCO = ulFout;
273 +      G450RemovePFactor(pScrn, ucP, &ulVCO);
274 +      while(ucP && (ulVCO > ulVCOMax))
275 +      {
276 +         ucP--;
277 +         ulVCO = ulFout;
278 +         G450RemovePFactor(pScrn, ucP, &ulVCO);
279 +      }
280 +   }
281 +
282 +   if(ulVCO > ulVCOMax)
283 +   {
284 +      *pulPLLMNP = 0xffffffff;
285 +   }
286 +   else
287 +   {
288 +      /* Pixel clock: 1 */
289 +      *pulPLLMNP = (1 << 24) + 0xff0000 + ucP;
290 +      G450FindNextPLLParam(pScrn, ulFout, pulPLLMNP);
291 +   }
292 +
293 +   return TRUE;
294 +
295 +}
296 +
297 +
298 +static CARD32 G450WriteMNP(ScrnInfoPtr pScrn, CARD32 ulMNP)
299 +{
300 +   MGAPtr pMga = MGAPTR(pScrn);
301 +
302 +   /* Pixel Pll */
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);    
307 +   return TRUE;
308 +}
309 +
310 +
311 +static CARD32 G450CompareMNP(ScrnInfoPtr pScrn, CARD32 ulFout, CARD32 ulMNP1,
312 +                      CARD32 ulMNP2, long *pulResult)
313 +{
314 +   CARD32 ulFreq, ulDelta1, ulDelta2;
315 +
316 +   G450CalculVCO(pScrn, ulMNP1, &ulFreq);
317 +   G450ApplyPFactor(pScrn, (CARD8) ulMNP1, &ulFreq);
318 +   G450CalculDeltaFreq(pScrn, ulFout, ulFreq, &ulDelta1);
319 +
320 +   G450CalculVCO(pScrn, ulMNP2, &ulFreq);
321 +   G450ApplyPFactor(pScrn, (CARD8) ulMNP2, &ulFreq);
322 +   G450CalculDeltaFreq(pScrn, ulFout, ulFreq, &ulDelta2);
323 +
324 +   if(ulDelta1 < ulDelta2)
325 +   {
326 +      *pulResult = -1;
327 +   }
328 +   else if(ulDelta1 > ulDelta2)
329 +   {
330 +      *pulResult = 1;
331 +   }
332 +   else
333 +   {
334 +      *pulResult = 0;
335 +   }
336 +
337 +   if((ulDelta1 <= 5) && (ulDelta2 <= 5))
338 +   {
339 +      if((ulMNP1 & 0xff0000) < (ulMNP2 & 0xff0000))
340 +      {
341 +         *pulResult = -1;
342 +      }
343 +      else if((ulMNP1 & 0xff0000) > (ulMNP2 & 0xff0000))
344 +      {
345 +         *pulResult = 1;
346 +      }
347 +   }
348 +
349 +   return TRUE;
350 +}
351 +
352 +
353 +static CARD32 G450IsPllLocked(ScrnInfoPtr pScrn, Bool *lpbLocked)
354 +{
355 +   CARD32 ulFallBackCounter, ulLockCount, ulCount;
356 +   CARD8  ucPLLStatus;
357 +
358 +   MGAPtr pMga = MGAPTR(pScrn);
359 +
360 +   /* Pixel PLL */
361 +   OUTREG8(0x3c00, 0x4f);    
362 +
363 +   ulFallBackCounter = 0;
364 +
365 +   do 
366 +   {
367 +      ucPLLStatus = INREG8(0x3c0a);
368 +      ulFallBackCounter++;
369 +   } while(!(ucPLLStatus & PLLLOCK) && (ulFallBackCounter < 1000));
370 +
371 +   ulLockCount = 0;
372 +   if(ulFallBackCounter < 1000)
373 +   {
374 +      for(ulCount = 0; ulCount < 100; ulCount++)
375 +      {
376 +         ucPLLStatus = INREG8(0x3c0a);
377 +         if(ucPLLStatus & PLLLOCK)
378 +         {
379 +            ulLockCount++;
380 +         }
381 +      }
382 +   }
383 +
384 +   *lpbLocked = ulLockCount >= 90;
385 +
386 +   return TRUE;
387 +}
388 +
389 +
390 +double G450SetPLLFreq(ScrnInfoPtr pScrn, long f_out) 
391 +{
392 +   Bool bFoundValidPLL;
393 +   Bool bLocked;
394 +   CARD8  ucMisc;
395 +   CARD8  ucS;
396 +   CARD32 ulMaxIndex;
397 +   CARD32 ulMNP;
398 +   CARD32 ulMNPTable[MNP_TABLE_SIZE];
399 +   CARD32 ulIndex;
400 +   CARD32 ulTryMNP;
401 +   long lCompareResult;
402 +
403 +   MGAPtr pMga = MGAPTR(pScrn);
404 +
405 +   G450FindFirstPLLParam(pScrn, f_out, &ulMNP);
406 +   ulMNPTable[0] = ulMNP;
407 +   G450FindNextPLLParam(pScrn, f_out, &ulMNP);
408 +   ulMaxIndex = 1;
409 +   while(ulMNP != 0xffffffff)
410 +   {
411 +      int ulIndex;
412 +      Bool bSkipValue;
413 +
414 +      bSkipValue = FALSE;
415 +      if(ulMaxIndex == MNP_TABLE_SIZE)
416 +      {
417 +         G450CompareMNP(pScrn, f_out, ulMNP, ulMNPTable[MNP_TABLE_SIZE - 1],
418 +                        &lCompareResult);
419 +
420 +         if(lCompareResult > 0)
421 +         {
422 +            bSkipValue = TRUE;
423 +         }
424 +         else
425 +         {
426 +            ulMaxIndex--;
427 +         }
428 +      }
429 +
430 +      if(!bSkipValue)
431 +      {
432 +         for(ulIndex = ulMaxIndex; !bSkipValue && (ulIndex > 0); ulIndex--)
433 +         {
434 +            G450CompareMNP(pScrn, f_out, ulMNP, ulMNPTable[ulIndex - 1],
435 +                           &lCompareResult);
436 +
437 +            if(lCompareResult < 0)
438 +            {
439 +               ulMNPTable[ulIndex] = ulMNPTable[ulIndex - 1];
440 +            }
441 +            else
442 +            {
443 +               break;
444 +            }
445 +         }
446 +         ulMNPTable[ulIndex] = ulMNP;
447 +         ulMaxIndex++;
448 +      }
449 +
450 +      G450FindNextPLLParam(pScrn, f_out, &ulMNP);
451 +   }
452 +
453 +   bFoundValidPLL = FALSE;
454 +   ulMNP = 0;
455 +
456 +   /* For pixel pll */
457 +   ucMisc = INREG8(0x1FCC);
458 +   OUTREG8(0x1fc2, (CARD8)(ucMisc | CLKSEL_MGA));    
459 +
460 +   for(ulIndex = 0; !bFoundValidPLL && (ulIndex < ulMaxIndex); ulIndex++)
461 +   {
462 +      ulTryMNP = ulMNPTable[ulIndex];
463 +
464 +      for(ucS = 0; !bFoundValidPLL && (ucS < 0x40); ucS += 8)
465 +      {
466 +         ulTryMNP &= 0xffffffc7;
467 +         ulTryMNP |= (CARD32)ucS;
468 +         
469 +         bLocked = TRUE;
470 +         if((ulMNPTable[ulIndex] & 0xff00) < 0x300 ||
471 +            (ulMNPTable[ulIndex] & 0xff00) > 0x7a00)
472 +         {
473 +            bLocked = FALSE;
474 +         }
475 +
476 +         if(bLocked)
477 +         {
478 +            G450WriteMNP(pScrn, ulTryMNP - 0x300);
479 +            G450IsPllLocked(pScrn, &bLocked);
480 +         }     
481 +
482 +         if(bLocked)
483 +         {
484 +            G450WriteMNP(pScrn, ulTryMNP + 0x300);
485 +            G450IsPllLocked(pScrn, &bLocked);
486 +         }     
487 +
488 +         if(bLocked)
489 +         {
490 +            G450WriteMNP(pScrn, ulTryMNP - 0x200);
491 +            G450IsPllLocked(pScrn, &bLocked);
492 +         }     
493 +
494 +         if(bLocked)
495 +         {
496 +            G450WriteMNP(pScrn, ulTryMNP + 0x200);
497 +            G450IsPllLocked(pScrn, &bLocked);
498 +         }     
499 +
500 +         if(bLocked)
501 +         {
502 +            G450WriteMNP(pScrn, ulTryMNP - 0x100);
503 +            G450IsPllLocked(pScrn, &bLocked);
504 +         }     
505 +
506 +         if(bLocked)
507 +         {
508 +            G450WriteMNP(pScrn, ulTryMNP + 0x100);
509 +            G450IsPllLocked(pScrn, &bLocked);
510 +         }     
511 +
512 +         if(bLocked)
513 +         {
514 +            G450WriteMNP(pScrn, ulTryMNP);
515 +            G450IsPllLocked(pScrn, &bLocked);
516 +         }     
517 +         else if(!ulMNP)
518 +         {
519 +            G450WriteMNP(pScrn, ulTryMNP);
520 +            G450IsPllLocked(pScrn, &bLocked);
521 +            if(bLocked)
522 +            {
523 +               ulMNP = ulMNPTable[ulIndex]; 
524 +            }
525 +            bLocked = FALSE;
526 +         }
527 +
528 +         if(bLocked)
529 +         {
530 +            bFoundValidPLL = TRUE;
531 +         }
532 +      }
533 +   }
534 +
535 +   if(!bFoundValidPLL)
536 +   {
537 +      if(ulMNP)
538 +      {
539 +         G450WriteMNP(pScrn, ulMNP);
540 +      }
541 +      else
542 +      {
543 +         G450WriteMNP(pScrn, ulMNPTable[0]);
544 +      }
545 +   }
546 +  
547 +   return TRUE;
548 +}
This page took 0.065891 seconds and 3 git commands to generate.