summaryrefslogtreecommitdiff
path: root/staging/xf86-video-mga/git-fixes.patch
blob: 3534342e673db48421b156bb1447c63dc1bb3b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
diff --git a/man/Makefile.am b/man/Makefile.am
index b3688ce..1ea26b3 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -1,5 +1,5 @@
 #
-# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the "Software"),
@@ -19,7 +19,7 @@
 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
-# 
+#
 
 drivermandir = $(DRIVER_MAN_DIR)
 
diff --git a/man/mga.man b/man/mga.man
index 3a7a9f8..e1e674f 100644
--- a/man/mga.man
+++ b/man/mga.man
@@ -1,4 +1,3 @@
-.\" $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga.man,v 1.7 2003/04/03 07:11:03 herrb Exp $ 
 .\" shorthand for double quote that works everywhere.
 .ds q \N'34'
 .TH mga __drivermansuffix__ __vendorversion__
diff --git a/src/binding.h b/src/binding.h
index 6dcd1e9..57e9b92 100644
--- a/src/binding.h
+++ b/src/binding.h
@@ -13,7 +13,6 @@
  @end
 
 ***************************************************************************************/
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/HALlib/binding.h,v 1.3 2000/10/24 22:45:08 dawes Exp $ */
 
 #ifndef _BINDING
 #define _BINDING
diff --git a/src/mga.h b/src/mga.h
index 2cb3d88..c520e86 100644
--- a/src/mga.h
+++ b/src/mga.h
@@ -1,4 +1,3 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga.h,v 1.87tsi Exp $ */
 /*
  * MGA Millennium (MGA2064W) functions
  *
@@ -137,6 +136,10 @@ void MGAdbg_outreg32(ScrnInfoPtr, int,int, char*);
 #define PCI_CHIP_MGAG200_EH_PCI 0x0533
 #endif
 
+#ifndef PCI_CHIP_MGAG200_ER_PCI
+#define PCI_CHIP_MGAG200_ER_PCI 0x0534
+#endif
+
 /*
  * Read/write to the DAC via MMIO 
  */
