2 * VIDIX driver for SiS chipsets.
3 * Video bridge detection for SiS 300 and 310/325 series.
4 * Copyright (C) 2003 Jake Page, Sugar Media.
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with MPlayer; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * Based on SiS Xv driver
23 * Copyright 2002-2003 by Thomas Winischhofer, Vienna, Austria.
35 static void sis_ddc2_delay(unsigned short delaytime
)
40 for (i
= 0; i
< delaytime
; i
++) {
41 inSISIDXREG(SISSR
, 0x05, temp
);
46 static int sis_do_sense(int tempbl
, int tempbh
, int tempcl
, int tempch
)
50 outSISIDXREG(SISPART4
, 0x11, tempbl
);
51 temp
= tempbh
| tempcl
;
52 setSISIDXREG(SISPART4
, 0x10, 0xe0, temp
);
54 sis_ddc2_delay(0x1000);
56 inSISIDXREG(SISPART4
, 0x03, temp
);
59 return (temp
== tempch
);
63 /* sense connected devices on 30x bridge */
64 static void sis_sense_30x(void)
66 unsigned char backupP4_0d
, backupP2_00
, biosflag
;
67 unsigned char testsvhs_tempbl
, testsvhs_tempbh
;
68 unsigned char testsvhs_tempcl
, testsvhs_tempch
;
69 unsigned char testcvbs_tempbl
, testcvbs_tempbh
;
70 unsigned char testcvbs_tempcl
, testcvbs_tempch
;
71 unsigned char testvga2_tempbl
, testvga2_tempbh
;
72 unsigned char testvga2_tempcl
, testvga2_tempch
;
73 int myflag
, result
= 0, i
, j
, haveresult
;
75 inSISIDXREG(SISPART4
, 0x0d, backupP4_0d
);
76 outSISIDXREG(SISPART4
, 0x0d, (backupP4_0d
| 0x04));
78 inSISIDXREG(SISPART2
, 0x00, backupP2_00
);
79 outSISIDXREG(SISPART2
, 0x00, (backupP2_00
| 0x1c));
81 sis_do_sense(0, 0, 0, 0);
83 if (sis_vga_engine
== SIS_300_VGA
) {
84 testvga2_tempbh
= 0x00;
85 testvga2_tempbl
= 0xd1;
86 testsvhs_tempbh
= 0x00;
87 testsvhs_tempbl
= 0xb9;
88 testcvbs_tempbh
= 0x00;
89 testcvbs_tempbl
= 0xb3;
92 if (sis_vbflags
& (VB_301B
| VB_302B
| VB_301LV
| VB_302LV
)) {
93 testvga2_tempbh
= 0x01;
94 testvga2_tempbl
= 0x90;
95 testsvhs_tempbh
= 0x01;
96 testsvhs_tempbl
= 0x6b;
97 testcvbs_tempbh
= 0x01;
98 testcvbs_tempbl
= 0x74;
100 inSISIDXREG(SISPART4
, 0x01, myflag
);
102 testvga2_tempbh
= 0x00;
103 testvga2_tempbl
= 0xfd;
104 testsvhs_tempbh
= 0x00;
105 testsvhs_tempbl
= 0xdd;
106 testcvbs_tempbh
= 0x00;
107 testcvbs_tempbl
= 0xee;
109 testvga2_tempch
= 0x0e;
110 testvga2_tempcl
= 0x08;
111 testsvhs_tempch
= 0x06;
112 testsvhs_tempcl
= 0x04;
113 testcvbs_tempch
= 0x08;
114 testcvbs_tempcl
= 0x04;
116 if (sis_device_id
== DEVICE_SIS_300
) {
117 inSISIDXREG(SISSR
, 0x3b, myflag
);
118 if (!(myflag
& 0x01)) {
119 testvga2_tempbh
= 0x00;
120 testvga2_tempbl
= 0x00;
121 testvga2_tempch
= 0x00;
122 testvga2_tempcl
= 0x00;
126 testvga2_tempbh
= 0x00;
127 testvga2_tempbl
= 0xd1;
128 testsvhs_tempbh
= 0x00;
129 testsvhs_tempbl
= 0xb9;
130 testcvbs_tempbh
= 0x00;
131 testcvbs_tempbl
= 0xb3;
134 if (sis_vbflags
& (VB_301B
| VB_302B
| VB_301LV
| VB_302LV
)) {
135 if (sis_vbflags
& (VB_301B
| VB_302B
)) {
136 testvga2_tempbh
= 0x01;
137 testvga2_tempbl
= 0x90;
138 testsvhs_tempbh
= 0x01;
139 testsvhs_tempbl
= 0x6b;
140 testcvbs_tempbh
= 0x01;
141 testcvbs_tempbl
= 0x74;
143 testvga2_tempbh
= 0x00;
144 testvga2_tempbl
= 0x00;
145 testsvhs_tempbh
= 0x02;
146 testsvhs_tempbl
= 0x00;
147 testcvbs_tempbh
= 0x01;
148 testcvbs_tempbl
= 0x00;
151 if (sis_vbflags
& (VB_301
| VB_301B
| VB_302B
)) {
152 inSISIDXREG(SISPART4
, 0x01, myflag
);
154 testvga2_tempbh
= 0x00;
155 testvga2_tempbl
= 0xfd;
156 testsvhs_tempbh
= 0x00;
157 testsvhs_tempbl
= 0xdd;
158 testcvbs_tempbh
= 0x00;
159 testcvbs_tempbl
= 0xee;
162 if (sis_vbflags
& (VB_301LV
| VB_302LV
)) {
163 /* TW: No VGA2 or SCART on LV bridges */
164 testvga2_tempbh
= 0x00;
165 testvga2_tempbl
= 0x00;
166 testvga2_tempch
= 0x00;
167 testvga2_tempcl
= 0x00;
168 testsvhs_tempch
= 0x04;
169 testsvhs_tempcl
= 0x08;
170 testcvbs_tempch
= 0x08;
171 testcvbs_tempcl
= 0x08;
173 testvga2_tempch
= 0x0e;
174 testvga2_tempcl
= 0x08;
175 testsvhs_tempch
= 0x06;
176 testsvhs_tempcl
= 0x04;
177 testcvbs_tempch
= 0x08;
178 testcvbs_tempcl
= 0x04;
182 /* XXX: ?? andSISIDXREG(SISCR, 0x32, ~0x14); */
183 /* pSiS->postVBCR32 &= ~0x14; */
185 /* scan for VGA2/SCART */
186 if (testvga2_tempch
|| testvga2_tempcl
||
187 testvga2_tempbh
|| testvga2_tempbl
) {
190 for (j
= 0; j
< 10; j
++) {
192 for (i
= 0; i
< 3; i
++) {
193 if (sis_do_sense(testvga2_tempbl
, testvga2_tempbh
,
194 testvga2_tempcl
, testvga2_tempch
))
197 if ((result
== 0) || (result
>= 2))
201 if (biosflag
& 0x01) {
202 if (sis_verbose
> 1) {
204 ("[SiS] SiS30x: Detected TV connected to SCART output\n");
206 sis_vbflags
|= TV_SCART
;
207 orSISIDXREG(SISCR
, 0x32, 0x04);
208 /*pSiS->postVBCR32 |= 0x04; */
210 if (sis_verbose
> 1) {
212 ("[SiS] SiS30x: Detected secondary VGA connection\n");
214 sis_vbflags
|= VGA2_CONNECTED
;
215 orSISIDXREG(SISCR
, 0x32, 0x10);
216 /*pSiS->postVBCR32 |= 0x10; */
221 /* scanning for TV */
223 /* XXX: ?? andSISIDXREG(SISCR, 0x32, ~0x03); */
224 /* pSiS->postVBCR32 &= ~0x03; */
226 result
= sis_do_sense(testsvhs_tempbl
, testsvhs_tempbh
,
227 testsvhs_tempcl
, testsvhs_tempch
);
231 for (j
= 0; j
< 10; j
++) {
233 for (i
= 0; i
< 3; i
++) {
234 if (sis_do_sense(testsvhs_tempbl
, testsvhs_tempbh
,
235 testsvhs_tempcl
, testsvhs_tempch
))
238 if ((result
== 0) || (result
>= 2))
242 if (sis_verbose
> 1) {
244 ("[SiS] SiS30x: Detected TV connected to SVIDEO output\n");
246 /* TW: So we can be sure that there IS a SVIDEO output */
247 sis_vbflags
|= TV_SVIDEO
;
248 orSISIDXREG(SISCR
, 0x32, 0x02);
249 //pSiS->postVBCR32 |= 0x02;
252 if ((biosflag
& 0x02) || (!(result
))) {
254 for (j
= 0; j
< 10; j
++) {
256 for (i
= 0; i
< 3; i
++) {
257 if (sis_do_sense(testcvbs_tempbl
, testcvbs_tempbh
,
258 testcvbs_tempcl
, testcvbs_tempch
))
261 if ((result
== 0) || (result
>= 2))
265 if (sis_verbose
> 1) {
267 ("[SiS] SiS30x: Detected TV connected to COMPOSITE output\n");
269 sis_vbflags
|= TV_AVIDEO
;
270 orSISIDXREG(SISCR
, 0x32, 0x01);
271 //pSiS->postVBCR32 |= 0x01;
275 sis_do_sense(0, 0, 0, 0);
277 outSISIDXREG(SISPART2
, 0x00, backupP2_00
);
278 outSISIDXREG(SISPART4
, 0x0d, backupP4_0d
);
282 static void sis_detect_crt1(void)
285 unsigned char CRT1Detected
= 0;
286 unsigned char OtherDevices
= 0;
288 if (!(sis_vbflags
& VB_VIDEOBRIDGE
)) {
293 inSISIDXREG(SISCR
, 0x32, CR32
);
300 if (sis_crt1_off
== -1) {
302 /* BIOS detected no CRT1. */
303 /* If other devices exist, switch it off */
309 /* BIOS detected CRT1, leave/switch it on */
313 if (sis_verbose
> 0) {
314 printf("[SiS] %sCRT1 connection detected\n",
315 sis_crt1_off
? "No " : "");
319 static void sis_detect_tv(void)
321 unsigned char SR16
, SR38
, CR32
, CR38
= 0, CR79
;
324 if (!(sis_vbflags
& VB_VIDEOBRIDGE
))
327 inSISIDXREG(SISCR
, 0x32, CR32
);
328 inSISIDXREG(SISSR
, 0x16, SR16
);
329 inSISIDXREG(SISSR
, 0x38, SR38
);
330 switch (sis_vga_engine
) {
332 if (sis_device_id
== DEVICE_SIS_630_VGA
)
340 inSISIDXREG(SISCR
, temp
, CR38
);
344 sis_vbflags
|= CRT2_TV
;
347 sis_vbflags
|= TV_SCART
;
348 else if (CR32
& 0x02)
349 sis_vbflags
|= TV_SVIDEO
;
350 else if (CR32
& 0x01)
351 sis_vbflags
|= TV_AVIDEO
;
352 else if (CR32
& 0x40)
353 sis_vbflags
|= (TV_SVIDEO
| TV_HIVISION
);
354 else if ((CR38
& 0x04) && (sis_vbflags
& (VB_301LV
| VB_302LV
)))
355 sis_vbflags
|= TV_HIVISION_LV
;
356 else if ((CR38
& 0x04) && (sis_vbflags
& VB_CHRONTEL
))
357 sis_vbflags
|= (TV_CHSCART
| TV_PAL
);
358 else if ((CR38
& 0x08) && (sis_vbflags
& VB_CHRONTEL
))
359 sis_vbflags
|= (TV_CHHDTV
| TV_NTSC
);
361 if (sis_vbflags
& (TV_SCART
| TV_SVIDEO
| TV_AVIDEO
| TV_HIVISION
)) {
362 if (sis_vga_engine
== SIS_300_VGA
) {
363 /* TW: Should be SR38 here as well, but this
364 * does not work. Looks like a BIOS bug (2.04.5c).
367 sis_vbflags
|= TV_PAL
;
369 sis_vbflags
|= TV_NTSC
;
370 } else if ((sis_device_id
== DEVICE_SIS_550_VGA
)) {
371 inSISIDXREG(SISCR
, 0x79, CR79
);
373 inSISIDXREG(SISCR
, 0x79, CR79
);
377 sis_vbflags
|= TV_PAL
;
379 sis_vbflags
|= TV_PALM
;
380 else if (CR38
& 0x80)
381 sis_vbflags
|= TV_PALN
;
383 sis_vbflags
|= TV_NTSC
;
384 } else if ((sis_device_id
== DEVICE_SIS_650_VGA
)) {
385 inSISIDXREG(SISCR
, 0x79, CR79
);
387 sis_vbflags
|= TV_PAL
;
389 sis_vbflags
|= TV_PALM
;
390 else if (CR38
& 0x80)
391 sis_vbflags
|= TV_PALN
;
393 sis_vbflags
|= TV_NTSC
;
394 } else { /* 315, 330 */
396 sis_vbflags
|= TV_PAL
;
398 sis_vbflags
|= TV_PALM
;
399 else if (CR38
& 0x80)
400 sis_vbflags
|= TV_PALN
;
402 sis_vbflags
|= TV_NTSC
;
407 (TV_SCART
| TV_SVIDEO
| TV_AVIDEO
| TV_HIVISION
| TV_CHSCART
|
409 if (sis_verbose
> 0) {
410 printf("[SiS] %sTV standard %s\n",
411 (sis_vbflags
& (TV_CHSCART
| TV_CHHDTV
)) ? "Using " :
413 (sis_vbflags
& TV_NTSC
) ? ((sis_vbflags
& TV_CHHDTV
) ?
414 "480i HDTV" : "NTSC")
415 : ((sis_vbflags
& TV_PALM
) ? "PALM"
416 : ((sis_vbflags
& TV_PALN
) ? "PALN" : "PAL")));
423 static void sis_detect_crt2(void)
427 if (!(sis_vbflags
& VB_VIDEOBRIDGE
))
430 /* CRT2-VGA not supported on LVDS and 30xLV */
431 if (sis_vbflags
& (VB_LVDS
| VB_301LV
| VB_302LV
))
434 inSISIDXREG(SISCR
, 0x32, CR32
);
437 sis_vbflags
|= CRT2_VGA
;
441 /* Preinit: detect video bridge and sense connected devs */
442 static void sis_detect_video_bridge(void)
444 int temp
, temp1
, temp2
;
449 if (sis_vga_engine
!= SIS_300_VGA
&& sis_vga_engine
!= SIS_315_VGA
)
452 inSISIDXREG(SISPART4
, 0x00, temp
);
455 inSISIDXREG(SISPART4
, 0x01, temp1
);
458 sis_vbflags
|= VB_302LV
;
459 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_302LV;
460 if (sis_verbose
> 1) {
462 ("[SiS] Detected SiS302LV video bridge (ID 1; Revision 0x%x)\n",
466 } else if (temp1
>= 0xD0) {
467 sis_vbflags
|= VB_301LV
;
468 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_301LV;
469 if (sis_verbose
> 1) {
471 ("[SiS] Detected SiS301LV video bridge (ID 1; Revision 0x%x)\n",
474 } else if (temp1
>= 0xB0) {
475 sis_vbflags
|= VB_301B
;
476 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_301B;
477 inSISIDXREG(SISPART4
, 0x23, temp2
);
479 sis_vbflags
|= VB_30xBDH
;
480 if (sis_verbose
> 1) {
482 ("[SiS] Detected SiS301B%s video bridge (Revision 0x%x)\n",
483 (temp2
& 0x02) ? "" : " (DH)", temp1
);
486 sis_vbflags
|= VB_301
;
487 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_301;
488 if (sis_verbose
> 1) {
490 ("[SiS] Detected SiS301 video bridge (Revision 0x%x)\n",
497 } else if (temp
== 2) {
499 inSISIDXREG(SISPART4
, 0x01, temp1
);
502 sis_vbflags
|= VB_302LV
;
503 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_302LV;
504 if (sis_verbose
> 1) {
506 ("[SiS] Detected SiS302LV video bridge (ID 2; Revision 0x%x)\n",
509 } else if (temp1
>= 0xD0) {
510 sis_vbflags
|= VB_301LV
;
511 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_301LV;
512 if (sis_verbose
> 1) {
514 ("[SiS] Detected SiS301LV video bridge (ID 2; Revision 0x%x)\n",
518 sis_vbflags
|= VB_302B
;
519 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_302B;
520 inSISIDXREG(SISPART4
, 0x23, temp2
);
522 sis_vbflags
|= VB_30xBDH
;
523 if (sis_verbose
> 1) {
525 ("[SiS] Detected SiS302B%s video bridge (Revision 0x%x)\n",
526 (temp2
& 0x02) ? "" : " (DH)", temp1
);
532 } else if (temp
== 3) {
533 if (sis_verbose
> 1) {
534 printf("[SiS] Detected SiS303 video bridge - not supported\n");
537 /* big scary mess of code to handle unknown or Chrontel LVDS */
538 /* skipping it for now */
539 if (sis_verbose
> 1) {
541 ("[SiS] Detected Chrontel video bridge - not supported\n");
545 /* this is probably not relevant to video overlay driver... */
546 /* detects if brdige uses LCDA for low res text modes */
547 if (sis_vga_engine
== SIS_315_VGA
) {
548 if (sis_vbflags
& (VB_302B
| VB_301LV
| VB_302LV
)) {
549 inSISIDXREG(SISCR
, 0x34, temp
);
551 inSISIDXREG(SISCR
, 0x38, temp
);
552 if ((temp
& 0x03) == 0x03) {
553 //pSiS->SiS_Pr->SiS_UseLCDA = TRUE;
554 sis_vbflags
|= VB_USELCDA
;
556 inSISIDXREG(SISCR
, 0x30, temp
);
558 inSISIDXREG(SISPART1
, 0x13, temp
);
560 //pSiS->SiS_Pr->SiS_UseLCDA = TRUE;
561 sis_vbflags
|= VB_USELCDA
;
566 if (sis_vbflags
& VB_USELCDA
) {
567 /* printf("Bridge uses LCDA for low resolution and text modes\n"); */
576 /* detect video bridge type and sense connected devices */
577 void sis_init_video_bridge(void)
580 sis_detect_video_bridge();
587 sis_detected_crt2_devices
=
588 sis_vbflags
& (CRT2_LCD
| CRT2_TV
| CRT2_VGA
);
591 if (sis_force_crt2_type
== CRT2_DEFAULT
) {
592 if (sis_vbflags
& CRT2_VGA
)
593 sis_force_crt2_type
= CRT2_VGA
;
594 else if (sis_vbflags
& CRT2_LCD
)
595 sis_force_crt2_type
= CRT2_LCD
;
596 else if (sis_vbflags
& CRT2_TV
)
597 sis_force_crt2_type
= CRT2_TV
;
600 switch (sis_force_crt2_type
) {
602 sis_vbflags
= sis_vbflags
& ~(CRT2_LCD
| CRT2_VGA
);
603 if (sis_vbflags
& VB_VIDEOBRIDGE
)
604 sis_vbflags
= sis_vbflags
| CRT2_TV
;
606 sis_vbflags
= sis_vbflags
& ~(CRT2_TV
);
609 sis_vbflags
= sis_vbflags
& ~(CRT2_TV
| CRT2_VGA
);
610 if ((sis_vbflags
& VB_VIDEOBRIDGE
) /* XXX: && (pSiS->VBLCDFlags) */
612 sis_vbflags
= sis_vbflags
| CRT2_LCD
;
614 sis_vbflags
= sis_vbflags
& ~(CRT2_LCD
);
615 if (sis_verbose
> 0) {
617 ("[SiS] Can't force CRT2 to LCD, no panel detected\n");
622 if (sis_vbflags
& VB_LVDS
) {
623 if (sis_verbose
> 0) {
624 printf("[SiS] LVDS does not support secondary VGA\n");
628 if (sis_vbflags
& (VB_301LV
| VB_302LV
)) {
629 if (sis_verbose
> 0) {
631 ("[SiS] SiS30xLV bridge does not support secondary VGA\n");
635 sis_vbflags
= sis_vbflags
& ~(CRT2_TV
| CRT2_LCD
);
636 if (sis_vbflags
& VB_VIDEOBRIDGE
)
637 sis_vbflags
= sis_vbflags
| CRT2_VGA
;
639 sis_vbflags
= sis_vbflags
& ~(CRT2_VGA
);
642 sis_vbflags
&= ~(CRT2_TV
| CRT2_LCD
| CRT2_VGA
);
645 /* CRT2 gamma correction?? */
647 /* other force modes: */
648 /* have a 'force tv type' (svideo, composite, scart) option? */
649 /* have a 'force crt1 type' (to turn it off, etc??) */
651 /* TW: Check if CRT1 used (or needed; this eg. if no CRT2 detected) */
652 if (sis_vbflags
& VB_VIDEOBRIDGE
) {
654 /* TW: No CRT2 output? Then we NEED CRT1!
655 * We also need CRT1 if depth = 8 and bridge=LVDS|630+301B
657 if ((!(sis_vbflags
& (CRT2_VGA
| CRT2_LCD
| CRT2_TV
))) || ( /*(pScrn->bitsPerPixel == 8) && */
658 ((sis_vbflags
& (VB_LVDS
| VB_CHRONTEL
)) || ((sis_vga_engine
== SIS_300_VGA
) && (sis_vbflags
& VB_301B
))))) {
661 /* TW: No CRT2 output? Then we can't use hw overlay on CRT2 */
662 if (!(sis_vbflags
& (CRT2_VGA
| CRT2_LCD
| CRT2_TV
)))
663 sis_overlay_on_crt1
= 1;
665 } else { /* TW: no video bridge? */
667 /* Then we NEED CRT1... */
669 /* ... and can't use CRT2 for overlay output */
670 sis_overlay_on_crt1
= 1;
673 /* tvstandard options ? */
675 // determine using CRT1 or CRT2?
676 /* -> NO dualhead right now... */
677 if (sis_vbflags
& DISPTYPE_DISP2
) {
679 sis_vbflags
|= VB_DISPMODE_SINGLE
;
680 /* TW: No CRT1? Then we use the video overlay on CRT2 */
681 sis_overlay_on_crt1
= 0;
682 } else /* TW: CRT1 and CRT2 - mirror or dual head ----- */
683 sis_vbflags
|= (VB_DISPMODE_MIRROR
| DISPTYPE_CRT1
);
684 } else { /* TW: CRT1 only ------------------------------- */
685 sis_vbflags
|= (VB_DISPMODE_SINGLE
| DISPTYPE_CRT1
);
688 if (sis_verbose
> 0) {
689 printf("[SiS] Using hardware overlay on CRT%d\n",
690 sis_overlay_on_crt1
? 1 : 2);