2 * VIDIX driver for SiS chipsets.
3 * Video bridge detection for SiS 300 and 310/325 series.
5 * Copyright (C) 2003 Jake Page, Sugar Media
6 * Based on SiS Xv driver
7 * Copyright 2002-2003 by Thomas Winischhofer, Vienna, Austria
9 * This file is part of MPlayer.
11 * MPlayer is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * MPlayer is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include "sis_bridge.h"
36 static void sis_ddc2_delay(unsigned short delaytime
)
41 for (i
= 0; i
< delaytime
; i
++) {
42 inSISIDXREG(SISSR
, 0x05, temp
);
47 static int sis_do_sense(int tempbl
, int tempbh
, int tempcl
, int tempch
)
51 outSISIDXREG(SISPART4
, 0x11, tempbl
);
52 temp
= tempbh
| tempcl
;
53 setSISIDXREG(SISPART4
, 0x10, 0xe0, temp
);
55 sis_ddc2_delay(0x1000);
57 inSISIDXREG(SISPART4
, 0x03, temp
);
60 return temp
== tempch
;
64 /* sense connected devices on 30x bridge */
65 static void sis_sense_30x(void)
67 unsigned char backupP4_0d
, backupP2_00
, biosflag
;
68 unsigned char testsvhs_tempbl
, testsvhs_tempbh
;
69 unsigned char testsvhs_tempcl
, testsvhs_tempch
;
70 unsigned char testcvbs_tempbl
, testcvbs_tempbh
;
71 unsigned char testcvbs_tempcl
, testcvbs_tempch
;
72 unsigned char testvga2_tempbl
, testvga2_tempbh
;
73 unsigned char testvga2_tempcl
, testvga2_tempch
;
74 int myflag
, result
= 0, i
, j
, haveresult
;
76 inSISIDXREG(SISPART4
, 0x0d, backupP4_0d
);
77 outSISIDXREG(SISPART4
, 0x0d, (backupP4_0d
| 0x04));
79 inSISIDXREG(SISPART2
, 0x00, backupP2_00
);
80 outSISIDXREG(SISPART2
, 0x00, (backupP2_00
| 0x1c));
82 sis_do_sense(0, 0, 0, 0);
84 if (sis_vga_engine
== SIS_300_VGA
) {
85 testvga2_tempbh
= 0x00;
86 testvga2_tempbl
= 0xd1;
87 testsvhs_tempbh
= 0x00;
88 testsvhs_tempbl
= 0xb9;
89 testcvbs_tempbh
= 0x00;
90 testcvbs_tempbl
= 0xb3;
93 if (sis_vbflags
& (VB_301B
| VB_302B
| VB_301LV
| VB_302LV
)) {
94 testvga2_tempbh
= 0x01;
95 testvga2_tempbl
= 0x90;
96 testsvhs_tempbh
= 0x01;
97 testsvhs_tempbl
= 0x6b;
98 testcvbs_tempbh
= 0x01;
99 testcvbs_tempbl
= 0x74;
101 inSISIDXREG(SISPART4
, 0x01, myflag
);
103 testvga2_tempbh
= 0x00;
104 testvga2_tempbl
= 0xfd;
105 testsvhs_tempbh
= 0x00;
106 testsvhs_tempbl
= 0xdd;
107 testcvbs_tempbh
= 0x00;
108 testcvbs_tempbl
= 0xee;
110 testvga2_tempch
= 0x0e;
111 testvga2_tempcl
= 0x08;
112 testsvhs_tempch
= 0x06;
113 testsvhs_tempcl
= 0x04;
114 testcvbs_tempch
= 0x08;
115 testcvbs_tempcl
= 0x04;
117 if (sis_device_id
== DEVICE_SIS_300
) {
118 inSISIDXREG(SISSR
, 0x3b, myflag
);
119 if (!(myflag
& 0x01)) {
120 testvga2_tempbh
= 0x00;
121 testvga2_tempbl
= 0x00;
122 testvga2_tempch
= 0x00;
123 testvga2_tempcl
= 0x00;
127 testvga2_tempbh
= 0x00;
128 testvga2_tempbl
= 0xd1;
129 testsvhs_tempbh
= 0x00;
130 testsvhs_tempbl
= 0xb9;
131 testcvbs_tempbh
= 0x00;
132 testcvbs_tempbl
= 0xb3;
135 if (sis_vbflags
& (VB_301B
| VB_302B
| VB_301LV
| VB_302LV
)) {
136 if (sis_vbflags
& (VB_301B
| VB_302B
)) {
137 testvga2_tempbh
= 0x01;
138 testvga2_tempbl
= 0x90;
139 testsvhs_tempbh
= 0x01;
140 testsvhs_tempbl
= 0x6b;
141 testcvbs_tempbh
= 0x01;
142 testcvbs_tempbl
= 0x74;
144 testvga2_tempbh
= 0x00;
145 testvga2_tempbl
= 0x00;
146 testsvhs_tempbh
= 0x02;
147 testsvhs_tempbl
= 0x00;
148 testcvbs_tempbh
= 0x01;
149 testcvbs_tempbl
= 0x00;
152 if (sis_vbflags
& (VB_301
| VB_301B
| VB_302B
)) {
153 inSISIDXREG(SISPART4
, 0x01, myflag
);
155 testvga2_tempbh
= 0x00;
156 testvga2_tempbl
= 0xfd;
157 testsvhs_tempbh
= 0x00;
158 testsvhs_tempbl
= 0xdd;
159 testcvbs_tempbh
= 0x00;
160 testcvbs_tempbl
= 0xee;
163 if (sis_vbflags
& (VB_301LV
| VB_302LV
)) {
164 /* TW: No VGA2 or SCART on LV bridges */
165 testvga2_tempbh
= 0x00;
166 testvga2_tempbl
= 0x00;
167 testvga2_tempch
= 0x00;
168 testvga2_tempcl
= 0x00;
169 testsvhs_tempch
= 0x04;
170 testsvhs_tempcl
= 0x08;
171 testcvbs_tempch
= 0x08;
172 testcvbs_tempcl
= 0x08;
174 testvga2_tempch
= 0x0e;
175 testvga2_tempcl
= 0x08;
176 testsvhs_tempch
= 0x06;
177 testsvhs_tempcl
= 0x04;
178 testcvbs_tempch
= 0x08;
179 testcvbs_tempcl
= 0x04;
183 /* XXX: ?? andSISIDXREG(SISCR, 0x32, ~0x14); */
184 /* pSiS->postVBCR32 &= ~0x14; */
186 /* scan for VGA2/SCART */
187 if (testvga2_tempch
|| testvga2_tempcl
||
188 testvga2_tempbh
|| testvga2_tempbl
) {
191 for (j
= 0; j
< 10; j
++) {
193 for (i
= 0; i
< 3; i
++) {
194 if (sis_do_sense(testvga2_tempbl
, testvga2_tempbh
,
195 testvga2_tempcl
, testvga2_tempch
))
198 if ((result
== 0) || (result
>= 2))
202 if (biosflag
& 0x01) {
203 if (sis_verbose
> 1) {
205 ("[SiS] SiS30x: Detected TV connected to SCART output\n");
207 sis_vbflags
|= TV_SCART
;
208 orSISIDXREG(SISCR
, 0x32, 0x04);
209 /*pSiS->postVBCR32 |= 0x04; */
211 if (sis_verbose
> 1) {
213 ("[SiS] SiS30x: Detected secondary VGA connection\n");
215 sis_vbflags
|= VGA2_CONNECTED
;
216 orSISIDXREG(SISCR
, 0x32, 0x10);
217 /*pSiS->postVBCR32 |= 0x10; */
222 /* scanning for TV */
224 /* XXX: ?? andSISIDXREG(SISCR, 0x32, ~0x03); */
225 /* pSiS->postVBCR32 &= ~0x03; */
227 result
= sis_do_sense(testsvhs_tempbl
, testsvhs_tempbh
,
228 testsvhs_tempcl
, testsvhs_tempch
);
232 for (j
= 0; j
< 10; j
++) {
234 for (i
= 0; i
< 3; i
++) {
235 if (sis_do_sense(testsvhs_tempbl
, testsvhs_tempbh
,
236 testsvhs_tempcl
, testsvhs_tempch
))
239 if ((result
== 0) || (result
>= 2))
243 if (sis_verbose
> 1) {
245 ("[SiS] SiS30x: Detected TV connected to SVIDEO output\n");
247 /* TW: So we can be sure that there IS a SVIDEO output */
248 sis_vbflags
|= TV_SVIDEO
;
249 orSISIDXREG(SISCR
, 0x32, 0x02);
250 //pSiS->postVBCR32 |= 0x02;
253 if ((biosflag
& 0x02) || (!(result
))) {
255 for (j
= 0; j
< 10; j
++) {
257 for (i
= 0; i
< 3; i
++) {
258 if (sis_do_sense(testcvbs_tempbl
, testcvbs_tempbh
,
259 testcvbs_tempcl
, testcvbs_tempch
))
262 if ((result
== 0) || (result
>= 2))
266 if (sis_verbose
> 1) {
268 ("[SiS] SiS30x: Detected TV connected to COMPOSITE output\n");
270 sis_vbflags
|= TV_AVIDEO
;
271 orSISIDXREG(SISCR
, 0x32, 0x01);
272 //pSiS->postVBCR32 |= 0x01;
276 sis_do_sense(0, 0, 0, 0);
278 outSISIDXREG(SISPART2
, 0x00, backupP2_00
);
279 outSISIDXREG(SISPART4
, 0x0d, backupP4_0d
);
283 static void sis_detect_crt1(void)
286 unsigned char CRT1Detected
= 0;
287 unsigned char OtherDevices
= 0;
289 if (!(sis_vbflags
& VB_VIDEOBRIDGE
)) {
294 inSISIDXREG(SISCR
, 0x32, CR32
);
301 if (sis_crt1_off
== -1) {
303 /* BIOS detected no CRT1. */
304 /* If other devices exist, switch it off */
310 /* BIOS detected CRT1, leave/switch it on */
314 if (sis_verbose
> 0) {
315 printf("[SiS] %sCRT1 connection detected\n",
316 sis_crt1_off
? "No " : "");
320 static void sis_detect_tv(void)
322 unsigned char SR16
, SR38
, CR32
, CR38
= 0, CR79
;
325 if (!(sis_vbflags
& VB_VIDEOBRIDGE
))
328 inSISIDXREG(SISCR
, 0x32, CR32
);
329 inSISIDXREG(SISSR
, 0x16, SR16
);
330 inSISIDXREG(SISSR
, 0x38, SR38
);
331 switch (sis_vga_engine
) {
333 if (sis_device_id
== DEVICE_SIS_630_VGA
)
341 inSISIDXREG(SISCR
, temp
, CR38
);
345 sis_vbflags
|= CRT2_TV
;
348 sis_vbflags
|= TV_SCART
;
349 else if (CR32
& 0x02)
350 sis_vbflags
|= TV_SVIDEO
;
351 else if (CR32
& 0x01)
352 sis_vbflags
|= TV_AVIDEO
;
353 else if (CR32
& 0x40)
354 sis_vbflags
|= (TV_SVIDEO
| TV_HIVISION
);
355 else if ((CR38
& 0x04) && (sis_vbflags
& (VB_301LV
| VB_302LV
)))
356 sis_vbflags
|= TV_HIVISION_LV
;
357 else if ((CR38
& 0x04) && (sis_vbflags
& VB_CHRONTEL
))
358 sis_vbflags
|= (TV_CHSCART
| TV_PAL
);
359 else if ((CR38
& 0x08) && (sis_vbflags
& VB_CHRONTEL
))
360 sis_vbflags
|= (TV_CHHDTV
| TV_NTSC
);
362 if (sis_vbflags
& (TV_SCART
| TV_SVIDEO
| TV_AVIDEO
| TV_HIVISION
)) {
363 if (sis_vga_engine
== SIS_300_VGA
) {
364 /* TW: Should be SR38 here as well, but this
365 * does not work. Looks like a BIOS bug (2.04.5c).
368 sis_vbflags
|= TV_PAL
;
370 sis_vbflags
|= TV_NTSC
;
371 } else if ((sis_device_id
== DEVICE_SIS_550_VGA
)) {
372 inSISIDXREG(SISCR
, 0x79, CR79
);
374 inSISIDXREG(SISCR
, 0x79, CR79
);
378 sis_vbflags
|= TV_PAL
;
380 sis_vbflags
|= TV_PALM
;
381 else if (CR38
& 0x80)
382 sis_vbflags
|= TV_PALN
;
384 sis_vbflags
|= TV_NTSC
;
385 } else if ((sis_device_id
== DEVICE_SIS_650_VGA
)) {
386 inSISIDXREG(SISCR
, 0x79, CR79
);
388 sis_vbflags
|= TV_PAL
;
390 sis_vbflags
|= TV_PALM
;
391 else if (CR38
& 0x80)
392 sis_vbflags
|= TV_PALN
;
394 sis_vbflags
|= TV_NTSC
;
395 } else { /* 315, 330 */
397 sis_vbflags
|= TV_PAL
;
399 sis_vbflags
|= TV_PALM
;
400 else if (CR38
& 0x80)
401 sis_vbflags
|= TV_PALN
;
403 sis_vbflags
|= TV_NTSC
;
408 (TV_SCART
| TV_SVIDEO
| TV_AVIDEO
| TV_HIVISION
| TV_CHSCART
|
410 if (sis_verbose
> 0) {
411 printf("[SiS] %sTV standard %s\n",
412 (sis_vbflags
& (TV_CHSCART
| TV_CHHDTV
)) ? "Using " :
414 (sis_vbflags
& TV_NTSC
) ? ((sis_vbflags
& TV_CHHDTV
) ?
415 "480i HDTV" : "NTSC")
416 : ((sis_vbflags
& TV_PALM
) ? "PALM"
417 : ((sis_vbflags
& TV_PALN
) ? "PALN" : "PAL")));
424 static void sis_detect_crt2(void)
428 if (!(sis_vbflags
& VB_VIDEOBRIDGE
))
431 /* CRT2-VGA not supported on LVDS and 30xLV */
432 if (sis_vbflags
& (VB_LVDS
| VB_301LV
| VB_302LV
))
435 inSISIDXREG(SISCR
, 0x32, CR32
);
438 sis_vbflags
|= CRT2_VGA
;
442 /* Preinit: detect video bridge and sense connected devs */
443 static void sis_detect_video_bridge(void)
445 int temp
, temp1
, temp2
;
450 if (sis_vga_engine
!= SIS_300_VGA
&& sis_vga_engine
!= SIS_315_VGA
)
453 inSISIDXREG(SISPART4
, 0x00, temp
);
456 inSISIDXREG(SISPART4
, 0x01, temp1
);
459 sis_vbflags
|= VB_302LV
;
460 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_302LV;
461 if (sis_verbose
> 1) {
463 ("[SiS] Detected SiS302LV video bridge (ID 1; Revision 0x%x)\n",
467 } else if (temp1
>= 0xD0) {
468 sis_vbflags
|= VB_301LV
;
469 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_301LV;
470 if (sis_verbose
> 1) {
472 ("[SiS] Detected SiS301LV video bridge (ID 1; Revision 0x%x)\n",
475 } else if (temp1
>= 0xB0) {
476 sis_vbflags
|= VB_301B
;
477 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_301B;
478 inSISIDXREG(SISPART4
, 0x23, temp2
);
480 sis_vbflags
|= VB_30xBDH
;
481 if (sis_verbose
> 1) {
483 ("[SiS] Detected SiS301B%s video bridge (Revision 0x%x)\n",
484 (temp2
& 0x02) ? "" : " (DH)", temp1
);
487 sis_vbflags
|= VB_301
;
488 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_301;
489 if (sis_verbose
> 1) {
491 ("[SiS] Detected SiS301 video bridge (Revision 0x%x)\n",
498 } else if (temp
== 2) {
500 inSISIDXREG(SISPART4
, 0x01, temp1
);
503 sis_vbflags
|= VB_302LV
;
504 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_302LV;
505 if (sis_verbose
> 1) {
507 ("[SiS] Detected SiS302LV video bridge (ID 2; Revision 0x%x)\n",
510 } else if (temp1
>= 0xD0) {
511 sis_vbflags
|= VB_301LV
;
512 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_301LV;
513 if (sis_verbose
> 1) {
515 ("[SiS] Detected SiS301LV video bridge (ID 2; Revision 0x%x)\n",
519 sis_vbflags
|= VB_302B
;
520 //pSiS->sishw_ext.ujVBChipID = VB_CHIP_302B;
521 inSISIDXREG(SISPART4
, 0x23, temp2
);
523 sis_vbflags
|= VB_30xBDH
;
524 if (sis_verbose
> 1) {
526 ("[SiS] Detected SiS302B%s video bridge (Revision 0x%x)\n",
527 (temp2
& 0x02) ? "" : " (DH)", temp1
);
533 } else if (temp
== 3) {
534 if (sis_verbose
> 1) {
535 printf("[SiS] Detected SiS303 video bridge - not supported\n");
538 /* big scary mess of code to handle unknown or Chrontel LVDS */
539 /* skipping it for now */
540 if (sis_verbose
> 1) {
542 ("[SiS] Detected Chrontel video bridge - not supported\n");
546 /* this is probably not relevant to video overlay driver... */
547 /* detects if brdige uses LCDA for low res text modes */
548 if (sis_vga_engine
== SIS_315_VGA
) {
549 if (sis_vbflags
& (VB_302B
| VB_301LV
| VB_302LV
)) {
550 inSISIDXREG(SISCR
, 0x34, temp
);
552 inSISIDXREG(SISCR
, 0x38, temp
);
553 if ((temp
& 0x03) == 0x03) {
554 //pSiS->SiS_Pr->SiS_UseLCDA = TRUE;
555 sis_vbflags
|= VB_USELCDA
;
557 inSISIDXREG(SISCR
, 0x30, temp
);
559 inSISIDXREG(SISPART1
, 0x13, temp
);
561 //pSiS->SiS_Pr->SiS_UseLCDA = TRUE;
562 sis_vbflags
|= VB_USELCDA
;
567 if (sis_vbflags
& VB_USELCDA
) {
568 /* printf("Bridge uses LCDA for low resolution and text modes\n"); */
577 /* detect video bridge type and sense connected devices */
578 void sis_init_video_bridge(void)
581 sis_detect_video_bridge();
588 sis_detected_crt2_devices
=
589 sis_vbflags
& (CRT2_LCD
| CRT2_TV
| CRT2_VGA
);
592 if (sis_force_crt2_type
== CRT2_DEFAULT
) {
593 if (sis_vbflags
& CRT2_VGA
)
594 sis_force_crt2_type
= CRT2_VGA
;
595 else if (sis_vbflags
& CRT2_LCD
)
596 sis_force_crt2_type
= CRT2_LCD
;
597 else if (sis_vbflags
& CRT2_TV
)
598 sis_force_crt2_type
= CRT2_TV
;
601 switch (sis_force_crt2_type
) {
603 sis_vbflags
= sis_vbflags
& ~(CRT2_LCD
| CRT2_VGA
);
604 if (sis_vbflags
& VB_VIDEOBRIDGE
)
605 sis_vbflags
= sis_vbflags
| CRT2_TV
;
607 sis_vbflags
= sis_vbflags
& ~(CRT2_TV
);
610 sis_vbflags
= sis_vbflags
& ~(CRT2_TV
| CRT2_VGA
);
611 if ((sis_vbflags
& VB_VIDEOBRIDGE
) /* XXX: && (pSiS->VBLCDFlags) */
613 sis_vbflags
= sis_vbflags
| CRT2_LCD
;
615 sis_vbflags
= sis_vbflags
& ~(CRT2_LCD
);
616 if (sis_verbose
> 0) {
618 ("[SiS] Can't force CRT2 to LCD, no panel detected\n");
623 if (sis_vbflags
& VB_LVDS
) {
624 if (sis_verbose
> 0) {
625 printf("[SiS] LVDS does not support secondary VGA\n");
629 if (sis_vbflags
& (VB_301LV
| VB_302LV
)) {
630 if (sis_verbose
> 0) {
632 ("[SiS] SiS30xLV bridge does not support secondary VGA\n");
636 sis_vbflags
= sis_vbflags
& ~(CRT2_TV
| CRT2_LCD
);
637 if (sis_vbflags
& VB_VIDEOBRIDGE
)
638 sis_vbflags
= sis_vbflags
| CRT2_VGA
;
640 sis_vbflags
= sis_vbflags
& ~(CRT2_VGA
);
643 sis_vbflags
&= ~(CRT2_TV
| CRT2_LCD
| CRT2_VGA
);
646 /* CRT2 gamma correction?? */
648 /* other force modes: */
649 /* have a 'force tv type' (svideo, composite, scart) option? */
650 /* have a 'force crt1 type' (to turn it off, etc??) */
652 /* TW: Check if CRT1 used (or needed; this eg. if no CRT2 detected) */
653 if (sis_vbflags
& VB_VIDEOBRIDGE
) {
655 /* TW: No CRT2 output? Then we NEED CRT1!
656 * We also need CRT1 if depth = 8 and bridge=LVDS|630+301B
658 if ((!(sis_vbflags
& (CRT2_VGA
| CRT2_LCD
| CRT2_TV
))) || ( /*(pScrn->bitsPerPixel == 8) && */
659 ((sis_vbflags
& (VB_LVDS
| VB_CHRONTEL
)) || ((sis_vga_engine
== SIS_300_VGA
) && (sis_vbflags
& VB_301B
))))) {
662 /* TW: No CRT2 output? Then we can't use hw overlay on CRT2 */
663 if (!(sis_vbflags
& (CRT2_VGA
| CRT2_LCD
| CRT2_TV
)))
664 sis_overlay_on_crt1
= 1;
666 } else { /* TW: no video bridge? */
668 /* Then we NEED CRT1... */
670 /* ... and can't use CRT2 for overlay output */
671 sis_overlay_on_crt1
= 1;
674 /* tvstandard options ? */
676 // determine using CRT1 or CRT2?
677 /* -> NO dualhead right now... */
678 if (sis_vbflags
& DISPTYPE_DISP2
) {
680 sis_vbflags
|= VB_DISPMODE_SINGLE
;
681 /* TW: No CRT1? Then we use the video overlay on CRT2 */
682 sis_overlay_on_crt1
= 0;
683 } else /* TW: CRT1 and CRT2 - mirror or dual head ----- */
684 sis_vbflags
|= (VB_DISPMODE_MIRROR
| DISPTYPE_CRT1
);
685 } else { /* TW: CRT1 only ------------------------------- */
686 sis_vbflags
|= (VB_DISPMODE_SINGLE
| DISPTYPE_CRT1
);
689 if (sis_verbose
> 0) {
690 printf("[SiS] Using hardware overlay on CRT%d\n",
691 sis_overlay_on_crt1
? 1 : 2);