@@ -200,7 +203,9 @@ void MGAdbg_outreg32(ScrnInfoPtr, int,int, char*);
 typedef struct {
     unsigned char	ExtVga[6];
     unsigned char 	DacClk[6];
-    unsigned char *     DacRegs;
+    unsigned char	ExtVga_Index24;
+    unsigned char	Dac_Index90;
+    unsigned char * DacRegs;
     unsigned long	crtc2[0x58];
     unsigned char	dac2[0x21];
     CARD32		Option;
@@ -479,6 +484,7 @@ typedef struct {
     int is_G200WB:1;
     int is_G200EV:1;
     int is_G200EH:1;
+    int is_G200ER:1;
 
     int KVM;
 
diff --git a/src/mga_common.h b/src/mga_common.h
index 90f6b37..81be2bc 100644
--- a/src/mga_common.h
+++ b/src/mga_common.h
@@ -25,8 +25,6 @@
  * Converted to common header format:
  *   Jens Owen <jens@tungstengraphics.com>
  *
- * $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_common.h,v 1.2 2002/12/16 16:19:18 dawes Exp $
- *
  */
 
 #ifndef _MGA_COMMON_H_
diff --git a/src/mga_dacG.c b/src/mga_dacG.c
index df00765..fca1031 100644
--- a/src/mga_dacG.c
+++ b/src/mga_dacG.c
@@ -444,6 +444,116 @@ MGAG200WBPIXPLLSET(ScrnInfoPtr pScrn, MGARegPtr mgaReg)
     outMGAdac(MGA1064_REMHEADCTL, ucTempByte);
 }
 
+#define G200ER_PLLREF 48000
+#define G200ER_VCOMIN 1056000
+#define G200ER_VCOMAX 1488000
+
+static void MGAG200ERComputePLLParam(ScrnInfoPtr pScrn, long lFo, int *piM, int *piN, int *piP)
+{
+
+    int  ulM;
+    int  ulN;
+    int  ulO;
+    int  ulR;
+
+    CARD32 ulComputedFo;
+    CARD32 ulVco;
+    CARD32 ulFDelta;
+    CARD32 ulFTmpDelta;
+
+    CARD32 aulMDivValue[] = {1, 2, 4, 8};
+
+    CARD32 ulFo   = lFo;
+
+    ulFDelta = 0xFFFFFFFF;
+
+    for (ulR = 0; ulR < 4;  ulR++)
+    {
+    	if(ulFDelta==0) break;
+        for (ulN = 5; (ulN <= 128) ; ulN++)
+        {
+            if(ulFDelta==0) break;
+            for (ulM = 3; ulM >= 0; ulM--)
+            {
+            	if(ulFDelta==0) break;
+                for (ulO = 5; ulO <= 32; ulO++)
+                {
+                	ulVco = (G200ER_PLLREF * (ulN+1)) / (ulR+1);
+                	// Validate vco
+                    if (ulVco < G200ER_VCOMIN) continue;
+					if (ulVco > G200ER_VCOMAX) continue;
+                	ulComputedFo = ulVco / (aulMDivValue[ulM] * (ulO+1));
+
+                    if (ulComputedFo > ulFo)
+                    {
+                        ulFTmpDelta = ulComputedFo - ulFo;
+                    }
+                    else
+                    {
+                        ulFTmpDelta = ulFo - ulComputedFo;
+                    }
+
+                    if (ulFTmpDelta < ulFDelta)
+                    {
+                        ulFDelta = ulFTmpDelta;
+                        // XG200ERPIXPLLCM M<1:0> O<7:3>
+                        *piM = (CARD8)ulM | (CARD8)(ulO<<3);
+                        //
+                        // XG200ERPIXPLLCN N<6:0>
+                        *piN = (CARD8)ulN;
+                        //
+                        // XG200ERPIXPLLCP R<1:0> cg<7:4> (Use R value)
+                        *piP = (CARD8)ulR | (CARD8)(ulR<<3);
+
+                        // Test
+                        int ftest = (G200ER_PLLREF * (ulN+1)) / ((ulR+1) * aulMDivValue[ulM] * (ulO+1));
+                        ftest=ftest;
+                    }
+                } // End O Loop
+            } // End M Loop
+        } // End N Loop
+    } // End R Loop
+}
+
+static void
+MGAG200ERPIXPLLSET(ScrnInfoPtr pScrn, MGARegPtr mgaReg)
+{
+    //TODO  G200ER Validate sequence 
+    CARD8 ucPixCtrl, ucTempByte;
+    MGAPtr pMga = MGAPTR(pScrn);
+
+
+    // Set pixclkdis to 1
+    ucPixCtrl = inMGAdac(MGA1064_PIX_CLK_CTL);
+    ucPixCtrl |= MGA1064_PIX_CLK_CTL_CLK_DIS;
+    outMGAdac(MGA1064_PIX_CLK_CTL, ucPixCtrl);
+
+    ucTempByte = inMGAdac(MGA1064_REMHEADCTL);
+    ucTempByte |= MGA1064_REMHEADCTL_CLKDIS;
+    outMGAdac(MGA1064_REMHEADCTL, ucTempByte);
+
+    // Select PLL Set C
+    ucTempByte = INREG8(MGAREG_MEM_MISC_READ);
+    ucTempByte |= (0x3<<2) | 0xc0; //select MGA pixel clock
+    OUTREG8(MGAREG_MEM_MISC_WRITE, ucTempByte);
+
+    ucPixCtrl &= ~MGA1064_PIX_CLK_CTL_CLK_DIS;
+    ucPixCtrl |= MGA1064_PIX_CLK_CTL_CLK_POW_DOWN;
+    outMGAdac(MGA1064_PIX_CLK_CTL, ucPixCtrl);
+
+    // Wait 500 us
+    usleep(500);
+
+    // Program the Pixel PLL Register
+    outMGAdac(MGA1064_ER_PIX_PLLC_N, mgaReg->PllN);
+    outMGAdac(MGA1064_ER_PIX_PLLC_M, mgaReg->PllM);
+    outMGAdac(MGA1064_ER_PIX_PLLC_P, mgaReg->PllP);
+
+        // Wait 50 us
+    usleep(50);
+
+}
+
 static void
 MGAG200WBPrepareForModeSwitch(ScrnInfoPtr pScrn)
 {
@@ -768,8 +878,13 @@ MGAGSetPCLK( ScrnInfoPtr pScrn, long f_out )
 
 	    pReg->PllM = m;
 	    pReg->PllN = n;
-	    pReg->PllP = p;
-        } else {
+	    pReg->PllP = p;		
+	} else if (pMga->is_G200ER) {
+	    MGAG200ERComputePLLParam(pScrn, f_out, &m, &n, &p);
+	    pReg->PllM = m;
+	    pReg->PllN = n;
+	    pReg->PllP = p;		
+    } else {
 	    /* Do the calculations for m, n, p and s */
 	    MGAGCalcClock( pScrn, f_out, &m, &n, &p, &s );
 
@@ -966,6 +1081,10 @@ MGAGInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
                 pReg->Option2 = 0x0000b000;
                 break;
 
+		case PCI_CHIP_MGAG200_ER_PCI:
+			pReg->Dac_Index90 = 0;
+			break;
+
         case PCI_CHIP_MGAG200_EH_PCI:
                 pReg->DacRegs[MGA1064_MISC_CTL] =
                     MGA1064_MISC_CTL_VGA8 |
@@ -1088,6 +1207,7 @@ MGAGInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
         if (pMga->is_G200WB){
             pReg->ExtVga[1] |= 0x88;
         }
+	pReg->ExtVga_Index24 = 0x05;
 		
 	pVga->CRTC[0]	= ht - 4;
 	pVga->CRTC[1]	= hd;
@@ -1327,10 +1447,15 @@ MGA_NOT_HAL(
 	      if ( (pMga->is_G200EV || pMga->is_G200WB || pMga->is_G200EH) &&
 		   (i >= 0x44) && (i <= 0x4E))
 	         continue;
-
+			 
 	      outMGAdac(i, mgaReg->DacRegs[i]);
 	   }
 	   
+		if (pMga->is_G200ER)
+        {
+			outMGAdac(0x90, mgaReg->Dac_Index90);
+        }
+   
 	   if (!MGAISGx50(pMga)) {
 	       /* restore pci_option register */
 #ifdef XSERVER_LIBPCIACCESS
@@ -1361,7 +1486,9 @@ MGA_NOT_HAL(
 #endif
 	   }
 
-           if (pMga->is_G200EV) {
+           if (pMga->is_G200ER) {
+               MGAG200ERPIXPLLSET(pScrn, mgaReg);               
+           } else  if (pMga->is_G200EV) {
                MGAG200EVPIXPLLSET(pScrn, mgaReg);
            } else if (pMga->is_G200WB) {
                MGAG200WBPIXPLLSET(pScrn, mgaReg);
@@ -1388,6 +1515,11 @@ MGA_NOT_HAL(
            for (i = 0; i < 6; i++)
 	      OUTREG16(MGAREG_CRTCEXT_INDEX, (mgaReg->ExtVga[i] << 8) | i);
 
+           if (pMga->is_G200ER) {
+               OUTREG8(MGAREG_CRTCEXT_INDEX, 0x24);
+               OUTREG8(MGAREG_CRTCEXT_DATA,  mgaReg->ExtVga_Index24);			   
+           }
+
 	   /* This handles restoring the generic VGA registers. */
 	   if (pMga->is_G200SE) {
  	      MGAG200SERestoreMode(pScrn, vgaReg);
@@ -1404,7 +1536,7 @@ MGA_NOT_HAL(
                OUTREG16(MGAREG_CRTCEXT_INDEX, 6);
                OUTREG16(MGAREG_CRTCEXT_DATA, 0);
            }
-
+		   
 	   /*
 	    * this is needed to properly restore start address
 	    */
@@ -1555,6 +1687,11 @@ MGAGSave(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, MGARegPtr mgaReg,
             mgaReg->PllM = inMGAdac(MGA1064_EH_PIX_PLLC_M);
             mgaReg->PllN = inMGAdac(MGA1064_EH_PIX_PLLC_N);
             mgaReg->PllP = inMGAdac(MGA1064_EH_PIX_PLLC_P);
+        } else if (pMga->is_G200ER) {
+            mgaReg->PllM = inMGAdac(MGA1064_ER_PIX_PLLC_M);
+            mgaReg->PllN = inMGAdac(MGA1064_ER_PIX_PLLC_N);
+            mgaReg->PllP = inMGAdac(MGA1064_ER_PIX_PLLC_P);
+            mgaReg->Dac_Index90 = inMGAdac(0x90);
         }
 
         mgaReg->PIXPLLCSaved = TRUE;
@@ -1583,6 +1720,11 @@ MGAGSave(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, MGARegPtr mgaReg,
 		OUTREG8(MGAREG_CRTCEXT_INDEX, i);
 		mgaReg->ExtVga[i] = INREG8(MGAREG_CRTCEXT_DATA);
 	}
+	if (pMga->is_G200ER)
+	{
+		OUTREG8(MGAREG_CRTCEXT_INDEX, 0x24);
+		mgaReg->ExtVga_Index24 = INREG8(MGAREG_CRTCEXT_DATA);
+	}
 
 #ifdef DEBUG		
 	ErrorF("Saved values:\nDAC:");
@@ -1737,7 +1879,7 @@ static const struct mgag_i2c_private {
     { (1 << 0), (1 << 2) },
     { (1 << 4), (1 << 5) },
     { (1 << 0), (1 << 1) },  /* G200SE, G200EV and G200WB I2C bits */
-    { (1 << 1), (1 << 0) },  /* G200EH I2C bits */
+    { (1 << 1), (1 << 0) },  /* G200EH, G200ER I2C bits */
 };
 
 
@@ -1750,7 +1892,7 @@ MGAG_ddc1Read(ScrnInfoPtr pScrn)
 
   if (pMga->is_G200SE || pMga->is_G200WB || pMga->is_G200EV)
     i2c_index = 3;
-  else if (pMga->is_G200EH)
+  else if (pMga->is_G200EH || pMga->is_G200ER)
     i2c_index = 4;
   else
     i2c_index = 0;
@@ -1851,7 +1993,7 @@ MGAG_i2cInit(ScrnInfoPtr pScrn)
 
         if (pMga->is_G200SE || pMga->is_G200WB || pMga->is_G200EV)
             i2c_index = 3;
-        else if (pMga->is_G200EH)
+        else if (pMga->is_G200EH || pMga->is_G200ER)
             i2c_index = 4;
         else
             i2c_index = 0;
@@ -1976,7 +2118,7 @@ void MGAGSetupFuncs(ScrnInfoPtr pScrn)
     pMga->Save = MGAGSave;
     pMga->Restore = MGAGRestore;
     pMga->ModeInit = MGAGInit;
-    if (!pMga->is_G200WB){
+    if ((!pMga->is_G200WB) && (!pMga->is_G200ER)) {
         pMga->ddc1Read = MGAG_ddc1Read;
         /* vgaHWddc1SetSpeed will only work if the card is in VGA mode */
         pMga->DDC1SetSpeed = vgaHWddc1SetSpeedWeak();
diff --git a/src/mga_dri.c b/src/mga_dri.c
index 3fda623..14f342f 100644
--- a/src/mga_dri.c
+++ b/src/mga_dri.c
@@ -32,7 +32,6 @@
 
 #include "xf86.h"
 #include "xf86_OSproc.h"
-#include "xf86Priv.h"
 
 #include "xf86PciInfo.h"
 #include "xf86Pci.h"
diff --git a/src/mga_dri.h b/src/mga_dri.h
index f1afb5d..1984b9c 100644
--- a/src/mga_dri.h
+++ b/src/mga_dri.h
@@ -1,5 +1,3 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.h,v 1.6 2001/04/10 16:08:01 dawes Exp $ */
-
 /*
  * Copyright 2000 VA Linux Systems Inc., Fremont, California.
  * All Rights Reserved.
diff --git a/src/mga_dripriv.h b/src/mga_dripriv.h
index 3ddd133..feca134 100644
--- a/src/mga_dripriv.h
+++ b/src/mga_dripriv.h
@@ -1,5 +1,3 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dripriv.h,v 1.4 2001/04/10 16:08:01 dawes Exp $ */
-
 /*
  * Copyright 2000 VA Linux Systems Inc., Fremont, California.
  * All Rights Reserved.
diff --git a/src/mga_driver.c b/src/mga_driver.c
index 5a1e9b4..b140013 100644
--- a/src/mga_driver.c
+++ b/src/mga_driver.c
@@ -1,4 +1,3 @@
-/* $XConsortium: mga_driver.c /main/12 1996/10/28 05:13:26 kaleb $ */
 /*
  * MGA Millennium (MGA2064W) with Ti3026 RAMDAC driver v.1.1
  *
@@ -404,6 +403,21 @@ static const struct mga_device_attributes attribs[] = {
 	8192, 0x4000,          /* Memory probe size & offset values */
     },
 
+    /* G200ER */
+    [15] = { 0, 1, 0, 0, 1, 0, 0, 0, new_BARs,
+            (TRANSC_SOLID_FILL | TWO_PASS_COLOR_EXPAND | USE_LINEAR_EXPANSION),
+	{
+	    { 50000, 230000 }, /* System VCO frequencies */
+	    { 50000, 203400 }, /* Pixel VCO frequencies */
+	    { 0, 0 },          /* Video VCO frequencies */
+	    45000,            /* Memory clock */
+	    27050,             /* PLL reference frequency */
+	    0,                 /* Supports fast bitblt? */
+	    MGA_HOST_PCI       /* Host interface */
+	},
+
+	16384, 0x4000,          /* Memory probe size & offset values */
+    }
 };
 
 #ifdef XSERVER_LIBPCIACCESS
@@ -433,6 +447,8 @@ static const struct pci_id_match mga_device_match[] = {
 
     MGA_DEVICE_MATCH( PCI_CHIP_MGAG200_EH_PCI, 14 ),
 
+	MGA_DEVICE_MATCH(PCI_CHIP_MGAG200_ER_PCI, 15 ),
+
     { 0, 0, 0 },
 };
 #endif
@@ -450,6 +466,7 @@ static SymTabRec MGAChipsets[] = {
     { PCI_CHIP_MGAG200_SE_A_PCI,	"mgag200 SE A PCI" },
     { PCI_CHIP_MGAG200_SE_B_PCI,	"mgag200 SE B PCI" },
     { PCI_CHIP_MGAG200_EV_PCI,	"mgag200 EV Maxim" },
+    { PCI_CHIP_MGAG200_ER_PCI,	"mgag200 ER SH7757" },	
     { PCI_CHIP_MGAG200_WINBOND_PCI,	"mgag200 eW Nuvoton" },
     { PCI_CHIP_MGAG200_EH_PCI,	"mgag200eH" },
     { PCI_CHIP_MGAG400,		"mgag400" },
@@ -472,6 +489,8 @@ static PciChipsets MGAPciChipsets[] = {
 	RES_SHARED_VGA },
     { PCI_CHIP_MGAG200_EV_PCI, PCI_CHIP_MGAG200_EV_PCI,
 	RES_SHARED_VGA },
+    { PCI_CHIP_MGAG200_ER_PCI, PCI_CHIP_MGAG200_ER_PCI,
+	RES_SHARED_VGA },
     { PCI_CHIP_MGAG200_WINBOND_PCI, PCI_CHIP_MGAG200_WINBOND_PCI,
 	RES_SHARED_VGA },
     { PCI_CHIP_MGAG200_EH_PCI, PCI_CHIP_MGAG200_EH_PCI,
@@ -913,6 +932,11 @@ MGAProbe(DriverPtr drv, int flags)
             case PCI_CHIP_MGAG200_EH_PCI:
                 attrib_no = 14;
                 break;
+				
+            case PCI_CHIP_MGAG200_ER_PCI:
+                attrib_no = 15;
+                break;
+				
 
 	    default:
 		return FALSE;
@@ -1081,7 +1105,7 @@ MGACountRam(ScrnInfoPtr pScrn)
 
 	if (pMga->is_G200SE)
 	    pMga->reg_1e24 = INREG(0x1e24); /* stash the model for later */
-	if (pMga->reg_1e24 == 0x01) {
+	if (pMga->reg_1e24 >= 0x01) {
 	    MGAUnmapMem(pScrn);
 	    ProbeSize = 16384;
 	    ProbeSizeOffset = 0x10000;
@@ -1286,6 +1310,11 @@ MGAdoDDC(ScrnInfoPtr pScrn)
     MGASave(pScrn);
 
     /* It is now safe to talk to the card */
+    /* Allow access to DDC */
+    if (pMga->is_G200ER) {
+	 CARD8 ucData = inMGAdac(MGA1064_GEN_IO_CTL2);
+     outMGAdac(MGA1064_GEN_IO_CTL2, ucData | 1);        
+    }
 
     /* Initialize I2C buses - used by DDC if available */
     if (pMga->i2cInit) {
@@ -1327,6 +1356,12 @@ MGAdoDDC(ScrnInfoPtr pScrn)
 	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "end of monitor info\n");
     }
 
+    /* Remove access to DDC */
+    if (pMga->is_G200ER) {
+	  CARD8 ucData = inMGAdac(MGA1064_GEN_IO_CTL2);
+      outMGAdac(MGA1064_GEN_IO_CTL2, ucData & ~1);        
+    }
+
     /* Restore previous state and unmap MGA memory and MMIO areas */
     MGARestore(pScrn);
     MGAUnmapMem(pScrn);
@@ -1620,6 +1655,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
     pMga->is_G200EV = (pMga->Chipset == PCI_CHIP_MGAG200_EV_PCI);
     pMga->is_G200WB = (pMga->Chipset == PCI_CHIP_MGAG200_WINBOND_PCI);
     pMga->is_G200EH = (pMga->Chipset == PCI_CHIP_MGAG200_EH_PCI);
+    pMga->is_G200ER = (pMga->Chipset == PCI_CHIP_MGAG200_ER_PCI);
 
 #ifdef USEMGAHAL
     if (pMga->chip_attribs->HAL_chipset) {
@@ -1780,15 +1816,9 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
 #ifndef XSERVER_LIBPCIACCESS
     /*
      * Find the BIOS base.  Get it from the PCI config if possible.  Otherwise
-     * use the VGA default.  Allow the config file to override this.
+     * use the VGA default.
      */
 
-    pMga->BiosFrom = X_NONE;
-    if (pMga->device->BiosBase != 0) {
-	/* XXX This isn't used */
-	pMga->BiosAddress = pMga->device->BiosBase;
-	pMga->BiosFrom = X_CONFIG;
-    } else {
 	/* details: rombase sdk pp 4-15 */
 	if (pMga->PciInfo->biosBase != 0) {
 	    pMga->BiosAddress = pMga->PciInfo->biosBase & 0xffff0000;
@@ -1797,7 +1827,6 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
 	    pMga->BiosAddress = 0xc0000;
 	    pMga->BiosFrom = X_DEFAULT;
 	}
-    }
     if (pMga->BiosAddress) {
 	xf86DrvMsg(pScrn->scrnIndex, pMga->BiosFrom, "BIOS at 0x%lX\n",
 		   (unsigned long)pMga->BiosAddress);
@@ -2142,6 +2171,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
     case PCI_CHIP_MGAG200_WINBOND_PCI:
     case PCI_CHIP_MGAG200_EV_PCI:
     case PCI_CHIP_MGAG200_EH_PCI:
+    case PCI_CHIP_MGAG200_ER_PCI:	
     case PCI_CHIP_MGAG400:
     case PCI_CHIP_MGAG550:
 	MGAGSetupFuncs(pScrn);
@@ -2255,6 +2285,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
           case PCI_CHIP_MGAG200_WINBOND_PCI:
 	  case PCI_CHIP_MGAG200_EV_PCI:
       case PCI_CHIP_MGAG200_EH_PCI:
+	  case PCI_CHIP_MGAG200_ER_PCI:	  
 	    pMga->SrcOrg = 0;
 	    pMga->DstOrg = 0;
 	    break;
@@ -2432,16 +2463,17 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
 	   maxPitch = 2048;
 	   break;
 	case PCI_CHIP_MGAG200_SE_A_PCI:
-	   if (pScrn->videoRam < 2048){
+           if (pScrn->videoRam < 2048){
                maxPitch = 1280;
-	   }
-	   break;
+           }
+           break;
 	case PCI_CHIP_MGAG200:
 	case PCI_CHIP_MGAG200_PCI:
 	case PCI_CHIP_MGAG200_SE_B_PCI:
         case PCI_CHIP_MGAG200_WINBOND_PCI:
 	case PCI_CHIP_MGAG200_EV_PCI:
     case PCI_CHIP_MGAG200_EH_PCI:
+	case PCI_CHIP_MGAG200_ER_PCI:	
 	case PCI_CHIP_MGAG400:
 	case PCI_CHIP_MGAG550:
 	   maxPitch = 4096;
@@ -3250,15 +3282,71 @@ MGA_HAL(
 	    outb(0xfac, 0x02);
     }
 
-    MGA_NOT_HAL(
-	if (pMga->is_G200SE) {
+    /* 
+     This function optimize the Priority Request control
+     Higher HiPriLvl will reduce drawing performance
+     We need to give enough bandwith to crtc to avoid visual artifact
+    */
+	if (pMga->is_G200SE) 
+    {
+        if (pMga->reg_1e24 >= 0x02)
+        {
+            /* Calulate CRTC Priority value */
+            CARD8  ucHiPriLvl;
+            CARD32 ulBitsPerPixel;
+            CARD32 ulMemoryBandwidth;
+
+            /* uiBitsPerPixel can only be 8,16 or32 */
+            if (pScrn->bitsPerPixel > 16)
+            {
+                ulBitsPerPixel = 32;
+            }
+            else if (pScrn->bitsPerPixel >  8) 
+            {
+                ulBitsPerPixel = 16;
+            }
+            else 
+            {
+                ulBitsPerPixel = 8;
+            }
+
+            
+            ulMemoryBandwidth = (mode->Clock * ulBitsPerPixel) / 1000;
+
+            if      (ulMemoryBandwidth    > 3100)  ucHiPriLvl = 0;
+            else if (ulMemoryBandwidth    > 2600)  ucHiPriLvl = 1;
+            else if (ulMemoryBandwidth    > 1900)  ucHiPriLvl = 2;
+            else if (ulMemoryBandwidth    > 1160)  ucHiPriLvl = 3;
+            else if (ulMemoryBandwidth    > 440)   ucHiPriLvl = 4;
+            else ucHiPriLvl = 5;
+
             OUTREG8(0x1FDE, 0x06);
-	    if (pMga->reg_1e24 == 0x01)
-		OUTREG8(0x1FDF, 0x03);
-	    else 
-		OUTREG8(0x1FDF, 0x14);
+		    OUTREG8(0x1FDF, ucHiPriLvl);
+
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Clock           == %d\n",   mode->Clock);
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO, "BitsPerPixel    == %d\n",   pScrn->bitsPerPixel);
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO, "MemoryBandwidth == %d\n",   ulMemoryBandwidth);
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO, "HiPriLvl        == %02X\n", ucHiPriLvl);
         }
-    );
+        else
+        {
+            MGA_NOT_HAL(
+                xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Clock           == %d\n",   mode->Clock);
+                xf86DrvMsg(pScrn->scrnIndex, X_INFO, "BitsPerPixel    == %d\n",   pScrn->bitsPerPixel);
+                OUTREG8(0x1FDE, 0x06);
+	            if (pMga->reg_1e24 >= 0x01)
+                {
+		            OUTREG8(0x1FDF, 0x03);
+                    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "HiPriLvl        == 03\n");
+                }
+	            else 
+                {
+		            OUTREG8(0x1FDF, 0x14);
+                    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "HiPriLvl        == 14h\n");
+                }
+            );
+        }
+    }
 
     pMga->CurrentLayout.mode = mode;
 
@@ -4322,13 +4410,23 @@ MGAValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
     MGAPtr pMga = MGAPTR(pScrn);
 
     if (pMga->Chipset == PCI_CHIP_MGAG200_SE_A_PCI) {
-	if (mode->HDisplay > 1600)
-	    return MODE_VIRTUAL_X;
-	if (mode->VDisplay > 1200)
-	    return MODE_VIRTUAL_Y;
-	if (pMga->reg_1e24 == 0x01 &&
-	    xf86ModeBandwidth(mode, pScrn->bitsPerPixel) > 244)
-	    return MODE_BANDWIDTH;
+    	if (pMga->reg_1e24 == 0x01) {
+	        if (mode->HDisplay > 1600)
+	            return MODE_VIRTUAL_X;
+	        if (mode->VDisplay > 1200)
+	            return MODE_VIRTUAL_Y;
+	        if (xf86ModeBandwidth(mode, pScrn->bitsPerPixel) > 244)
+	            return MODE_BANDWIDTH;
+        } else {
+            if (pMga->reg_1e24 >= 0x02) {
+	            if (mode->HDisplay > 1920)
+	                return MODE_VIRTUAL_X;
+	            if (mode->VDisplay > 1200)
+	                return MODE_VIRTUAL_Y;
+	            if (xf86ModeBandwidth(mode, pScrn->bitsPerPixel) > 301)
+	                return MODE_BANDWIDTH;
+            }
+        }
     } else if (pMga->is_G200WB){
         if (mode->Flags & V_DBLSCAN)
             return MODE_NO_DBLESCAN;
@@ -4340,10 +4438,13 @@ MGAValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
 	    return MODE_BANDWIDTH;
     } else if (pMga->is_G200EV
 	       && (xf86ModeBandwidth(mode, pScrn->bitsPerPixel) > 327)) {
-        return MODE_BANDWIDTH;
+	return MODE_BANDWIDTH;
     } else if (pMga->is_G200EH
                && (xf86ModeBandwidth(mode, pScrn->bitsPerPixel) > 375)) {
         return MODE_BANDWIDTH;
+    } else if (pMga->is_G200ER
+               && (xf86ModeBandwidth(mode, pScrn->bitsPerPixel) > 550)) {
+        return MODE_BANDWIDTH;
     }
 
     lace = 1 + ((mode->Flags & V_INTERLACE) != 0);
diff --git a/src/mga_macros.h b/src/mga_macros.h
index 69dc8e3..bffd063 100644
--- a/src/mga_macros.h
+++ b/src/mga_macros.h
@@ -1,5 +1,3 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_macros.h,v 1.21 2001/09/26 12:59:17 alanh Exp $ */
-
 #ifndef _MGA_MACROS_H_
 #define _MGA_MACROS_H_
 
diff --git a/src/mga_merge.c b/src/mga_merge.c
index 753f752..1fd0572 100644
--- a/src/mga_merge.c
+++ b/src/mga_merge.c
@@ -363,6 +363,7 @@ MGAPreInitMergedFB(ScrnInfoPtr pScrn1, int flags)
     case PCI_CHIP_MGAG200_WINBOND_PCI:
     case PCI_CHIP_MGAG200_EV_PCI:
     case PCI_CHIP_MGAG200_EH_PCI:
+	case PCI_CHIP_MGAG200_ER_PCI:
     case PCI_CHIP_MGAG400:
     case PCI_CHIP_MGAG550:
 	MGAGSetupFuncs(pScrn);
@@ -518,6 +519,7 @@ MGAPreInitMergedFB(ScrnInfoPtr pScrn1, int flags)
         case PCI_CHIP_MGAG200_WINBOND_PCI:
         case PCI_CHIP_MGAG200_EV_PCI:
         case PCI_CHIP_MGAG200_EH_PCI:
+	case PCI_CHIP_MGAG200_ER_PCI:		
 	case PCI_CHIP_MGAG400:
 	case PCI_CHIP_MGAG550:
 	   maxPitch = 4096;
diff --git a/src/mga_reg.h b/src/mga_reg.h
index 6251976..5a37db6 100644
--- a/src/mga_reg.h
+++ b/src/mga_reg.h
@@ -1,11 +1,3 @@
-/* $XConsortium: mgareg.h /main/2 1996/10/25 10:33:21 kaleb $ */
-
-
-
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_reg.h,v 1.18 2001/09/26 12:59:18 alanh Exp $ */
-
-
-
 /*
  * MGA Millennium (MGA2064W) functions
  * MGA Mystique (MGA1064SG) functions
@@ -377,6 +369,7 @@
 #define MGA1064_MISC_CTL_VGA8   		( 0x01 << 3 )
 #define MGA1064_MISC_CTL_DAC_RAM_CS   		( 0x01 << 4 )
 
+#define MGA1064_GEN_IO_CTL2	0x29
 #define MGA1064_GEN_IO_CTL	0x2a
 #define MGA1064_GEN_IO_DATA	0x2b
 #define MGA1064_SYS_PLL_M	0x2c
@@ -437,6 +430,10 @@
 #define MGA1064_EH_PIX_PLLC_N   0xb7
 #define MGA1064_EH_PIX_PLLC_P   0xb8
 
+/* Modified PLL for G200 Maxim (G200ER) */
+#define MGA1064_ER_PIX_PLLC_M	0xb7
+#define MGA1064_ER_PIX_PLLC_N	0xb6
+#define MGA1064_ER_PIX_PLLC_P	0xb8
 
 #define MGA1064_DISP_CTL        0x8a
 #define MGA1064_DISP_CTL_DAC1OUTSEL_MASK       0x01
diff --git a/src/mga_sarea.h b/src/mga_sarea.h
index c5ffbbc..16fc9ce 100644
--- a/src/mga_sarea.h
+++ b/src/mga_sarea.h
@@ -1,5 +1,3 @@
-/* $XFree86$ */
-
 /*
  * Copyright 2000 Gareth Hughes
  * All Rights Reserved.
diff --git a/src/mga_storm.c b/src/mga_storm.c
index 87473c8..db7fae7 100644
--- a/src/mga_storm.c
+++ b/src/mga_storm.c
@@ -1131,6 +1131,7 @@ void MGAStormEngineInit( ScrnInfoPtr pScrn )
     case PCI_CHIP_MGAG200_WINBOND_PCI:
     case PCI_CHIP_MGAG200_EV_PCI:
     case PCI_CHIP_MGAG200_EH_PCI:
+    case PCI_CHIP_MGAG200_ER_PCI:	
 	pMga->SrcOrg = 0;
 	OUTREG(MGAREG_SRCORG, pMga->realSrcOrg);
 	OUTREG(MGAREG_DSTORG, pMga->DstOrg);
diff --git a/src/mgareg_flags.h b/src/mgareg_flags.h
index 69050fc..548af86 100644
--- a/src/mgareg_flags.h
+++ b/src/mgareg_flags.h
@@ -19,7 +19,6 @@
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mgareg_flags.h,v 1.2 2003/01/12 03:55:47 tsi Exp $ */
 
 #ifndef _MGAREGS_H_
 #define _MGAREGS_H_
diff --git a/util/stormdwg.c b/util/stormdwg.c
index 99f76cc..b43cc32 100644
--- a/util/stormdwg.c
+++ b/util/stormdwg.c
@@ -1,8 +1,3 @@
-/* $XConsortium: dwg.c /main/2 1996/10/28 06:57:55 kaleb $ */
-
-
-
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/util/stormdwg.c,v 1.1 1997/04/12 14:11:29 hohndel Exp $ */
 
 #include <stdio.h>
 #include <stdlib.h>