]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/usb/misc/sisusbvga/sisusb_init.c
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/init.h>
44 #include <linux/slab.h>
45 #include <linux/spinlock.h>
49 #ifdef INCL_SISUSB_CON
51 #include "sisusb_init.h"
53 /*********************************************/
54 /* POINTER INITIALIZATION */
55 /*********************************************/
57 static void SiSUSB_InitPtr(struct SiS_Private
*SiS_Pr
)
59 SiS_Pr
->SiS_ModeResInfo
= SiSUSB_ModeResInfo
;
60 SiS_Pr
->SiS_StandTable
= SiSUSB_StandTable
;
62 SiS_Pr
->SiS_SModeIDTable
= SiSUSB_SModeIDTable
;
63 SiS_Pr
->SiS_EModeIDTable
= SiSUSB_EModeIDTable
;
64 SiS_Pr
->SiS_RefIndex
= SiSUSB_RefIndex
;
65 SiS_Pr
->SiS_CRT1Table
= SiSUSB_CRT1Table
;
67 SiS_Pr
->SiS_VCLKData
= SiSUSB_VCLKData
;
70 /*********************************************/
71 /* HELPER: SetReg, GetReg */
72 /*********************************************/
75 SiS_SetReg(struct SiS_Private
*SiS_Pr
, unsigned long port
,
76 unsigned short index
, unsigned short data
)
78 sisusb_setidxreg(SiS_Pr
->sisusb
, port
, index
, data
);
82 SiS_SetRegByte(struct SiS_Private
*SiS_Pr
, unsigned long port
,
85 sisusb_setreg(SiS_Pr
->sisusb
, port
, data
);
89 SiS_GetReg(struct SiS_Private
*SiS_Pr
, unsigned long port
, unsigned short index
)
93 sisusb_getidxreg(SiS_Pr
->sisusb
, port
, index
, &data
);
99 SiS_GetRegByte(struct SiS_Private
*SiS_Pr
, unsigned long port
)
103 sisusb_getreg(SiS_Pr
->sisusb
, port
, &data
);
109 SiS_SetRegANDOR(struct SiS_Private
*SiS_Pr
, unsigned long port
,
110 unsigned short index
, unsigned short DataAND
,
111 unsigned short DataOR
)
113 sisusb_setidxregandor(SiS_Pr
->sisusb
, port
, index
, DataAND
, DataOR
);
117 SiS_SetRegAND(struct SiS_Private
*SiS_Pr
, unsigned long port
,
118 unsigned short index
, unsigned short DataAND
)
120 sisusb_setidxregand(SiS_Pr
->sisusb
, port
, index
, DataAND
);
124 SiS_SetRegOR(struct SiS_Private
*SiS_Pr
, unsigned long port
,
125 unsigned short index
, unsigned short DataOR
)
127 sisusb_setidxregor(SiS_Pr
->sisusb
, port
, index
, DataOR
);
130 /*********************************************/
131 /* HELPER: DisplayOn, DisplayOff */
132 /*********************************************/
134 static void SiS_DisplayOn(struct SiS_Private
*SiS_Pr
)
136 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x01, 0xDF);
139 /*********************************************/
140 /* HELPER: Init Port Addresses */
141 /*********************************************/
143 static void SiSUSBRegInit(struct SiS_Private
*SiS_Pr
, unsigned long BaseAddr
)
145 SiS_Pr
->SiS_P3c4
= BaseAddr
+ 0x14;
146 SiS_Pr
->SiS_P3d4
= BaseAddr
+ 0x24;
147 SiS_Pr
->SiS_P3c0
= BaseAddr
+ 0x10;
148 SiS_Pr
->SiS_P3ce
= BaseAddr
+ 0x1e;
149 SiS_Pr
->SiS_P3c2
= BaseAddr
+ 0x12;
150 SiS_Pr
->SiS_P3ca
= BaseAddr
+ 0x1a;
151 SiS_Pr
->SiS_P3c6
= BaseAddr
+ 0x16;
152 SiS_Pr
->SiS_P3c7
= BaseAddr
+ 0x17;
153 SiS_Pr
->SiS_P3c8
= BaseAddr
+ 0x18;
154 SiS_Pr
->SiS_P3c9
= BaseAddr
+ 0x19;
155 SiS_Pr
->SiS_P3cb
= BaseAddr
+ 0x1b;
156 SiS_Pr
->SiS_P3cc
= BaseAddr
+ 0x1c;
157 SiS_Pr
->SiS_P3cd
= BaseAddr
+ 0x1d;
158 SiS_Pr
->SiS_P3da
= BaseAddr
+ 0x2a;
159 SiS_Pr
->SiS_Part1Port
= BaseAddr
+ SIS_CRT2_PORT_04
;
162 /*********************************************/
163 /* HELPER: GetSysFlags */
164 /*********************************************/
166 static void SiS_GetSysFlags(struct SiS_Private
*SiS_Pr
)
168 SiS_Pr
->SiS_MyCR63
= 0x63;
171 /*********************************************/
172 /* HELPER: Init PCI & Engines */
173 /*********************************************/
175 static void SiSInitPCIetc(struct SiS_Private
*SiS_Pr
)
177 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x20, 0xa1);
178 /* - Enable 2D (0x40)
180 * - Enable 3D vertex command fetch (0x10)
181 * - Enable 3D command parser (0x08)
182 * - Enable 3D G/L transformation engine (0x80)
184 SiS_SetRegOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x1E, 0xDA);
187 /*********************************************/
188 /* HELPER: SET SEGMENT REGISTERS */
189 /*********************************************/
191 static void SiS_SetSegRegLower(struct SiS_Private
*SiS_Pr
, unsigned short value
)
196 temp
= SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cb
) & 0xf0;
197 temp
|= (value
>> 4);
198 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cb
, temp
);
199 temp
= SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cd
) & 0xf0;
200 temp
|= (value
& 0x0f);
201 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cd
, temp
);
204 static void SiS_SetSegRegUpper(struct SiS_Private
*SiS_Pr
, unsigned short value
)
209 temp
= SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cb
) & 0x0f;
210 temp
|= (value
& 0xf0);
211 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cb
, temp
);
212 temp
= SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cd
) & 0x0f;
213 temp
|= (value
<< 4);
214 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3cd
, temp
);
217 static void SiS_SetSegmentReg(struct SiS_Private
*SiS_Pr
, unsigned short value
)
219 SiS_SetSegRegLower(SiS_Pr
, value
);
220 SiS_SetSegRegUpper(SiS_Pr
, value
);
223 static void SiS_ResetSegmentReg(struct SiS_Private
*SiS_Pr
)
225 SiS_SetSegmentReg(SiS_Pr
, 0);
229 SiS_SetSegmentRegOver(struct SiS_Private
*SiS_Pr
, unsigned short value
)
231 unsigned short temp
= value
>> 8;
235 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x1d, temp
);
236 SiS_SetSegmentReg(SiS_Pr
, value
);
239 static void SiS_ResetSegmentRegOver(struct SiS_Private
*SiS_Pr
)
241 SiS_SetSegmentRegOver(SiS_Pr
, 0);
244 static void SiS_ResetSegmentRegisters(struct SiS_Private
*SiS_Pr
)
246 SiS_ResetSegmentReg(SiS_Pr
);
247 SiS_ResetSegmentRegOver(SiS_Pr
);
250 /*********************************************/
251 /* HELPER: SearchModeID */
252 /*********************************************/
255 SiS_SearchModeID(struct SiS_Private
*SiS_Pr
, unsigned short *ModeNo
,
256 unsigned short *ModeIdIndex
)
258 if ((*ModeNo
) <= 0x13) {
260 if ((*ModeNo
) != 0x03)
267 for (*ModeIdIndex
= 0;; (*ModeIdIndex
)++) {
269 if (SiS_Pr
->SiS_EModeIDTable
[*ModeIdIndex
].Ext_ModeID
==
273 if (SiS_Pr
->SiS_EModeIDTable
[*ModeIdIndex
].Ext_ModeID
==
283 /*********************************************/
284 /* HELPER: ENABLE CRT1 */
285 /*********************************************/
287 static void SiS_HandleCRT1(struct SiS_Private
*SiS_Pr
)
289 /* Enable CRT1 gating */
290 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3d4
, SiS_Pr
->SiS_MyCR63
, 0xbf);
293 /*********************************************/
294 /* HELPER: GetColorDepth */
295 /*********************************************/
297 static unsigned short
298 SiS_GetColorDepth(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
299 unsigned short ModeIdIndex
)
301 static const unsigned short ColorDepth
[6] = { 1, 2, 4, 4, 6, 8 };
302 unsigned short modeflag
;
305 if (ModeNo
<= 0x13) {
306 modeflag
= SiS_Pr
->SiS_SModeIDTable
[ModeIdIndex
].St_ModeFlag
;
308 modeflag
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].Ext_ModeFlag
;
311 index
= (modeflag
& ModeTypeMask
) - ModeEGA
;
314 return ColorDepth
[index
];
317 /*********************************************/
318 /* HELPER: GetOffset */
319 /*********************************************/
321 static unsigned short
322 SiS_GetOffset(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
323 unsigned short ModeIdIndex
, unsigned short rrti
)
325 unsigned short xres
, temp
, colordepth
, infoflag
;
327 infoflag
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_InfoFlag
;
328 xres
= SiS_Pr
->SiS_RefIndex
[rrti
].XRes
;
330 colordepth
= SiS_GetColorDepth(SiS_Pr
, ModeNo
, ModeIdIndex
);
334 if (infoflag
& InterlaceMode
)
340 temp
+= (colordepth
>> 1);
345 /*********************************************/
347 /*********************************************/
350 SiS_SetSeqRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
352 unsigned char SRdata
;
355 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x00, 0x03);
357 SRdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].SR
[0] | 0x20;
358 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x01, SRdata
);
360 for (i
= 2; i
<= 4; i
++) {
361 SRdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].SR
[i
- 1];
362 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, i
, SRdata
);
366 /*********************************************/
368 /*********************************************/
371 SiS_SetMiscRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
373 unsigned char Miscdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].MISC
;
375 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c2
, Miscdata
);
378 /*********************************************/
380 /*********************************************/
383 SiS_SetCRTCRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
385 unsigned char CRTCdata
;
388 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x11, 0x7f);
390 for (i
= 0; i
<= 0x18; i
++) {
391 CRTCdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].CRTC
[i
];
392 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, i
, CRTCdata
);
396 /*********************************************/
398 /*********************************************/
401 SiS_SetATTRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
403 unsigned char ARdata
;
406 for (i
= 0; i
<= 0x13; i
++) {
407 ARdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].ATTR
[i
];
408 SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3da
);
409 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, i
);
410 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, ARdata
);
412 SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3da
);
413 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, 0x14);
414 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, 0x00);
416 SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3da
);
417 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c0
, 0x20);
418 SiS_GetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3da
);
421 /*********************************************/
423 /*********************************************/
426 SiS_SetGRCRegs(struct SiS_Private
*SiS_Pr
, unsigned short StandTableIndex
)
428 unsigned char GRdata
;
431 for (i
= 0; i
<= 0x08; i
++) {
432 GRdata
= SiS_Pr
->SiS_StandTable
[StandTableIndex
].GRC
[i
];
433 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3ce
, i
, GRdata
);
436 if (SiS_Pr
->SiS_ModeType
> ModeVGA
) {
437 /* 256 color disable */
438 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3ce
, 0x05, 0xBF);
442 /*********************************************/
443 /* CLEAR EXTENDED REGISTERS */
444 /*********************************************/
446 static void SiS_ClearExt1Regs(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
)
450 for (i
= 0x0A; i
<= 0x0E; i
++) {
451 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, i
, 0x00);
454 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x37, 0xFE);
457 /*********************************************/
459 /*********************************************/
461 static unsigned short
462 SiS_GetRatePtr(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
463 unsigned short ModeIdIndex
)
465 unsigned short rrti
, i
, index
, temp
;
470 index
= SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x33) & 0x0F;
474 rrti
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].REFindex
;
475 ModeNo
= SiS_Pr
->SiS_RefIndex
[rrti
].ModeID
;
479 if (SiS_Pr
->SiS_RefIndex
[rrti
+ i
].ModeID
!= ModeNo
)
483 SiS_Pr
->SiS_RefIndex
[rrti
+ i
].Ext_InfoFlag
& ModeTypeMask
;
484 if (temp
< SiS_Pr
->SiS_ModeType
)
489 } while (index
!= 0xFFFF);
496 /*********************************************/
498 /*********************************************/
500 static void SiS_SetCRT1Sync(struct SiS_Private
*SiS_Pr
, unsigned short rrti
)
502 unsigned short sync
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_InfoFlag
>> 8;
505 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c2
, sync
);
508 /*********************************************/
510 /*********************************************/
513 SiS_SetCRT1CRTC(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
514 unsigned short ModeIdIndex
, unsigned short rrti
)
517 unsigned short temp
, i
, j
, modeflag
;
519 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x11, 0x7f);
521 modeflag
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].Ext_ModeFlag
;
523 index
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_CRT1CRTC
;
525 for (i
= 0, j
= 0; i
<= 7; i
++, j
++) {
526 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, j
,
527 SiS_Pr
->SiS_CRT1Table
[index
].CR
[i
]);
529 for (j
= 0x10; i
<= 10; i
++, j
++) {
530 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, j
,
531 SiS_Pr
->SiS_CRT1Table
[index
].CR
[i
]);
533 for (j
= 0x15; i
<= 12; i
++, j
++) {
534 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, j
,
535 SiS_Pr
->SiS_CRT1Table
[index
].CR
[i
]);
537 for (j
= 0x0A; i
<= 15; i
++, j
++) {
538 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, j
,
539 SiS_Pr
->SiS_CRT1Table
[index
].CR
[i
]);
542 temp
= SiS_Pr
->SiS_CRT1Table
[index
].CR
[16] & 0xE0;
543 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0E, temp
);
545 temp
= ((SiS_Pr
->SiS_CRT1Table
[index
].CR
[16]) & 0x01) << 5;
546 if (modeflag
& DoubleScanMode
)
548 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x09, 0x5F, temp
);
550 if (SiS_Pr
->SiS_ModeType
> ModeVGA
)
551 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x14, 0x4F);
554 /*********************************************/
556 /*********************************************/
557 /* (partly overruled by SetPitch() in XF86) */
558 /*********************************************/
561 SiS_SetCRT1Offset(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
562 unsigned short ModeIdIndex
, unsigned short rrti
)
564 unsigned short du
= SiS_GetOffset(SiS_Pr
, ModeNo
, ModeIdIndex
, rrti
);
565 unsigned short infoflag
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_InfoFlag
;
568 temp
= (du
>> 8) & 0x0f;
569 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0E, 0xF0, temp
);
571 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x13, (du
& 0xFF));
573 if (infoflag
& InterlaceMode
)
577 temp
= (du
>> 8) & 0xff;
581 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x10, temp
);
584 /*********************************************/
586 /*********************************************/
589 SiS_SetCRT1VCLK(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
592 unsigned short index
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_CRTVCLK
;
593 unsigned short clka
= SiS_Pr
->SiS_VCLKData
[index
].SR2B
;
594 unsigned short clkb
= SiS_Pr
->SiS_VCLKData
[index
].SR2C
;
596 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x31, 0xCF);
598 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x2B, clka
);
599 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x2C, clkb
);
600 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x2D, 0x01);
603 /*********************************************/
605 /*********************************************/
608 SiS_SetCRT1FIFO_310(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
611 unsigned short modeflag
= SiS_Pr
->SiS_EModeIDTable
[mi
].Ext_ModeFlag
;
613 /* disable auto-threshold */
614 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x3D, 0xFE);
616 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x08, 0xAE);
617 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x09, 0xF0);
622 if ((!(modeflag
& DoubleScanMode
)) || (!(modeflag
& HalfDCLK
))) {
623 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x08, 0x34);
624 SiS_SetRegOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x3D, 0x01);
628 /*********************************************/
630 /*********************************************/
633 SiS_SetVCLKState(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
636 unsigned short data
= 0, VCLK
= 0, index
= 0;
639 index
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_CRTVCLK
;
640 VCLK
= SiS_Pr
->SiS_VCLKData
[index
].CLOCK
;
645 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x32, 0xf3, data
);
648 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x1f, 0xe7);
654 else if (VCLK
>= 160)
656 else if (VCLK
>= 135)
659 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x07, 0xF8, data
);
663 SiS_SetCRT1ModeRegs(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
664 unsigned short ModeIdIndex
, unsigned short rrti
)
666 unsigned short data
, infoflag
= 0, modeflag
;
669 modeflag
= SiS_Pr
->SiS_SModeIDTable
[ModeIdIndex
].St_ModeFlag
;
671 modeflag
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].Ext_ModeFlag
;
672 infoflag
= SiS_Pr
->SiS_RefIndex
[rrti
].Ext_InfoFlag
;
676 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x1F, 0x3F);
680 if (SiS_Pr
->SiS_ModeType
> ModeEGA
) {
682 data
|= ((SiS_Pr
->SiS_ModeType
- ModeVGA
) << 2);
684 if (infoflag
& InterlaceMode
)
687 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x06, 0xC0, data
);
690 if (infoflag
& InterlaceMode
) {
691 /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
693 (SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x04) |
694 ((SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0b) & 0xc0) << 2))
697 (SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x00) |
698 ((SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0b) & 0x03) << 8))
700 data
= hrs
- (hto
>> 1) + 3;
702 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x19, (data
& 0xFF));
703 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x1a, 0xFC, (data
>> 8));
705 if (modeflag
& HalfDCLK
)
706 SiS_SetRegOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x01, 0x08);
709 if (modeflag
& LineCompareOff
)
711 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0F, 0xB7, data
);
713 if ((SiS_Pr
->SiS_ModeType
== ModeEGA
) && (ModeNo
> 0x13))
714 SiS_SetRegOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x0F, 0x40);
716 SiS_SetRegAND(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x31, 0xfb);
719 if (SiS_Pr
->SiS_ModeType
!= ModeText
) {
721 if (SiS_Pr
->SiS_ModeType
!= ModeEGA
)
724 SiS_SetRegANDOR(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x21, 0x1F, data
);
726 SiS_SetVCLKState(SiS_Pr
, ModeNo
, rrti
);
728 if (SiS_GetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x31) & 0x40)
729 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x52, 0x2c);
731 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x52, 0x6c);
734 /*********************************************/
736 /*********************************************/
739 SiS_WriteDAC(struct SiS_Private
*SiS_Pr
, unsigned long DACData
,
740 unsigned short shiftflag
, unsigned short dl
, unsigned short ah
,
741 unsigned short al
, unsigned short dh
)
743 unsigned short d1
, d2
, d3
;
761 SiS_SetRegByte(SiS_Pr
, DACData
, (d1
<< shiftflag
));
762 SiS_SetRegByte(SiS_Pr
, DACData
, (d2
<< shiftflag
));
763 SiS_SetRegByte(SiS_Pr
, DACData
, (d3
<< shiftflag
));
767 SiS_LoadDAC(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
770 unsigned short data
, data2
, time
, i
, j
, k
, m
, n
, o
;
771 unsigned short si
, di
, bx
, sf
;
772 unsigned long DACAddr
, DACData
;
773 const unsigned char *table
= NULL
;
776 data
= SiS_Pr
->SiS_SModeIDTable
[mi
].St_ModeFlag
;
778 data
= SiS_Pr
->SiS_EModeIDTable
[mi
].Ext_ModeFlag
;
785 else if (data
== 0x08)
787 else if (data
== 0x10)
795 DACAddr
= SiS_Pr
->SiS_P3c8
;
796 DACData
= SiS_Pr
->SiS_P3c9
;
798 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c6
, 0xFF);
800 SiS_SetRegByte(SiS_Pr
, DACAddr
, 0x00);
802 for (i
= 0; i
< j
; i
++) {
804 for (k
= 0; k
< 3; k
++) {
810 SiS_SetRegByte(SiS_Pr
, DACData
, (data2
<< sf
));
816 for (i
= 16; i
< 32; i
++) {
817 data
= table
[i
] << sf
;
818 for (k
= 0; k
< 3; k
++)
819 SiS_SetRegByte(SiS_Pr
, DACData
, data
);
822 for (m
= 0; m
< 9; m
++) {
825 for (n
= 0; n
< 3; n
++) {
826 for (o
= 0; o
< 5; o
++) {
827 SiS_WriteDAC(SiS_Pr
, DACData
, sf
, n
,
828 table
[di
], table
[bx
],
833 for (o
= 0; o
< 3; o
++) {
834 SiS_WriteDAC(SiS_Pr
, DACData
, sf
, n
,
835 table
[di
], table
[si
],
845 /*********************************************/
846 /* SET CRT1 REGISTER GROUP */
847 /*********************************************/
850 SiS_SetCRT1Group(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
,
851 unsigned short ModeIdIndex
)
853 unsigned short StandTableIndex
, rrti
;
855 SiS_Pr
->SiS_CRT1Mode
= ModeNo
;
862 SiS_ResetSegmentRegisters(SiS_Pr
);
863 SiS_SetSeqRegs(SiS_Pr
, StandTableIndex
);
864 SiS_SetMiscRegs(SiS_Pr
, StandTableIndex
);
865 SiS_SetCRTCRegs(SiS_Pr
, StandTableIndex
);
866 SiS_SetATTRegs(SiS_Pr
, StandTableIndex
);
867 SiS_SetGRCRegs(SiS_Pr
, StandTableIndex
);
868 SiS_ClearExt1Regs(SiS_Pr
, ModeNo
);
870 rrti
= SiS_GetRatePtr(SiS_Pr
, ModeNo
, ModeIdIndex
);
872 if (rrti
!= 0xFFFF) {
873 SiS_SetCRT1Sync(SiS_Pr
, rrti
);
874 SiS_SetCRT1CRTC(SiS_Pr
, ModeNo
, ModeIdIndex
, rrti
);
875 SiS_SetCRT1Offset(SiS_Pr
, ModeNo
, ModeIdIndex
, rrti
);
876 SiS_SetCRT1VCLK(SiS_Pr
, ModeNo
, rrti
);
879 SiS_SetCRT1FIFO_310(SiS_Pr
, ModeNo
, ModeIdIndex
);
881 SiS_SetCRT1ModeRegs(SiS_Pr
, ModeNo
, ModeIdIndex
, rrti
);
883 SiS_LoadDAC(SiS_Pr
, ModeNo
, ModeIdIndex
);
885 SiS_DisplayOn(SiS_Pr
);
888 /*********************************************/
890 /*********************************************/
892 int SiSUSBSetMode(struct SiS_Private
*SiS_Pr
, unsigned short ModeNo
)
894 unsigned short ModeIdIndex
;
895 unsigned long BaseAddr
= SiS_Pr
->IOAddress
;
897 SiSUSB_InitPtr(SiS_Pr
);
898 SiSUSBRegInit(SiS_Pr
, BaseAddr
);
899 SiS_GetSysFlags(SiS_Pr
);
901 if (!(SiS_SearchModeID(SiS_Pr
, &ModeNo
, &ModeIdIndex
)))
904 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3c4
, 0x05, 0x86);
906 SiSInitPCIetc(SiS_Pr
);
910 SiS_Pr
->SiS_ModeType
=
911 SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].Ext_ModeFlag
& ModeTypeMask
;
913 SiS_Pr
->SiS_SetFlag
= LowModeTests
;
915 /* Set mode on CRT1 */
916 SiS_SetCRT1Group(SiS_Pr
, ModeNo
, ModeIdIndex
);
918 SiS_HandleCRT1(SiS_Pr
);
920 SiS_DisplayOn(SiS_Pr
);
921 SiS_SetRegByte(SiS_Pr
, SiS_Pr
->SiS_P3c6
, 0xFF);
923 /* Store mode number */
924 SiS_SetReg(SiS_Pr
, SiS_Pr
->SiS_P3d4
, 0x34, ModeNo
);
929 int SiSUSBSetVESAMode(struct SiS_Private
*SiS_Pr
, unsigned short VModeNo
)
931 unsigned short ModeNo
= 0;
934 SiSUSB_InitPtr(SiS_Pr
);
936 if (VModeNo
== 0x03) {
945 if (SiS_Pr
->SiS_EModeIDTable
[i
].Ext_VESAID
== VModeNo
) {
946 ModeNo
= SiS_Pr
->SiS_EModeIDTable
[i
].Ext_ModeID
;
950 } while (SiS_Pr
->SiS_EModeIDTable
[i
++].Ext_ModeID
!= 0xff);
957 return SiSUSBSetMode(SiS_Pr
, ModeNo
);
960 #endif /* INCL_SISUSB_CON */