1 #include <linux/delay.h>
2 #include <linux/vmalloc.h>
7 #include "vb_setmode.h"
9 static const unsigned short XGINew_DDRDRAM_TYPE340
[4][2] = {
15 static const unsigned short XGINew_DDRDRAM_TYPE20
[12][2] = {
29 #define XGIFB_ROM_SIZE 65536
32 XGINew_GetXG20DRAMType(struct xgi_hw_device_info
*HwDeviceExtension
,
33 struct vb_device_info
*pVBInfo
)
35 unsigned char data
, temp
;
37 if (HwDeviceExtension
->jChipType
< XG20
) {
38 data
= xgifb_reg_get(pVBInfo
->P3c4
, 0x39) & 0x02;
40 data
= (xgifb_reg_get(pVBInfo
->P3c4
, 0x3A) &
43 } else if (HwDeviceExtension
->jChipType
== XG27
) {
44 temp
= xgifb_reg_get(pVBInfo
->P3c4
, 0x3B);
45 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
46 if (((temp
& 0x88) == 0x80) || ((temp
& 0x88) == 0x08))
51 } else if (HwDeviceExtension
->jChipType
== XG21
) {
52 /* Independent GPIO control */
53 xgifb_reg_and(pVBInfo
->P3d4
, 0xB4, ~0x02);
55 xgifb_reg_or(pVBInfo
->P3d4
, 0x4A, 0x80); /* Enable GPIOH read */
56 /* GPIOF 0:DVI 1:DVO */
57 temp
= xgifb_reg_get(pVBInfo
->P3d4
, 0x48);
59 /* for current XG20 & XG21, GPIOH is floating, driver will
60 * fix DDR temporarily */
61 if (temp
& 0x01) /* DVI read GPIOH */
65 /* ~HOTPLUG_SUPPORT */
66 xgifb_reg_or(pVBInfo
->P3d4
, 0xB4, 0x02);
69 data
= xgifb_reg_get(pVBInfo
->P3d4
, 0x97) & 0x01;
78 static void XGINew_DDR1x_MRS_340(unsigned long P3c4
,
79 struct vb_device_info
*pVBInfo
)
81 xgifb_reg_set(P3c4
, 0x18, 0x01);
82 xgifb_reg_set(P3c4
, 0x19, 0x20);
83 xgifb_reg_set(P3c4
, 0x16, 0x00);
84 xgifb_reg_set(P3c4
, 0x16, 0x80);
87 xgifb_reg_set(P3c4
, 0x18, 0x00);
88 xgifb_reg_set(P3c4
, 0x19, 0x20);
89 xgifb_reg_set(P3c4
, 0x16, 0x00);
90 xgifb_reg_set(P3c4
, 0x16, 0x80);
95 pVBInfo
->SR15
[2][pVBInfo
->ram_type
]); /* SR18 */
96 xgifb_reg_set(P3c4
, 0x19, 0x01);
97 xgifb_reg_set(P3c4
, 0x16, pVBInfo
->SR16
[0]);
98 xgifb_reg_set(P3c4
, 0x16, pVBInfo
->SR16
[1]);
100 xgifb_reg_set(P3c4
, 0x1B, 0x03);
104 pVBInfo
->SR15
[2][pVBInfo
->ram_type
]); /* SR18 */
105 xgifb_reg_set(P3c4
, 0x19, 0x00);
106 xgifb_reg_set(P3c4
, 0x16, pVBInfo
->SR16
[2]);
107 xgifb_reg_set(P3c4
, 0x16, pVBInfo
->SR16
[3]);
108 xgifb_reg_set(P3c4
, 0x1B, 0x00);
111 static void XGINew_SetMemoryClock(struct xgi_hw_device_info
*HwDeviceExtension
,
112 struct vb_device_info
*pVBInfo
)
115 xgifb_reg_set(pVBInfo
->P3c4
,
117 pVBInfo
->MCLKData
[pVBInfo
->ram_type
].SR28
);
118 xgifb_reg_set(pVBInfo
->P3c4
,
120 pVBInfo
->MCLKData
[pVBInfo
->ram_type
].SR29
);
121 xgifb_reg_set(pVBInfo
->P3c4
,
123 pVBInfo
->MCLKData
[pVBInfo
->ram_type
].SR2A
);
125 xgifb_reg_set(pVBInfo
->P3c4
,
127 pVBInfo
->ECLKData
[pVBInfo
->ram_type
].SR2E
);
128 xgifb_reg_set(pVBInfo
->P3c4
,
130 pVBInfo
->ECLKData
[pVBInfo
->ram_type
].SR2F
);
131 xgifb_reg_set(pVBInfo
->P3c4
,
133 pVBInfo
->ECLKData
[pVBInfo
->ram_type
].SR30
);
135 /* When XG42 ECLK = MCLK = 207MHz, Set SR32 D[1:0] = 10b */
136 /* Modify SR32 value, when MCLK=207MHZ, ELCK=250MHz,
137 * Set SR32 D[1:0] = 10b */
138 if (HwDeviceExtension
->jChipType
== XG42
) {
139 if ((pVBInfo
->MCLKData
[pVBInfo
->ram_type
].SR28
== 0x1C) &&
140 (pVBInfo
->MCLKData
[pVBInfo
->ram_type
].SR29
== 0x01) &&
141 (((pVBInfo
->ECLKData
[pVBInfo
->ram_type
].SR2E
== 0x1C) &&
142 (pVBInfo
->ECLKData
[pVBInfo
->ram_type
].SR2F
== 0x01)) ||
143 ((pVBInfo
->ECLKData
[pVBInfo
->ram_type
].SR2E
== 0x22) &&
144 (pVBInfo
->ECLKData
[pVBInfo
->ram_type
].SR2F
== 0x01))))
145 xgifb_reg_set(pVBInfo
->P3c4
,
147 ((unsigned char) xgifb_reg_get(
148 pVBInfo
->P3c4
, 0x32) & 0xFC) | 0x02);
152 static void XGINew_DDRII_Bootup_XG27(
153 struct xgi_hw_device_info
*HwDeviceExtension
,
154 unsigned long P3c4
, struct vb_device_info
*pVBInfo
)
156 unsigned long P3d4
= P3c4
+ 0x10;
157 pVBInfo
->ram_type
= XGINew_GetXG20DRAMType(HwDeviceExtension
, pVBInfo
);
158 XGINew_SetMemoryClock(HwDeviceExtension
, pVBInfo
);
160 /* Set Double Frequency */
161 xgifb_reg_set(P3d4
, 0x97, pVBInfo
->XGINew_CR97
); /* CR97 */
165 xgifb_reg_set(P3c4
, 0x18, 0x00); /* Set SR18 */ /* EMRS2 */
166 xgifb_reg_set(P3c4
, 0x19, 0x80); /* Set SR19 */
167 xgifb_reg_set(P3c4
, 0x16, 0x20); /* Set SR16 */
169 xgifb_reg_set(P3c4
, 0x16, 0xA0); /* Set SR16 */
172 xgifb_reg_set(P3c4
, 0x18, 0x00); /* Set SR18 */ /* EMRS3 */
173 xgifb_reg_set(P3c4
, 0x19, 0xC0); /* Set SR19 */
174 xgifb_reg_set(P3c4
, 0x16, 0x20); /* Set SR16 */
176 xgifb_reg_set(P3c4
, 0x16, 0xA0); /* Set SR16 */
179 xgifb_reg_set(P3c4
, 0x18, 0x00); /* Set SR18 */ /* EMRS1 */
180 xgifb_reg_set(P3c4
, 0x19, 0x40); /* Set SR19 */
181 xgifb_reg_set(P3c4
, 0x16, 0x20); /* Set SR16 */
183 xgifb_reg_set(P3c4
, 0x16, 0xA0); /* Set SR16 */
186 xgifb_reg_set(P3c4
, 0x18, 0x42); /* Set SR18 */ /* MRS, DLL Enable */
187 xgifb_reg_set(P3c4
, 0x19, 0x0A); /* Set SR19 */
188 xgifb_reg_set(P3c4
, 0x16, 0x00); /* Set SR16 */
190 xgifb_reg_set(P3c4
, 0x16, 0x00); /* Set SR16 */
191 xgifb_reg_set(P3c4
, 0x16, 0x80); /* Set SR16 */
193 xgifb_reg_set(P3c4
, 0x1B, 0x04); /* Set SR1B */
195 xgifb_reg_set(P3c4
, 0x1B, 0x00); /* Set SR1B */
197 xgifb_reg_set(P3c4
, 0x18, 0x42); /* Set SR18 */ /* MRS, DLL Reset */
198 xgifb_reg_set(P3c4
, 0x19, 0x08); /* Set SR19 */
199 xgifb_reg_set(P3c4
, 0x16, 0x00); /* Set SR16 */
202 xgifb_reg_set(P3c4
, 0x16, 0x83); /* Set SR16 */
205 xgifb_reg_set(P3c4
, 0x18, 0x80); /* Set SR18 */ /* MRS, ODT */
206 xgifb_reg_set(P3c4
, 0x19, 0x46); /* Set SR19 */
207 xgifb_reg_set(P3c4
, 0x16, 0x20); /* Set SR16 */
209 xgifb_reg_set(P3c4
, 0x16, 0xA0); /* Set SR16 */
212 xgifb_reg_set(P3c4
, 0x18, 0x00); /* Set SR18 */ /* EMRS */
213 xgifb_reg_set(P3c4
, 0x19, 0x40); /* Set SR19 */
214 xgifb_reg_set(P3c4
, 0x16, 0x20); /* Set SR16 */
216 xgifb_reg_set(P3c4
, 0x16, 0xA0); /* Set SR16 */
219 /* Set SR1B refresh control 000:close; 010:open */
220 xgifb_reg_set(P3c4
, 0x1B, 0x04);
225 static void XGINew_DDR2_MRS_XG20(struct xgi_hw_device_info
*HwDeviceExtension
,
226 unsigned long P3c4
, struct vb_device_info
*pVBInfo
)
228 unsigned long P3d4
= P3c4
+ 0x10;
230 pVBInfo
->ram_type
= XGINew_GetXG20DRAMType(HwDeviceExtension
, pVBInfo
);
231 XGINew_SetMemoryClock(HwDeviceExtension
, pVBInfo
);
233 xgifb_reg_set(P3d4
, 0x97, 0x11); /* CR97 */
236 xgifb_reg_set(P3c4
, 0x18, 0x00); /* EMRS2 */
237 xgifb_reg_set(P3c4
, 0x19, 0x80);
238 xgifb_reg_set(P3c4
, 0x16, 0x05);
239 xgifb_reg_set(P3c4
, 0x16, 0x85);
241 xgifb_reg_set(P3c4
, 0x18, 0x00); /* EMRS3 */
242 xgifb_reg_set(P3c4
, 0x19, 0xC0);
243 xgifb_reg_set(P3c4
, 0x16, 0x05);
244 xgifb_reg_set(P3c4
, 0x16, 0x85);
246 xgifb_reg_set(P3c4
, 0x18, 0x00); /* EMRS1 */
247 xgifb_reg_set(P3c4
, 0x19, 0x40);
248 xgifb_reg_set(P3c4
, 0x16, 0x05);
249 xgifb_reg_set(P3c4
, 0x16, 0x85);
251 xgifb_reg_set(P3c4
, 0x18, 0x42); /* MRS1 */
252 xgifb_reg_set(P3c4
, 0x19, 0x02);
253 xgifb_reg_set(P3c4
, 0x16, 0x05);
254 xgifb_reg_set(P3c4
, 0x16, 0x85);
257 xgifb_reg_set(P3c4
, 0x1B, 0x04); /* SR1B */
259 xgifb_reg_set(P3c4
, 0x1B, 0x00); /* SR1B */
262 xgifb_reg_set(P3c4
, 0x18, 0x42); /* MRS1 */
263 xgifb_reg_set(P3c4
, 0x19, 0x00);
264 xgifb_reg_set(P3c4
, 0x16, 0x05);
265 xgifb_reg_set(P3c4
, 0x16, 0x85);
270 static void XGINew_DDR1x_MRS_XG20(unsigned long P3c4
,
271 struct vb_device_info
*pVBInfo
)
273 xgifb_reg_set(P3c4
, 0x18, 0x01);
274 xgifb_reg_set(P3c4
, 0x19, 0x40);
275 xgifb_reg_set(P3c4
, 0x16, 0x00);
276 xgifb_reg_set(P3c4
, 0x16, 0x80);
279 xgifb_reg_set(P3c4
, 0x18, 0x00);
280 xgifb_reg_set(P3c4
, 0x19, 0x40);
281 xgifb_reg_set(P3c4
, 0x16, 0x00);
282 xgifb_reg_set(P3c4
, 0x16, 0x80);
286 pVBInfo
->SR15
[2][pVBInfo
->ram_type
]); /* SR18 */
287 xgifb_reg_set(P3c4
, 0x19, 0x01);
288 xgifb_reg_set(P3c4
, 0x16, 0x03);
289 xgifb_reg_set(P3c4
, 0x16, 0x83);
291 xgifb_reg_set(P3c4
, 0x1B, 0x03);
295 pVBInfo
->SR15
[2][pVBInfo
->ram_type
]); /* SR18 */
296 xgifb_reg_set(P3c4
, 0x19, 0x00);
297 xgifb_reg_set(P3c4
, 0x16, 0x03);
298 xgifb_reg_set(P3c4
, 0x16, 0x83);
299 xgifb_reg_set(P3c4
, 0x1B, 0x00);
302 static void XGINew_DDR1x_DefaultRegister(
303 struct xgi_hw_device_info
*HwDeviceExtension
,
304 unsigned long Port
, struct vb_device_info
*pVBInfo
)
306 unsigned long P3d4
= Port
, P3c4
= Port
- 0x10;
308 if (HwDeviceExtension
->jChipType
>= XG20
) {
309 XGINew_SetMemoryClock(HwDeviceExtension
, pVBInfo
);
312 pVBInfo
->CR40
[11][pVBInfo
->ram_type
]); /* CR82 */
315 pVBInfo
->CR40
[12][pVBInfo
->ram_type
]); /* CR85 */
318 pVBInfo
->CR40
[13][pVBInfo
->ram_type
]); /* CR86 */
320 xgifb_reg_set(P3d4
, 0x98, 0x01);
321 xgifb_reg_set(P3d4
, 0x9A, 0x02);
323 XGINew_DDR1x_MRS_XG20(P3c4
, pVBInfo
);
325 XGINew_SetMemoryClock(HwDeviceExtension
, pVBInfo
);
327 switch (HwDeviceExtension
->jChipType
) {
332 pVBInfo
->CR40
[11][pVBInfo
->ram_type
]);
336 pVBInfo
->CR40
[12][pVBInfo
->ram_type
]);
340 pVBInfo
->CR40
[13][pVBInfo
->ram_type
]);
343 xgifb_reg_set(P3d4
, 0x82, 0x88);
344 xgifb_reg_set(P3d4
, 0x86, 0x00);
345 /* Insert read command for delay */
346 xgifb_reg_get(P3d4
, 0x86);
347 xgifb_reg_set(P3d4
, 0x86, 0x88);
348 xgifb_reg_get(P3d4
, 0x86);
351 pVBInfo
->CR40
[13][pVBInfo
->ram_type
]);
352 xgifb_reg_set(P3d4
, 0x82, 0x77);
353 xgifb_reg_set(P3d4
, 0x85, 0x00);
355 /* Insert read command for delay */
356 xgifb_reg_get(P3d4
, 0x85);
357 xgifb_reg_set(P3d4
, 0x85, 0x88);
359 /* Insert read command for delay */
360 xgifb_reg_get(P3d4
, 0x85);
364 pVBInfo
->CR40
[12][pVBInfo
->ram_type
]);
368 pVBInfo
->CR40
[11][pVBInfo
->ram_type
]);
372 xgifb_reg_set(P3d4
, 0x97, 0x00);
373 xgifb_reg_set(P3d4
, 0x98, 0x01);
374 xgifb_reg_set(P3d4
, 0x9A, 0x02);
375 XGINew_DDR1x_MRS_340(P3c4
, pVBInfo
);
379 static void XGINew_DDR2_DefaultRegister(
380 struct xgi_hw_device_info
*HwDeviceExtension
,
381 unsigned long Port
, struct vb_device_info
*pVBInfo
)
383 unsigned long P3d4
= Port
, P3c4
= Port
- 0x10;
385 /* keep following setting sequence, each setting in
386 * the same reg insert idle */
387 xgifb_reg_set(P3d4
, 0x82, 0x77);
388 xgifb_reg_set(P3d4
, 0x86, 0x00);
389 xgifb_reg_get(P3d4
, 0x86); /* Insert read command for delay */
390 xgifb_reg_set(P3d4
, 0x86, 0x88);
391 xgifb_reg_get(P3d4
, 0x86); /* Insert read command for delay */
393 xgifb_reg_set(P3d4
, 0x86, pVBInfo
->CR40
[13][pVBInfo
->ram_type
]);
394 xgifb_reg_set(P3d4
, 0x82, 0x77);
395 xgifb_reg_set(P3d4
, 0x85, 0x00);
396 xgifb_reg_get(P3d4
, 0x85); /* Insert read command for delay */
397 xgifb_reg_set(P3d4
, 0x85, 0x88);
398 xgifb_reg_get(P3d4
, 0x85); /* Insert read command for delay */
401 pVBInfo
->CR40
[12][pVBInfo
->ram_type
]); /* CR85 */
402 if (HwDeviceExtension
->jChipType
== XG27
)
404 xgifb_reg_set(P3d4
, 0x82, pVBInfo
->CR40
[11][pVBInfo
->ram_type
]);
406 xgifb_reg_set(P3d4
, 0x82, 0xA8); /* CR82 */
408 xgifb_reg_set(P3d4
, 0x98, 0x01);
409 xgifb_reg_set(P3d4
, 0x9A, 0x02);
410 if (HwDeviceExtension
->jChipType
== XG27
)
411 XGINew_DDRII_Bootup_XG27(HwDeviceExtension
, P3c4
, pVBInfo
);
413 XGINew_DDR2_MRS_XG20(HwDeviceExtension
, P3c4
, pVBInfo
);
416 static void XGINew_SetDRAMDefaultRegister340(
417 struct xgi_hw_device_info
*HwDeviceExtension
,
418 unsigned long Port
, struct vb_device_info
*pVBInfo
)
420 unsigned char temp
, temp1
, temp2
, temp3
, i
, j
, k
;
422 unsigned long P3d4
= Port
, P3c4
= Port
- 0x10;
424 xgifb_reg_set(P3d4
, 0x6D, pVBInfo
->CR40
[8][pVBInfo
->ram_type
]);
425 xgifb_reg_set(P3d4
, 0x68, pVBInfo
->CR40
[5][pVBInfo
->ram_type
]);
426 xgifb_reg_set(P3d4
, 0x69, pVBInfo
->CR40
[6][pVBInfo
->ram_type
]);
427 xgifb_reg_set(P3d4
, 0x6A, pVBInfo
->CR40
[7][pVBInfo
->ram_type
]);
430 for (i
= 0; i
< 4; i
++) {
431 /* CR6B DQS fine tune delay */
432 temp
= pVBInfo
->CR6B
[pVBInfo
->ram_type
][i
];
433 for (j
= 0; j
< 4; j
++) {
434 temp1
= ((temp
>> (2 * j
)) & 0x03) << 2;
436 xgifb_reg_set(P3d4
, 0x6B, temp2
);
437 /* Insert read command for delay */
438 xgifb_reg_get(P3d4
, 0x6B);
445 for (i
= 0; i
< 4; i
++) {
446 /* CR6E DQM fine tune delay */
447 temp
= pVBInfo
->CR6E
[pVBInfo
->ram_type
][i
];
448 for (j
= 0; j
< 4; j
++) {
449 temp1
= ((temp
>> (2 * j
)) & 0x03) << 2;
451 xgifb_reg_set(P3d4
, 0x6E, temp2
);
452 /* Insert read command for delay */
453 xgifb_reg_get(P3d4
, 0x6E);
460 for (k
= 0; k
< 4; k
++) {
461 /* CR6E_D[1:0] select channel */
462 xgifb_reg_and_or(P3d4
, 0x6E, 0xFC, temp3
);
464 for (i
= 0; i
< 8; i
++) {
465 /* CR6F DQ fine tune delay */
466 temp
= pVBInfo
->CR6F
[pVBInfo
->ram_type
][8 * k
+ i
];
467 for (j
= 0; j
< 4; j
++) {
468 temp1
= (temp
>> (2 * j
)) & 0x03;
470 xgifb_reg_set(P3d4
, 0x6F, temp2
);
471 /* Insert read command for delay */
472 xgifb_reg_get(P3d4
, 0x6F);
482 pVBInfo
->CR40
[9][pVBInfo
->ram_type
]); /* CR80 */
485 pVBInfo
->CR40
[10][pVBInfo
->ram_type
]); /* CR81 */
488 /* CR89 terminator type select */
489 temp
= pVBInfo
->CR89
[pVBInfo
->ram_type
][0];
490 for (j
= 0; j
< 4; j
++) {
491 temp1
= (temp
>> (2 * j
)) & 0x03;
493 xgifb_reg_set(P3d4
, 0x89, temp2
);
494 xgifb_reg_get(P3d4
, 0x89); /* Insert read command for delay */
499 temp
= pVBInfo
->CR89
[pVBInfo
->ram_type
][1];
502 xgifb_reg_set(P3d4
, 0x89, temp2
);
504 temp
= pVBInfo
->CR40
[3][pVBInfo
->ram_type
];
506 temp2
= (temp
>> 4) & 0x07;
508 xgifb_reg_set(P3d4
, 0x45, temp1
); /* CR45 */
509 xgifb_reg_set(P3d4
, 0x99, temp2
); /* CR99 */
510 xgifb_reg_or(P3d4
, 0x40, temp3
); /* CR40_D[7] */
513 pVBInfo
->CR40
[0][pVBInfo
->ram_type
]); /* CR41 */
515 if (HwDeviceExtension
->jChipType
== XG27
)
516 xgifb_reg_set(P3d4
, 0x8F, XG27_CR8F
); /* CR8F */
518 for (j
= 0; j
<= 6; j
++) /* CR90 - CR96 */
519 xgifb_reg_set(P3d4
, (0x90 + j
),
520 pVBInfo
->CR40
[14 + j
][pVBInfo
->ram_type
]);
522 for (j
= 0; j
<= 2; j
++) /* CRC3 - CRC5 */
523 xgifb_reg_set(P3d4
, (0xC3 + j
),
524 pVBInfo
->CR40
[21 + j
][pVBInfo
->ram_type
]);
526 for (j
= 0; j
< 2; j
++) /* CR8A - CR8B */
527 xgifb_reg_set(P3d4
, (0x8A + j
),
528 pVBInfo
->CR40
[1 + j
][pVBInfo
->ram_type
]);
530 if (HwDeviceExtension
->jChipType
== XG42
)
531 xgifb_reg_set(P3d4
, 0x8C, 0x87);
535 pVBInfo
->CR40
[4][pVBInfo
->ram_type
]); /* CR59 */
537 xgifb_reg_set(P3d4
, 0x83, 0x09); /* CR83 */
538 xgifb_reg_set(P3d4
, 0x87, 0x00); /* CR87 */
539 xgifb_reg_set(P3d4
, 0xCF, XG40_CRCF
); /* CRCF */
540 if (pVBInfo
->ram_type
) {
541 xgifb_reg_set(P3c4
, 0x17, 0x80); /* SR17 DDRII */
542 if (HwDeviceExtension
->jChipType
== XG27
)
543 xgifb_reg_set(P3c4
, 0x17, 0x02); /* SR17 DDRII */
546 xgifb_reg_set(P3c4
, 0x17, 0x00); /* SR17 DDR */
548 xgifb_reg_set(P3c4
, 0x1A, 0x87); /* SR1A */
550 temp
= XGINew_GetXG20DRAMType(HwDeviceExtension
, pVBInfo
);
552 XGINew_DDR1x_DefaultRegister(HwDeviceExtension
, P3d4
, pVBInfo
);
554 xgifb_reg_set(P3d4
, 0xB0, 0x80); /* DDRII Dual frequency mode */
555 XGINew_DDR2_DefaultRegister(HwDeviceExtension
, P3d4
, pVBInfo
);
559 pVBInfo
->SR15
[3][pVBInfo
->ram_type
]); /* SR1B */
563 static unsigned short XGINew_SetDRAMSize20Reg(
564 unsigned short dram_size
,
565 struct vb_device_info
*pVBInfo
)
567 unsigned short data
= 0, memsize
= 0;
569 unsigned char ChannelNo
;
571 RankSize
= dram_size
* pVBInfo
->ram_bus
/ 8;
572 data
= xgifb_reg_get(pVBInfo
->P3c4
, 0x13);
580 if (pVBInfo
->ram_channel
== 3)
583 ChannelNo
= pVBInfo
->ram_channel
;
585 if (ChannelNo
* RankSize
<= 256) {
586 while ((RankSize
>>= 1) > 0)
591 /* Fix DRAM Sizing Error */
592 xgifb_reg_set(pVBInfo
->P3c4
,
594 (xgifb_reg_get(pVBInfo
->P3c4
, 0x14) & 0x0F) |
601 static int XGINew_ReadWriteRest(unsigned short StopAddr
,
602 unsigned short StartAddr
, struct vb_device_info
*pVBInfo
)
605 unsigned long Position
= 0;
606 void __iomem
*fbaddr
= pVBInfo
->FBAddr
;
608 writel(Position
, fbaddr
+ Position
);
610 for (i
= StartAddr
; i
<= StopAddr
; i
++) {
612 writel(Position
, fbaddr
+ Position
);
615 udelay(500); /* Fix #1759 Memory Size error in Multi-Adapter. */
619 if (readl(fbaddr
+ Position
) != Position
)
622 for (i
= StartAddr
; i
<= StopAddr
; i
++) {
624 if (readl(fbaddr
+ Position
) != Position
)
630 static unsigned char XGINew_CheckFrequence(struct vb_device_info
*pVBInfo
)
634 data
= xgifb_reg_get(pVBInfo
->P3d4
, 0x97);
636 if ((data
& 0x10) == 0) {
637 data
= xgifb_reg_get(pVBInfo
->P3c4
, 0x39);
638 data
= (data
& 0x02) >> 1;
645 static void XGINew_CheckChannel(struct xgi_hw_device_info
*HwDeviceExtension
,
646 struct vb_device_info
*pVBInfo
)
650 switch (HwDeviceExtension
->jChipType
) {
653 data
= xgifb_reg_get(pVBInfo
->P3d4
, 0x97);
655 pVBInfo
->ram_channel
= 1; /* XG20 "JUST" one channel */
657 if (data
== 0) { /* Single_32_16 */
659 if ((HwDeviceExtension
->ulVideoMemorySize
- 1)
662 pVBInfo
->ram_bus
= 32; /* 32 bits */
663 /* 22bit + 2 rank + 32bit */
664 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xB1);
665 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x52);
668 if (XGINew_ReadWriteRest(24, 23, pVBInfo
) == 1)
671 if ((HwDeviceExtension
->ulVideoMemorySize
- 1) >
673 /* 22bit + 1 rank + 32bit */
674 xgifb_reg_set(pVBInfo
->P3c4
,
677 xgifb_reg_set(pVBInfo
->P3c4
,
682 if (XGINew_ReadWriteRest(23,
689 if ((HwDeviceExtension
->ulVideoMemorySize
- 1) >
691 pVBInfo
->ram_bus
= 16; /* 16 bits */
692 /* 22bit + 2 rank + 16bit */
693 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xB1);
694 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x41);
697 if (XGINew_ReadWriteRest(23, 22, pVBInfo
) == 1)
700 xgifb_reg_set(pVBInfo
->P3c4
,
706 } else { /* Dual_16_8 */
707 if ((HwDeviceExtension
->ulVideoMemorySize
- 1) >
709 pVBInfo
->ram_bus
= 16; /* 16 bits */
710 /* (0x31:12x8x2) 22bit + 2 rank */
711 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xB1);
713 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x41);
716 if (XGINew_ReadWriteRest(23, 22, pVBInfo
) == 1)
719 if ((HwDeviceExtension
->ulVideoMemorySize
- 1) >
721 /* (0x31:12x8x2) 22bit + 1 rank */
722 xgifb_reg_set(pVBInfo
->P3c4
,
726 xgifb_reg_set(pVBInfo
->P3c4
,
731 if (XGINew_ReadWriteRest(22,
738 if ((HwDeviceExtension
->ulVideoMemorySize
- 1) >
740 pVBInfo
->ram_bus
= 8; /* 8 bits */
741 /* (0x31:12x8x2) 22bit + 2 rank */
742 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xB1);
744 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x30);
747 if (XGINew_ReadWriteRest(22, 21, pVBInfo
) == 1)
749 else /* (0x31:12x8x2) 22bit + 1 rank */
750 xgifb_reg_set(pVBInfo
->P3c4
,
759 pVBInfo
->ram_bus
= 16; /* 16 bits */
760 pVBInfo
->ram_channel
= 1; /* Single channel */
761 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x51); /* 32Mx16 bit*/
765 XG42 SR14 D[3] Reserve
766 D[2] = 1, Dual Channel
769 It's Different from Other XG40 Series.
771 if (XGINew_CheckFrequence(pVBInfo
) == 1) { /* DDRII, DDR2x */
772 pVBInfo
->ram_bus
= 32; /* 32 bits */
773 pVBInfo
->ram_channel
= 2; /* 2 Channel */
774 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xA1);
775 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x44);
777 if (XGINew_ReadWriteRest(24, 23, pVBInfo
) == 1)
780 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0x21);
781 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x34);
782 if (XGINew_ReadWriteRest(23, 22, pVBInfo
) == 1)
785 pVBInfo
->ram_channel
= 1; /* Single Channel */
786 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xA1);
787 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x40);
789 if (XGINew_ReadWriteRest(23, 22, pVBInfo
) == 1)
792 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0x21);
793 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x30);
796 pVBInfo
->ram_bus
= 64; /* 64 bits */
797 pVBInfo
->ram_channel
= 1; /* 1 channels */
798 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xA1);
799 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x52);
801 if (XGINew_ReadWriteRest(24, 23, pVBInfo
) == 1)
804 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0x21);
805 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x42);
813 if (XGINew_CheckFrequence(pVBInfo
) == 1) { /* DDRII */
814 pVBInfo
->ram_bus
= 32; /* 32 bits */
815 pVBInfo
->ram_channel
= 3;
816 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xA1);
817 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x4C);
819 if (XGINew_ReadWriteRest(25, 23, pVBInfo
) == 1)
822 pVBInfo
->ram_channel
= 2; /* 2 channels */
823 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x48);
825 if (XGINew_ReadWriteRest(24, 23, pVBInfo
) == 1)
828 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0x21);
829 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x3C);
831 if (XGINew_ReadWriteRest(24, 23, pVBInfo
) == 1) {
832 pVBInfo
->ram_channel
= 3; /* 4 channels */
834 pVBInfo
->ram_channel
= 2; /* 2 channels */
835 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x38);
838 pVBInfo
->ram_bus
= 64; /* 64 bits */
839 pVBInfo
->ram_channel
= 2; /* 2 channels */
840 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0xA1);
841 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x5A);
843 if (XGINew_ReadWriteRest(25, 24, pVBInfo
) == 1) {
846 xgifb_reg_set(pVBInfo
->P3c4
, 0x13, 0x21);
847 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x4A);
854 static int XGINew_DDRSizing340(struct xgi_hw_device_info
*HwDeviceExtension
,
855 struct vb_device_info
*pVBInfo
)
858 unsigned short memsize
, start_addr
;
859 const unsigned short (*dram_table
)[2];
861 xgifb_reg_set(pVBInfo
->P3c4
, 0x15, 0x00); /* noninterleaving */
862 xgifb_reg_set(pVBInfo
->P3c4
, 0x1C, 0x00); /* nontiling */
863 XGINew_CheckChannel(HwDeviceExtension
, pVBInfo
);
865 if (HwDeviceExtension
->jChipType
>= XG20
) {
866 dram_table
= XGINew_DDRDRAM_TYPE20
;
867 size
= ARRAY_SIZE(XGINew_DDRDRAM_TYPE20
);
870 dram_table
= XGINew_DDRDRAM_TYPE340
;
871 size
= ARRAY_SIZE(XGINew_DDRDRAM_TYPE340
);
875 for (i
= 0; i
< size
; i
++) {
876 /* SetDRAMSizingType */
877 xgifb_reg_and_or(pVBInfo
->P3c4
, 0x13, 0x80, dram_table
[i
][1]);
878 udelay(15); /* should delay 50 ns */
880 memsize
= XGINew_SetDRAMSize20Reg(dram_table
[i
][0], pVBInfo
);
885 memsize
+= (pVBInfo
->ram_channel
- 2) + 20;
886 if ((HwDeviceExtension
->ulVideoMemorySize
- 1) <
887 (unsigned long) (1 << memsize
))
890 if (XGINew_ReadWriteRest(memsize
, start_addr
, pVBInfo
) == 1)
896 static void XGINew_SetDRAMSize_340(struct xgifb_video_info
*xgifb_info
,
897 struct xgi_hw_device_info
*HwDeviceExtension
,
898 struct vb_device_info
*pVBInfo
)
902 pVBInfo
->FBAddr
= HwDeviceExtension
->pjVideoMemoryAddress
;
904 XGISetModeNew(xgifb_info
, HwDeviceExtension
, 0x2e);
906 data
= xgifb_reg_get(pVBInfo
->P3c4
, 0x21);
907 /* disable read cache */
908 xgifb_reg_set(pVBInfo
->P3c4
, 0x21, (unsigned short) (data
& 0xDF));
909 XGI_DisplayOff(xgifb_info
, HwDeviceExtension
, pVBInfo
);
911 XGINew_DDRSizing340(HwDeviceExtension
, pVBInfo
);
912 data
= xgifb_reg_get(pVBInfo
->P3c4
, 0x21);
913 /* enable read cache */
914 xgifb_reg_set(pVBInfo
->P3c4
, 0x21, (unsigned short) (data
| 0x20));
917 static u8
*xgifb_copy_rom(struct pci_dev
*dev
, size_t *rom_size
)
919 void __iomem
*rom_address
;
922 rom_address
= pci_map_rom(dev
, rom_size
);
923 if (rom_address
== NULL
)
926 rom_copy
= vzalloc(XGIFB_ROM_SIZE
);
927 if (rom_copy
== NULL
)
930 *rom_size
= min_t(size_t, *rom_size
, XGIFB_ROM_SIZE
);
931 memcpy_fromio(rom_copy
, rom_address
, *rom_size
);
934 pci_unmap_rom(dev
, rom_address
);
938 static void xgifb_read_vbios(struct pci_dev
*pdev
,
939 struct vb_device_info
*pVBInfo
)
941 struct xgifb_video_info
*xgifb_info
= pci_get_drvdata(pdev
);
945 struct XGI21_LVDSCapStruct
*lvds
;
949 if (xgifb_info
->chip
!= XG21
)
951 pVBInfo
->IF_DEF_LVDS
= 0;
952 vbios
= xgifb_copy_rom(pdev
, &vbios_size
);
954 dev_err(&pdev
->dev
, "Video BIOS not available\n");
957 if (vbios_size
<= 0x65)
960 * The user can ignore the LVDS bit in the BIOS and force the display
963 if (!(vbios
[0x65] & 0x1) &&
964 (!xgifb_info
->display2_force
||
965 xgifb_info
->display2
!= XGIFB_DISP_LCD
)) {
969 if (vbios_size
<= 0x317)
971 i
= vbios
[0x316] | (vbios
[0x317] << 8);
972 if (vbios_size
<= i
- 1)
980 * Read the LVDS table index scratch register set by the BIOS.
982 entry
= xgifb_reg_get(xgifb_info
->dev_info
.P3d4
, 0x36);
986 lvds
= &xgifb_info
->lvds_data
;
987 if (vbios_size
<= i
+ 24)
989 lvds
->LVDS_Capability
= vbios
[i
] | (vbios
[i
+ 1] << 8);
990 lvds
->LVDSHT
= vbios
[i
+ 2] | (vbios
[i
+ 3] << 8);
991 lvds
->LVDSVT
= vbios
[i
+ 4] | (vbios
[i
+ 5] << 8);
992 lvds
->LVDSHDE
= vbios
[i
+ 6] | (vbios
[i
+ 7] << 8);
993 lvds
->LVDSVDE
= vbios
[i
+ 8] | (vbios
[i
+ 9] << 8);
994 lvds
->LVDSHFP
= vbios
[i
+ 10] | (vbios
[i
+ 11] << 8);
995 lvds
->LVDSVFP
= vbios
[i
+ 12] | (vbios
[i
+ 13] << 8);
996 lvds
->LVDSHSYNC
= vbios
[i
+ 14] | (vbios
[i
+ 15] << 8);
997 lvds
->LVDSVSYNC
= vbios
[i
+ 16] | (vbios
[i
+ 17] << 8);
998 lvds
->VCLKData1
= vbios
[i
+ 18];
999 lvds
->VCLKData2
= vbios
[i
+ 19];
1000 lvds
->PSC_S1
= vbios
[i
+ 20];
1001 lvds
->PSC_S2
= vbios
[i
+ 21];
1002 lvds
->PSC_S3
= vbios
[i
+ 22];
1003 lvds
->PSC_S4
= vbios
[i
+ 23];
1004 lvds
->PSC_S5
= vbios
[i
+ 24];
1006 pVBInfo
->IF_DEF_LVDS
= 1;
1009 dev_err(&pdev
->dev
, "Video BIOS corrupted\n");
1013 static void XGINew_ChkSenseStatus(struct xgi_hw_device_info
*HwDeviceExtension
,
1014 struct vb_device_info
*pVBInfo
)
1016 unsigned short tempbx
= 0, temp
, tempcx
, CR3CData
;
1018 temp
= xgifb_reg_get(pVBInfo
->P3d4
, 0x32);
1020 if (temp
& Monitor1Sense
)
1021 tempbx
|= ActiveCRT1
;
1022 if (temp
& LCDSense
)
1023 tempbx
|= ActiveLCD
;
1024 if (temp
& Monitor2Sense
)
1025 tempbx
|= ActiveCRT2
;
1026 if (temp
& TVSense
) {
1028 if (temp
& AVIDEOSense
)
1029 tempbx
|= (ActiveAVideo
<< 8);
1030 if (temp
& SVIDEOSense
)
1031 tempbx
|= (ActiveSVideo
<< 8);
1032 if (temp
& SCARTSense
)
1033 tempbx
|= (ActiveSCART
<< 8);
1034 if (temp
& HiTVSense
)
1035 tempbx
|= (ActiveHiTV
<< 8);
1036 if (temp
& YPbPrSense
)
1037 tempbx
|= (ActiveYPbPr
<< 8);
1040 tempcx
= xgifb_reg_get(pVBInfo
->P3d4
, 0x3d);
1041 tempcx
|= (xgifb_reg_get(pVBInfo
->P3d4
, 0x3e) << 8);
1043 if (tempbx
& tempcx
) {
1044 CR3CData
= xgifb_reg_get(pVBInfo
->P3d4
, 0x3c);
1045 if (!(CR3CData
& DisplayDeviceFromCMOS
))
1052 xgifb_reg_set(pVBInfo
->P3d4
, 0x3d, (tempbx
& 0x00FF));
1053 xgifb_reg_set(pVBInfo
->P3d4
, 0x3e, ((tempbx
& 0xFF00) >> 8));
1056 static void XGINew_SetModeScratch(struct xgi_hw_device_info
*HwDeviceExtension
,
1057 struct vb_device_info
*pVBInfo
)
1059 unsigned short temp
, tempcl
= 0, tempch
= 0, CR31Data
, CR38Data
;
1061 temp
= xgifb_reg_get(pVBInfo
->P3d4
, 0x3d);
1062 temp
|= xgifb_reg_get(pVBInfo
->P3d4
, 0x3e) << 8;
1063 temp
|= (xgifb_reg_get(pVBInfo
->P3d4
, 0x31) & (DriverMode
>> 8)) << 8;
1065 if (pVBInfo
->IF_DEF_CRT2Monitor
== 1) {
1066 if (temp
& ActiveCRT2
)
1067 tempcl
= SetCRT2ToRAMDAC
;
1070 if (temp
& ActiveLCD
) {
1071 tempcl
|= SetCRT2ToLCD
;
1072 if (temp
& DriverMode
) {
1073 if (temp
& ActiveTV
) {
1074 tempch
= SetToLCDA
| EnableDualEdge
;
1075 temp
^= SetCRT2ToLCD
;
1077 if ((temp
>> 8) & ActiveAVideo
)
1078 tempcl
|= SetCRT2ToAVIDEO
;
1079 if ((temp
>> 8) & ActiveSVideo
)
1080 tempcl
|= SetCRT2ToSVIDEO
;
1081 if ((temp
>> 8) & ActiveSCART
)
1082 tempcl
|= SetCRT2ToSCART
;
1084 if (pVBInfo
->IF_DEF_HiVision
== 1) {
1085 if ((temp
>> 8) & ActiveHiTV
)
1086 tempcl
|= SetCRT2ToHiVision
;
1089 if (pVBInfo
->IF_DEF_YPbPr
== 1) {
1090 if ((temp
>> 8) & ActiveYPbPr
)
1096 if ((temp
>> 8) & ActiveAVideo
)
1097 tempcl
|= SetCRT2ToAVIDEO
;
1098 if ((temp
>> 8) & ActiveSVideo
)
1099 tempcl
|= SetCRT2ToSVIDEO
;
1100 if ((temp
>> 8) & ActiveSCART
)
1101 tempcl
|= SetCRT2ToSCART
;
1103 if (pVBInfo
->IF_DEF_HiVision
== 1) {
1104 if ((temp
>> 8) & ActiveHiTV
)
1105 tempcl
|= SetCRT2ToHiVision
;
1108 if (pVBInfo
->IF_DEF_YPbPr
== 1) {
1109 if ((temp
>> 8) & ActiveYPbPr
)
1114 tempcl
|= SetSimuScanMode
;
1115 if ((!(temp
& ActiveCRT1
)) && ((temp
& ActiveLCD
) || (temp
& ActiveTV
)
1116 || (temp
& ActiveCRT2
)))
1117 tempcl
^= (SetSimuScanMode
| SwitchCRT2
);
1118 if ((temp
& ActiveLCD
) && (temp
& ActiveTV
))
1119 tempcl
^= (SetSimuScanMode
| SwitchCRT2
);
1120 xgifb_reg_set(pVBInfo
->P3d4
, 0x30, tempcl
);
1122 CR31Data
= xgifb_reg_get(pVBInfo
->P3d4
, 0x31);
1123 CR31Data
&= ~(SetNotSimuMode
>> 8);
1124 if (!(temp
& ActiveCRT1
))
1125 CR31Data
|= (SetNotSimuMode
>> 8);
1126 CR31Data
&= ~(DisableCRT2Display
>> 8);
1127 if (!((temp
& ActiveLCD
) || (temp
& ActiveTV
) || (temp
& ActiveCRT2
)))
1128 CR31Data
|= (DisableCRT2Display
>> 8);
1129 xgifb_reg_set(pVBInfo
->P3d4
, 0x31, CR31Data
);
1131 CR38Data
= xgifb_reg_get(pVBInfo
->P3d4
, 0x38);
1132 CR38Data
&= ~SetYPbPr
;
1134 xgifb_reg_set(pVBInfo
->P3d4
, 0x38, CR38Data
);
1138 static unsigned short XGINew_SenseLCD(struct xgi_hw_device_info
1140 struct vb_device_info
*pVBInfo
)
1142 unsigned short temp
;
1145 if (HwDeviceExtension
->ulCRT2LCDType
== LCD_UNKNOWN
) {
1148 temp
= (unsigned short) HwDeviceExtension
->ulCRT2LCDType
;
1149 switch (HwDeviceExtension
->ulCRT2LCDType
) {
1177 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x36, 0xF0, temp
);
1182 static void XGINew_GetXG21Sense(struct xgi_hw_device_info
*HwDeviceExtension
,
1183 struct vb_device_info
*pVBInfo
)
1187 if (pVBInfo
->IF_DEF_LVDS
) { /* For XG21 LVDS */
1188 xgifb_reg_or(pVBInfo
->P3d4
, 0x32, LCDSense
);
1190 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x38, ~0xE0, 0xC0);
1192 /* Enable GPIOA/B read */
1193 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x4A, ~0x03, 0x03);
1194 Temp
= xgifb_reg_get(pVBInfo
->P3d4
, 0x48) & 0xC0;
1195 if (Temp
== 0xC0) { /* DVI & DVO GPIOA/B pull high */
1196 XGINew_SenseLCD(HwDeviceExtension
, pVBInfo
);
1197 xgifb_reg_or(pVBInfo
->P3d4
, 0x32, LCDSense
);
1198 /* Enable read GPIOF */
1199 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x4A, ~0x20, 0x20);
1200 Temp
= xgifb_reg_get(pVBInfo
->P3d4
, 0x48) & 0x04;
1202 xgifb_reg_and_or(pVBInfo
->P3d4
,
1205 0x80); /* TMDS on chip */
1207 xgifb_reg_and_or(pVBInfo
->P3d4
,
1210 0xA0); /* Only DVO on chip */
1211 /* Disable read GPIOF */
1212 xgifb_reg_and(pVBInfo
->P3d4
, 0x4A, ~0x20);
1217 static void XGINew_GetXG27Sense(struct xgi_hw_device_info
*HwDeviceExtension
,
1218 struct vb_device_info
*pVBInfo
)
1220 unsigned char Temp
, bCR4A
;
1222 pVBInfo
->IF_DEF_LVDS
= 0;
1223 bCR4A
= xgifb_reg_get(pVBInfo
->P3d4
, 0x4A);
1224 /* Enable GPIOA/B/C read */
1225 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x4A, ~0x07, 0x07);
1226 Temp
= xgifb_reg_get(pVBInfo
->P3d4
, 0x48) & 0x07;
1227 xgifb_reg_set(pVBInfo
->P3d4
, 0x4A, bCR4A
);
1231 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x38, ~0xE0, 0xC0);
1232 xgifb_reg_set(pVBInfo
->P3d4
, 0x30, 0x21);
1234 /* TMDS/DVO setting */
1235 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x38, ~0xE0, 0xA0);
1237 xgifb_reg_or(pVBInfo
->P3d4
, 0x32, LCDSense
);
1241 static unsigned char GetXG21FPBits(struct vb_device_info
*pVBInfo
)
1243 unsigned char CR38
, CR4A
, temp
;
1245 CR4A
= xgifb_reg_get(pVBInfo
->P3d4
, 0x4A);
1246 /* enable GPIOE read */
1247 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x4A, ~0x10, 0x10);
1248 CR38
= xgifb_reg_get(pVBInfo
->P3d4
, 0x38);
1250 if ((CR38
& 0xE0) > 0x80) {
1251 temp
= xgifb_reg_get(pVBInfo
->P3d4
, 0x48);
1256 xgifb_reg_set(pVBInfo
->P3d4
, 0x4A, CR4A
);
1261 static unsigned char GetXG27FPBits(struct vb_device_info
*pVBInfo
)
1263 unsigned char CR4A
, temp
;
1265 CR4A
= xgifb_reg_get(pVBInfo
->P3d4
, 0x4A);
1266 /* enable GPIOA/B/C read */
1267 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x4A, ~0x03, 0x03);
1268 temp
= xgifb_reg_get(pVBInfo
->P3d4
, 0x48);
1272 temp
= ((temp
& 0x04) >> 1) || ((~temp
) & 0x01);
1274 xgifb_reg_set(pVBInfo
->P3d4
, 0x4A, CR4A
);
1279 unsigned char XGIInitNew(struct pci_dev
*pdev
)
1281 struct xgifb_video_info
*xgifb_info
= pci_get_drvdata(pdev
);
1282 struct xgi_hw_device_info
*HwDeviceExtension
= &xgifb_info
->hw_info
;
1283 struct vb_device_info VBINF
;
1284 struct vb_device_info
*pVBInfo
= &VBINF
;
1285 unsigned char i
, temp
= 0, temp1
;
1287 pVBInfo
->FBAddr
= HwDeviceExtension
->pjVideoMemoryAddress
;
1289 pVBInfo
->BaseAddr
= xgifb_info
->vga_base
;
1291 if (pVBInfo
->FBAddr
== NULL
) {
1292 dev_dbg(&pdev
->dev
, "pVBInfo->FBAddr == 0\n");
1295 if (pVBInfo
->BaseAddr
== 0) {
1296 dev_dbg(&pdev
->dev
, "pVBInfo->BaseAddr == 0\n");
1300 outb(0x67, (pVBInfo
->BaseAddr
+ 0x12)); /* 3c2 <- 67 ,ynlai */
1302 pVBInfo
->ISXPDOS
= 0;
1304 pVBInfo
->P3c4
= pVBInfo
->BaseAddr
+ 0x14;
1305 pVBInfo
->P3d4
= pVBInfo
->BaseAddr
+ 0x24;
1306 pVBInfo
->P3c0
= pVBInfo
->BaseAddr
+ 0x10;
1307 pVBInfo
->P3ce
= pVBInfo
->BaseAddr
+ 0x1e;
1308 pVBInfo
->P3c2
= pVBInfo
->BaseAddr
+ 0x12;
1309 pVBInfo
->P3ca
= pVBInfo
->BaseAddr
+ 0x1a;
1310 pVBInfo
->P3c6
= pVBInfo
->BaseAddr
+ 0x16;
1311 pVBInfo
->P3c7
= pVBInfo
->BaseAddr
+ 0x17;
1312 pVBInfo
->P3c8
= pVBInfo
->BaseAddr
+ 0x18;
1313 pVBInfo
->P3c9
= pVBInfo
->BaseAddr
+ 0x19;
1314 pVBInfo
->P3da
= pVBInfo
->BaseAddr
+ 0x2A;
1315 pVBInfo
->Part0Port
= pVBInfo
->BaseAddr
+ XGI_CRT2_PORT_00
;
1316 pVBInfo
->Part1Port
= pVBInfo
->BaseAddr
+ SIS_CRT2_PORT_04
;
1317 pVBInfo
->Part2Port
= pVBInfo
->BaseAddr
+ SIS_CRT2_PORT_10
;
1318 pVBInfo
->Part3Port
= pVBInfo
->BaseAddr
+ SIS_CRT2_PORT_12
;
1319 pVBInfo
->Part4Port
= pVBInfo
->BaseAddr
+ SIS_CRT2_PORT_14
;
1320 pVBInfo
->Part5Port
= pVBInfo
->BaseAddr
+ SIS_CRT2_PORT_14
+ 2;
1322 if (HwDeviceExtension
->jChipType
< XG20
)
1323 /* Run XGI_GetVBType before InitTo330Pointer */
1324 XGI_GetVBType(pVBInfo
);
1326 InitTo330Pointer(HwDeviceExtension
->jChipType
, pVBInfo
);
1328 xgifb_read_vbios(pdev
, pVBInfo
);
1331 xgifb_reg_set(pVBInfo
->P3c4
, 0x05, 0x86);
1333 /* GetXG21Sense (GPIO) */
1334 if (HwDeviceExtension
->jChipType
== XG21
)
1335 XGINew_GetXG21Sense(HwDeviceExtension
, pVBInfo
);
1337 if (HwDeviceExtension
->jChipType
== XG27
)
1338 XGINew_GetXG27Sense(HwDeviceExtension
, pVBInfo
);
1340 /* Reset Extended register */
1342 for (i
= 0x06; i
< 0x20; i
++)
1343 xgifb_reg_set(pVBInfo
->P3c4
, i
, 0);
1345 for (i
= 0x21; i
<= 0x27; i
++)
1346 xgifb_reg_set(pVBInfo
->P3c4
, i
, 0);
1348 for (i
= 0x31; i
<= 0x3B; i
++)
1349 xgifb_reg_set(pVBInfo
->P3c4
, i
, 0);
1351 /* Auto over driver for XG42 */
1352 if (HwDeviceExtension
->jChipType
== XG42
)
1353 xgifb_reg_set(pVBInfo
->P3c4
, 0x3B, 0xC0);
1355 for (i
= 0x79; i
<= 0x7C; i
++)
1356 xgifb_reg_set(pVBInfo
->P3d4
, i
, 0);
1358 if (HwDeviceExtension
->jChipType
>= XG20
)
1359 xgifb_reg_set(pVBInfo
->P3d4
, 0x97, pVBInfo
->XGINew_CR97
);
1361 /* SetDefExt1Regs begin */
1362 xgifb_reg_set(pVBInfo
->P3c4
, 0x07, XGI330_SR07
);
1363 if (HwDeviceExtension
->jChipType
== XG27
) {
1364 xgifb_reg_set(pVBInfo
->P3c4
, 0x40, XG27_SR40
);
1365 xgifb_reg_set(pVBInfo
->P3c4
, 0x41, XG27_SR41
);
1367 xgifb_reg_set(pVBInfo
->P3c4
, 0x11, 0x0F);
1368 xgifb_reg_set(pVBInfo
->P3c4
, 0x1F, XGI330_SR1F
);
1369 /* Frame buffer can read/write SR20 */
1370 xgifb_reg_set(pVBInfo
->P3c4
, 0x20, 0xA0);
1371 /* H/W request for slow corner chip */
1372 xgifb_reg_set(pVBInfo
->P3c4
, 0x36, 0x70);
1373 if (HwDeviceExtension
->jChipType
== XG27
)
1374 xgifb_reg_set(pVBInfo
->P3c4
, 0x36, XG27_SR36
);
1376 if (HwDeviceExtension
->jChipType
< XG20
) {
1379 /* Set AGP customize registers (in SetDefAGPRegs) Start */
1380 for (i
= 0x47; i
<= 0x4C; i
++)
1381 xgifb_reg_set(pVBInfo
->P3d4
,
1383 pVBInfo
->AGPReg
[i
- 0x47]);
1385 for (i
= 0x70; i
<= 0x71; i
++)
1386 xgifb_reg_set(pVBInfo
->P3d4
,
1388 pVBInfo
->AGPReg
[6 + i
- 0x70]);
1390 for (i
= 0x74; i
<= 0x77; i
++)
1391 xgifb_reg_set(pVBInfo
->P3d4
,
1393 pVBInfo
->AGPReg
[8 + i
- 0x74]);
1395 pci_read_config_dword(pdev
, 0x50, &Temp
);
1400 xgifb_reg_set(pVBInfo
->P3d4
, 0x48, 0x20); /* CR48 */
1404 xgifb_reg_set(pVBInfo
->P3c4
, 0x23, XGI330_SR23
);
1405 xgifb_reg_set(pVBInfo
->P3c4
, 0x24, XGI330_SR24
);
1406 xgifb_reg_set(pVBInfo
->P3c4
, 0x25, XGI330_SR25
);
1408 if (HwDeviceExtension
->jChipType
< XG20
) {
1410 XGI_UnLockCRT2(HwDeviceExtension
, pVBInfo
);
1411 /* disable VideoCapture */
1412 xgifb_reg_and_or(pVBInfo
->Part0Port
, 0x3F, 0xEF, 0x00);
1413 xgifb_reg_set(pVBInfo
->Part1Port
, 0x00, 0x00);
1414 /* chk if BCLK>=100MHz */
1415 temp1
= (unsigned char) xgifb_reg_get(pVBInfo
->P3d4
, 0x7B);
1416 temp
= (unsigned char) ((temp1
>> 4) & 0x0F);
1418 xgifb_reg_set(pVBInfo
->Part1Port
,
1419 0x02, XGI330_CRT2Data_1_2
);
1421 xgifb_reg_set(pVBInfo
->Part1Port
, 0x2E, 0x08); /* use VB */
1424 xgifb_reg_set(pVBInfo
->P3c4
, 0x27, 0x1F);
1426 if ((HwDeviceExtension
->jChipType
== XG42
) &&
1427 XGINew_GetXG20DRAMType(HwDeviceExtension
, pVBInfo
) != 0) {
1429 xgifb_reg_set(pVBInfo
->P3c4
,
1431 (XGI330_SR31
& 0x3F) | 0x40);
1432 xgifb_reg_set(pVBInfo
->P3c4
,
1434 (XGI330_SR32
& 0xFC) | 0x01);
1436 xgifb_reg_set(pVBInfo
->P3c4
, 0x31, XGI330_SR31
);
1437 xgifb_reg_set(pVBInfo
->P3c4
, 0x32, XGI330_SR32
);
1439 xgifb_reg_set(pVBInfo
->P3c4
, 0x33, XGI330_SR33
);
1441 if (HwDeviceExtension
->jChipType
< XG20
) {
1442 if (XGI_BridgeIsOn(pVBInfo
) == 1) {
1443 if (pVBInfo
->IF_DEF_LVDS
== 0) {
1444 xgifb_reg_set(pVBInfo
->Part2Port
, 0x00, 0x1C);
1445 xgifb_reg_set(pVBInfo
->Part4Port
,
1446 0x0D, XGI330_CRT2Data_4_D
);
1447 xgifb_reg_set(pVBInfo
->Part4Port
,
1448 0x0E, XGI330_CRT2Data_4_E
);
1449 xgifb_reg_set(pVBInfo
->Part4Port
,
1450 0x10, XGI330_CRT2Data_4_10
);
1451 xgifb_reg_set(pVBInfo
->Part4Port
, 0x0F, 0x3F);
1454 XGI_LockCRT2(HwDeviceExtension
, pVBInfo
);
1458 XGI_SenseCRT1(pVBInfo
);
1460 if (HwDeviceExtension
->jChipType
== XG21
) {
1462 xgifb_reg_and_or(pVBInfo
->P3d4
,
1465 Monitor1Sense
); /* Z9 default has CRT */
1466 temp
= GetXG21FPBits(pVBInfo
);
1467 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x37, ~0x01, temp
);
1470 if (HwDeviceExtension
->jChipType
== XG27
) {
1471 xgifb_reg_and_or(pVBInfo
->P3d4
,
1474 Monitor1Sense
); /* Z9 default has CRT */
1475 temp
= GetXG27FPBits(pVBInfo
);
1476 xgifb_reg_and_or(pVBInfo
->P3d4
, 0x37, ~0x03, temp
);
1479 pVBInfo
->ram_type
= XGINew_GetXG20DRAMType(HwDeviceExtension
, pVBInfo
);
1481 XGINew_SetDRAMDefaultRegister340(HwDeviceExtension
,
1485 XGINew_SetDRAMSize_340(xgifb_info
, HwDeviceExtension
, pVBInfo
);
1487 xgifb_reg_set(pVBInfo
->P3c4
,
1489 (unsigned char) ((pVBInfo
->SR22
) & 0xFE));
1491 xgifb_reg_set(pVBInfo
->P3c4
, 0x21, pVBInfo
->SR21
);
1493 XGINew_ChkSenseStatus(HwDeviceExtension
, pVBInfo
);
1494 XGINew_SetModeScratch(HwDeviceExtension
, pVBInfo
);
1496 xgifb_reg_set(pVBInfo
->P3d4
, 0x8c, 0x87);
1497 xgifb_reg_set(pVBInfo
->P3c4
, 0x14, 0x31);