2 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
4 * Display mode initializing code
6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
8 * If distributed as part of the Linux kernel, this code is licensed under the
11 * Otherwise, the following license terms apply:
13 * * Redistribution and use in source and binary forms, with or without
14 * * modification, are permitted provided that the following conditions
16 * * 1) Redistributions of source code must retain the above copyright
17 * * notice, this list of conditions and the following disclaimer.
18 * * 2) Redistributions in binary form must reproduce the above copyright
19 * * notice, this list of conditions and the following disclaimer in the
20 * * documentation and/or other materials provided with the distribution.
21 * * 3) The name of the author may not be used to endorse or promote products
22 * * derived from this software without specific prior written permission.
24 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * Author: Thomas Winischhofer <thomas@winischhofer.net>
39 #include <linux/module.h>
40 #include <linux/kernel.h>
41 #include <linux/errno.h>
42 #include <linux/poll.h>
43 #include <linux/spinlock.h>
47 #ifdef INCL_SISUSB_CON
49 #include "sisusb_init.h"
51 /*********************************************/
52 /* POINTER INITIALIZATION */
53 /*********************************************/
55 static void SiSUSB_InitPtr(struct SiS_Private
*SiS_Pr
)
57 SiS_Pr
->SiS_ModeResInfo
= SiSUSB_ModeResInfo
;
58 SiS_Pr
->SiS_StandTable
= SiSUSB_StandTable
;
60 SiS_Pr
->SiS_SModeIDTable
= SiSUSB_SModeIDTable
;
61 SiS_Pr
->SiS_EModeIDTable
= SiSUSB_EModeIDTable
;
62 SiS_Pr
->SiS_RefIndex
= SiSUSB_RefIndex
;
63 SiS_Pr
->SiS_CRT1Table
= SiSUSB_CRT1Table
;
65 SiS_Pr
->SiS_VCLKData
= SiSUSB_VCLKData
;
68 /*********************************************/
69 /* HELPER: SetReg, GetReg */
70 /*********************************************/
73 SiS_SetReg(struct SiS_Private
*SiS_Pr
, unsigned long port
,
74 unsigned short index
, unsigned short data
)
76 sisusb_setidxreg(SiS_Pr
->sisusb
, port
, index
, data
);
80 SiS_SetRegByte(struct SiS_Private
*SiS_Pr
, unsigned long port
,
83 sisusb_setreg(SiS_Pr
->sisusb
, port
, data
);
87 SiS_GetReg(struct SiS_Private
*SiS_Pr
, unsigned long port
, unsigned short index
)
91 sisusb_getidxreg(SiS_Pr
->sisusb
, port
, index
, &data
);
97 SiS_GetRegByte(struct SiS_Private
*SiS_Pr
, unsigned long port
)
101 sisusb_getreg(SiS_Pr
->sisusb
, port
, &data
);
107 SiS_SetRegANDOR(struct SiS_Private
*SiS_Pr
, unsigned long port
,
108 unsigned short index
, unsigned short DataAND
,
109 unsigned short DataOR
)
111 sisusb_setidxregandor(SiS_Pr
->sisusb
, port
, index
, DataAND
, DataOR
);
115 SiS_SetRegAND(struct SiS_Private
*SiS_Pr
, unsigned long port
,
116 unsigned short index
, unsigned short DataAND
)
118 sisusb_setidxregand(SiS_Pr
->sisusb
, port
, index
, DataAND
);
122 SiS_SetRegOR(struct SiS_Private
*SiS_Pr
, unsigned long port
,
123 unsigned short index
, unsigned short DataOR
)
125 sisusb_setidxregor(SiS_Pr
->sisusb
, port
, index
, DataOR
);
128 /*********************************************/
129 /* HELPER: DisplayOn, DisplayOff */
130 /*********************************************/
132 static void SiS_DisplayOn(struct SiS_Private
*SiS_Pr
)
134 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x01, 0xDF);
137 /*********************************************/
138 /* HELPER: Init Port Addresses */
139 /*********************************************/
141 static void SiSUSBRegInit(struct SiS_Private
*SiS_Pr
, unsigned long BaseAddr
)
143 SiS_Pr
->SiS_P3c4
= BaseAddr
+ 0x14;
144 SiS_Pr
->SiS_P3d4
= BaseAddr
+ 0x24;
145 SiS_Pr
->SiS_P3c0
= BaseAddr
+ 0x10;
146 SiS_Pr
->SiS_P3ce
= BaseAddr
+ 0x1e;
147 SiS_Pr
->SiS_P3c2
= BaseAddr
+ 0x12;
148 SiS_Pr
->SiS_P3ca
= BaseAddr
+ 0x1a;
149 SiS_Pr
->SiS_P3c6
= BaseAddr
+ 0x16;
150 SiS_Pr
->SiS_P3c7
= BaseAddr
+ 0x17;
151 SiS_Pr
->SiS_P3c8
= BaseAddr
+ 0x18;
152 SiS_Pr
->SiS_P3c9
= BaseAddr
+ 0x19;
153 SiS_Pr
->SiS_P3cb
= BaseAddr
+ 0x1b;
154 SiS_Pr
->SiS_P3cc
= BaseAddr
+ 0x1c;
155 SiS_Pr
->SiS_P3cd
= BaseAddr
+ 0x1d;
156 SiS_Pr
->SiS_P3da
= BaseAddr
+ 0x2a;
157 SiS_Pr
->SiS_Part1Port
= BaseAddr
+ SIS_CRT2_PORT_04
;
160 /*********************************************/
161 /* HELPER: GetSysFlags */
162 /*********************************************/
164 static void SiS_GetSysFlags(struct SiS_Private
*SiS_Pr
)
166 SiS_Pr
->SiS_MyCR63
= 0x63;
169 /*********************************************/
170 /* HELPER: Init PCI & Engines */
171 /*********************************************/
173 static void SiSInitPCIetc(struct SiS_Private
*SiS_Pr
)
175 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x20, 0xa1);
176 /* - Enable 2D (0x40)
178 * - Enable 3D vertex command fetch (0x10)
179 * - Enable 3D command parser (0x08)
180 * - Enable 3D G/L transformation engine (0x80)
182 SiS_SetRegOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x1E, 0xDA);
185 /*********************************************/
186 /* HELPER: SET SEGMENT REGISTERS */
187 /*********************************************/
189 static void SiS_SetSegRegLower(struct SiS_Private
*SiS_Pr
, unsigned short value
)
194 temp
= SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cb
) & 0xf0;
195 temp
|= (value
>> 4);
196 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cb
, temp
);
197 temp
= SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cd
) & 0xf0;
198 temp
|= (value
& 0x0f);
199 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cd
, temp
);
202 static void SiS_SetSegRegUpper(struct SiS_Private
*SiS_Pr
, unsigned short value
)
207 temp
= SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cb
) & 0x0f;
208 temp
|= (value
& 0xf0);
209 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cb
, temp
);
210 temp
= SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cd
) & 0x0f;
211 temp
|= (value
<< 4);
212 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cd
, temp
);
215 static void SiS_SetSegmentReg(struct SiS_Private
*SiS_Pr
, unsigned short value
)
217 SiS_SetSegRegLower(SiS_Pr
, value
);
218 SiS_SetSegRegUpper(SiS_Pr
, value
);
221 static void SiS_ResetSegmentReg(struct SiS_Private
*SiS_Pr
)
223 SiS_SetSegmentReg(SiS_Pr
, 0);
227 SiS_SetSegmentRegOver(struct SiS_Private
*SiS_Pr
, unsigned short value
)
229 unsigned short temp
= value
>> 8;
233 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x1d, temp
);
234 SiS_SetSegmentReg(SiS_Pr
, value
);
237 static void SiS_ResetSegmentRegOver(struct SiS_Private
*SiS_Pr
)
239 SiS_SetSegmentRegOver(SiS_Pr
, 0);
242 static void SiS_ResetSegmentRegisters(struct SiS_Private
*SiS_Pr
)
244 SiS_ResetSegmentReg(SiS_Pr
);
245 SiS_ResetSegmentRegOver(SiS_Pr
);
248 /*********************************************/
249 /* HELPER: SearchModeID */
250 /*********************************************/
253 SiS_SearchModeID(struct SiS_Private
*SiS_Pr
, unsigned short *ModeNo
,
254 unsigned short *ModeIdIndex
)
256 if ((*ModeNo
) <= 0x13) {
258 if ((*ModeNo
) != 0x03)
265 for (*ModeIdIndex
= 0;; (*ModeIdIndex
)++) {
267 if (SiS_Pr
->SiS_EModeIDTable
[*ModeIdIndex
].Ext_ModeID
==
271 if (SiS_Pr
->SiS_EModeIDTable
[*ModeIdIndex
].Ext_ModeID
==
281 /*********************************************/
282 /* HELPER: ENABLE CRT1 */
283 /*********************************************/
285 static void SiS_HandleCRT1(struct SiS_Private
*SiS_Pr
)
287 /* Enable CRT1 gating */
288 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3d4
, SiS_Pr
->SiS_MyCR63
, 0xbf);
291 /*********************************************/
292 /* HELPER: GetColorDepth */
293 /*********************************************/
295 static unsigned short
296 SiS_GetColorDepth(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
297 unsigned short ModeIdIndex
)
299 static const unsigned short ColorDepth
[6] = { 1, 2, 4, 4, 6, 8 };
300 unsigned short modeflag
;
303 if (ModeNo
<= 0x13) {
304 modeflag
= SiS_Pr
->SiS_SModeIDTable
[ModeIdIndex
].St_ModeFlag
;
306 modeflag
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].Ext_ModeFlag
;
309 index
= (modeflag
& ModeTypeMask
) - ModeEGA
;
312 return ColorDepth
[index
];
315 /*********************************************/
316 /* HELPER: GetOffset */
317 /*********************************************/
319 static unsigned short
320 SiS_GetOffset(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
321 unsigned short ModeIdIndex
, unsigned short rrti
)
323 unsigned short xres
, temp
, colordepth
, infoflag
;
325 infoflag
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_InfoFlag
;
326 xres
= SiS_Pr
->SiS_RefIndex
[rrti
].XRes
;
328 colordepth
= SiS_GetColorDepth(SiS_Pr
, ModeNo
, ModeIdIndex
);
332 if (infoflag
& InterlaceMode
)
338 temp
+= (colordepth
>> 1);
343 /*********************************************/
345 /*********************************************/
348 SiS_SetSeqRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
350 unsigned char SRdata
;
353 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x00, 0x03);
355 SRdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].SR
[0] | 0x20;
356 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x01, SRdata
);
358 for (i
= 2; i
<= 4; i
++) {
359 SRdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].SR
[i
- 1];
360 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, i
, SRdata
);
364 /*********************************************/
366 /*********************************************/
369 SiS_SetMiscRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
371 unsigned char Miscdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].MISC
;
373 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c2
, Miscdata
);
376 /*********************************************/
378 /*********************************************/
381 SiS_SetCRTCRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
383 unsigned char CRTCdata
;
386 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x11, 0x7f);
388 for (i
= 0; i
<= 0x18; i
++) {
389 CRTCdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].CRTC
[i
];
390 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, i
, CRTCdata
);
394 /*********************************************/
396 /*********************************************/
399 SiS_SetATTRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
401 unsigned char ARdata
;
404 for (i
= 0; i
<= 0x13; i
++) {
405 ARdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].ATTR
[i
];
406 SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3da
);
407 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, i
);
408 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, ARdata
);
410 SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3da
);
411 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, 0x14);
412 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, 0x00);
414 SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3da
);
415 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, 0x20);
416 SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3da
);
419 /*********************************************/
421 /*********************************************/
424 SiS_SetGRCRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
426 unsigned char GRdata
;
429 for (i
= 0; i
<= 0x08; i
++) {
430 GRdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].GRC
[i
];
431 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3ce
, i
, GRdata
);
434 if (SiS_Pr
->SiS_ModeType
> ModeVGA
) {
435 /* 256 color disable */
436 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3ce
, 0x05, 0xBF);
440 /*********************************************/
441 /* CLEAR EXTENDED REGISTERS */
442 /*********************************************/
444 static void SiS_ClearExt1Regs(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
)
448 for (i
= 0x0A; i
<= 0x0E; i
++) {
449 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, i
, 0x00);
452 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x37, 0xFE);
455 /*********************************************/
457 /*********************************************/
459 static unsigned short
460 SiS_GetRatePtr(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
461 unsigned short ModeIdIndex
)
463 unsigned short rrti
, i
, index
, temp
;
468 index
= SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x33) & 0x0F;
472 rrti
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].REFindex
;
473 ModeNo
= SiS_Pr
->SiS_RefIndex
[rrti
].ModeID
;
477 if (SiS_Pr
->SiS_RefIndex
[rrti
+ i
].ModeID
!= ModeNo
)
481 SiS_Pr
->SiS_RefIndex
[rrti
+ i
].Ext_InfoFlag
& ModeTypeMask
;
482 if (temp
< SiS_Pr
->SiS_ModeType
)
487 } while (index
!= 0xFFFF);
494 /*********************************************/
496 /*********************************************/
498 static void SiS_SetCRT1Sync(struct SiS_Private
*SiS_Pr
, unsigned short rrti
)
500 unsigned short sync
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_InfoFlag
>> 8;
503 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c2
, sync
);
506 /*********************************************/
508 /*********************************************/
511 SiS_SetCRT1CRTC(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
512 unsigned short ModeIdIndex
, unsigned short rrti
)
515 unsigned short temp
, i
, j
, modeflag
;
517 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x11, 0x7f);
519 modeflag
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].Ext_ModeFlag
;
521 index
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_CRT1CRTC
;
523 for (i
= 0, j
= 0; i
<= 7; i
++, j
++) {
524 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, j
,
525 SiS_Pr
->SiS_CRT1Table
[index
].CR
[i
]);
527 for (j
= 0x10; i
<= 10; i
++, j
++) {
528 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, j
,
529 SiS_Pr
->SiS_CRT1Table
[index
].CR
[i
]);
531 for (j
= 0x15; i
<= 12; i
++, j
++) {
532 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, j
,
533 SiS_Pr
->SiS_CRT1Table
[index
].CR
[i
]);
535 for (j
= 0x0A; i
<= 15; i
++, j
++) {
536 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, j
,
537 SiS_Pr
->SiS_CRT1Table
[index
].CR
[i
]);
540 temp
= SiS_Pr
->SiS_CRT1Table
[index
].CR
[16] & 0xE0;
541 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0E, temp
);
543 temp
= ((SiS_Pr
->SiS_CRT1Table
[index
].CR
[16]) & 0x01) << 5;
544 if (modeflag
& DoubleScanMode
)
546 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x09, 0x5F, temp
);
548 if (SiS_Pr
->SiS_ModeType
> ModeVGA
)
549 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x14, 0x4F);
552 /*********************************************/
554 /*********************************************/
555 /* (partly overruled by SetPitch() in XF86) */
556 /*********************************************/
559 SiS_SetCRT1Offset(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
560 unsigned short ModeIdIndex
, unsigned short rrti
)
562 unsigned short du
= SiS_GetOffset(SiS_Pr
, ModeNo
, ModeIdIndex
, rrti
);
563 unsigned short infoflag
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_InfoFlag
;
566 temp
= (du
>> 8) & 0x0f;
567 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0E, 0xF0, temp
);
569 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x13, (du
& 0xFF));
571 if (infoflag
& InterlaceMode
)
575 temp
= (du
>> 8) & 0xff;
579 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x10, temp
);
582 /*********************************************/
584 /*********************************************/
587 SiS_SetCRT1VCLK(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
590 unsigned short index
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_CRTVCLK
;
591 unsigned short clka
= SiS_Pr
->SiS_VCLKData
[index
].SR2B
;
592 unsigned short clkb
= SiS_Pr
->SiS_VCLKData
[index
].SR2C
;
594 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x31, 0xCF);
596 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x2B, clka
);
597 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x2C, clkb
);
598 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x2D, 0x01);
601 /*********************************************/
603 /*********************************************/
606 SiS_SetCRT1FIFO_310(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
609 unsigned short modeflag
= SiS_Pr
->SiS_EModeIDTable
[mi
].Ext_ModeFlag
;
611 /* disable auto-threshold */
612 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x3D, 0xFE);
614 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x08, 0xAE);
615 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x09, 0xF0);
620 if ((!(modeflag
& DoubleScanMode
)) || (!(modeflag
& HalfDCLK
))) {
621 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x08, 0x34);
622 SiS_SetRegOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x3D, 0x01);
626 /*********************************************/
628 /*********************************************/
631 SiS_SetVCLKState(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
634 unsigned short data
= 0, VCLK
= 0, index
= 0;
637 index
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_CRTVCLK
;
638 VCLK
= SiS_Pr
->SiS_VCLKData
[index
].CLOCK
;
643 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x32, 0xf3, data
);
646 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x1f, 0xe7);
652 else if (VCLK
>= 160)
654 else if (VCLK
>= 135)
657 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x07, 0xF8, data
);
661 SiS_SetCRT1ModeRegs(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
662 unsigned short ModeIdIndex
, unsigned short rrti
)
664 unsigned short data
, infoflag
= 0, modeflag
;
667 modeflag
= SiS_Pr
->SiS_SModeIDTable
[ModeIdIndex
].St_ModeFlag
;
669 modeflag
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].Ext_ModeFlag
;
670 infoflag
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_InfoFlag
;
674 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x1F, 0x3F);
678 if (SiS_Pr
->SiS_ModeType
> ModeEGA
) {
680 data
|= ((SiS_Pr
->SiS_ModeType
- ModeVGA
) << 2);
682 if (infoflag
& InterlaceMode
)
685 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x06, 0xC0, data
);
688 if (infoflag
& InterlaceMode
) {
689 /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
691 (SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x04) |
692 ((SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0b) & 0xc0) << 2))
695 (SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x00) |
696 ((SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0b) & 0x03) << 8))
698 data
= hrs
- (hto
>> 1) + 3;
700 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x19, (data
& 0xFF));
701 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x1a, 0xFC, (data
>> 8));
703 if (modeflag
& HalfDCLK
)
704 SiS_SetRegOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x01, 0x08);
707 if (modeflag
& LineCompareOff
)
709 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0F, 0xB7, data
);
711 if ((SiS_Pr
->SiS_ModeType
== ModeEGA
) && (ModeNo
> 0x13))
712 SiS_SetRegOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0F, 0x40);
714 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x31, 0xfb);
717 if (SiS_Pr
->SiS_ModeType
!= ModeText
) {
719 if (SiS_Pr
->SiS_ModeType
!= ModeEGA
)
722 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x21, 0x1F, data
);
724 SiS_SetVCLKState(SiS_Pr
, ModeNo
, rrti
);
726 if (SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x31) & 0x40)
727 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x52, 0x2c);
729 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x52, 0x6c);
732 /*********************************************/
734 /*********************************************/
737 SiS_WriteDAC(struct SiS_Private
*SiS_Pr
, unsigned long DACData
,
738 unsigned short shiftflag
, unsigned short dl
, unsigned short ah
,
739 unsigned short al
, unsigned short dh
)
741 unsigned short d1
, d2
, d3
;
759 SiS_SetRegByte(SiS_Pr
, DACData
, (d1
<< shiftflag
));
760 SiS_SetRegByte(SiS_Pr
, DACData
, (d2
<< shiftflag
));
761 SiS_SetRegByte(SiS_Pr
, DACData
, (d3
<< shiftflag
));
765 SiS_LoadDAC(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
768 unsigned short data
, data2
, time
, i
, j
, k
, m
, n
, o
;
769 unsigned short si
, di
, bx
, sf
;
770 unsigned long DACAddr
, DACData
;
771 const unsigned char *table
= NULL
;
774 data
= SiS_Pr
->SiS_SModeIDTable
[mi
].St_ModeFlag
;
776 data
= SiS_Pr
->SiS_EModeIDTable
[mi
].Ext_ModeFlag
;
783 else if (data
== 0x08)
785 else if (data
== 0x10)
793 DACAddr
= SiS_Pr
->SiS_P3c8
;
794 DACData
= SiS_Pr
->SiS_P3c9
;
796 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c6
, 0xFF);
798 SiS_SetRegByte(SiS_Pr
, DACAddr
, 0x00);
800 for (i
= 0; i
< j
; i
++) {
802 for (k
= 0; k
< 3; k
++) {
808 SiS_SetRegByte(SiS_Pr
, DACData
, (data2
<< sf
));
814 for (i
= 16; i
< 32; i
++) {
815 data
= table
[i
] << sf
;
816 for (k
= 0; k
< 3; k
++)
817 SiS_SetRegByte(SiS_Pr
, DACData
, data
);
820 for (m
= 0; m
< 9; m
++) {
823 for (n
= 0; n
< 3; n
++) {
824 for (o
= 0; o
< 5; o
++) {
825 SiS_WriteDAC(SiS_Pr
, DACData
, sf
, n
,
826 table
[di
], table
[bx
],
831 for (o
= 0; o
< 3; o
++) {
832 SiS_WriteDAC(SiS_Pr
, DACData
, sf
, n
,
833 table
[di
], table
[si
],
843 /*********************************************/
844 /* SET CRT1 REGISTER GROUP */
845 /*********************************************/
848 SiS_SetCRT1Group(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
849 unsigned short ModeIdIndex
)
851 unsigned short StandTableIndex
, rrti
;
853 SiS_Pr
->SiS_CRT1Mode
= ModeNo
;
860 SiS_ResetSegmentRegisters(SiS_Pr
);
861 SiS_SetSeqRegs(SiS_Pr
, StandTableIndex
);
862 SiS_SetMiscRegs(SiS_Pr
, StandTableIndex
);
863 SiS_SetCRTCRegs(SiS_Pr
, StandTableIndex
);
864 SiS_SetATTRegs(SiS_Pr
, StandTableIndex
);
865 SiS_SetGRCRegs(SiS_Pr
, StandTableIndex
);
866 SiS_ClearExt1Regs(SiS_Pr
, ModeNo
);
868 rrti
= SiS_GetRatePtr(SiS_Pr
, ModeNo
, ModeIdIndex
);
870 if (rrti
!= 0xFFFF) {
871 SiS_SetCRT1Sync(SiS_Pr
, rrti
);
872 SiS_SetCRT1CRTC(SiS_Pr
, ModeNo
, ModeIdIndex
, rrti
);
873 SiS_SetCRT1Offset(SiS_Pr
, ModeNo
, ModeIdIndex
, rrti
);
874 SiS_SetCRT1VCLK(SiS_Pr
, ModeNo
, rrti
);
877 SiS_SetCRT1FIFO_310(SiS_Pr
, ModeNo
, ModeIdIndex
);
879 SiS_SetCRT1ModeRegs(SiS_Pr
, ModeNo
, ModeIdIndex
, rrti
);
881 SiS_LoadDAC(SiS_Pr
, ModeNo
, ModeIdIndex
);
883 SiS_DisplayOn(SiS_Pr
);
886 /*********************************************/
888 /*********************************************/
890 int SiSUSBSetMode(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
)
892 unsigned short ModeIdIndex
;
893 unsigned long BaseAddr
= SiS_Pr
->IOAddress
;
895 SiSUSB_InitPtr(SiS_Pr
);
896 SiSUSBRegInit(SiS_Pr
, BaseAddr
);
897 SiS_GetSysFlags(SiS_Pr
);
899 if (!(SiS_SearchModeID(SiS_Pr
, &ModeNo
, &ModeIdIndex
)))
902 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x05, 0x86);
904 SiSInitPCIetc(SiS_Pr
);
908 SiS_Pr
->SiS_ModeType
=
909 SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].Ext_ModeFlag
& ModeTypeMask
;
911 SiS_Pr
->SiS_SetFlag
= LowModeTests
;
913 /* Set mode on CRT1 */
914 SiS_SetCRT1Group(SiS_Pr
, ModeNo
, ModeIdIndex
);
916 SiS_HandleCRT1(SiS_Pr
);
918 SiS_DisplayOn(SiS_Pr
);
919 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c6
, 0xFF);
921 /* Store mode number */
922 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x34, ModeNo
);
927 int SiSUSBSetVESAMode(struct SiS_Private
*SiS_Pr
, unsigned short VModeNo
)
929 unsigned short ModeNo
= 0;
932 SiSUSB_InitPtr(SiS_Pr
);
934 if (VModeNo
== 0x03) {
943 if (SiS_Pr
->SiS_EModeIDTable
[i
].Ext_VESAID
== VModeNo
) {
944 ModeNo
= SiS_Pr
->SiS_EModeIDTable
[i
].Ext_ModeID
;
948 } while (SiS_Pr
->SiS_EModeIDTable
[i
++].Ext_ModeID
!= 0xff);
955 return SiSUSBSetMode(SiS_Pr
, ModeNo
);
958 #endif /* INCL_SISUSB_CON */