Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
[sfrench/cifs-2.6.git] / drivers / staging / xgifb / vb_util.c
1 #include "osdef.h"
2 #include "vb_def.h"
3 #include "vgatypes.h"
4 #include "vb_struct.h"
5
6 #ifdef LINUX_KERNEL
7 #include "XGIfb.h"
8 #include <asm/io.h>
9 #include <linux/types.h>
10 #endif
11
12 #ifdef TC
13 #include <stdio.h>
14 #include <string.h>
15 #include <conio.h>
16 #include <dos.h>
17 #endif
18
19 #ifdef WIN2000
20 #include <dderror.h>
21 #include <devioctl.h>
22 #include <miniport.h>
23 #include <ntddvdeo.h>
24 #include <video.h>
25
26 #include "xgiv.h"
27 #include "dd_i2c.h"
28 #include "tools.h"
29 #endif
30
31 #ifdef LINUX_XF86
32 #include "xf86.h"
33 #include "xf86PciInfo.h"
34 #include "xgi.h"
35 #include "xgi_regs.h"
36 #endif
37
38
39
40
41 void XGINew_SetReg1( ULONG , USHORT , USHORT ) ;
42 void XGINew_SetReg2( ULONG , USHORT , USHORT ) ;
43 void XGINew_SetReg3( ULONG , USHORT ) ;
44 void XGINew_SetReg4( ULONG , ULONG ) ;
45 UCHAR XGINew_GetReg1( ULONG , USHORT) ;
46 UCHAR XGINew_GetReg2( ULONG ) ;
47 ULONG XGINew_GetReg3( ULONG ) ;
48 void XGINew_ClearDAC( PUCHAR ) ;
49 void     XGINew_SetRegANDOR(ULONG Port,USHORT Index,USHORT DataAND,USHORT DataOR);
50 void     XGINew_SetRegOR(ULONG Port,USHORT Index,USHORT DataOR);
51 void     XGINew_SetRegAND(ULONG Port,USHORT Index,USHORT DataAND);
52
53
54 /* --------------------------------------------------------------------- */
55 /* Function : XGINew_SetReg1 */
56 /* Input : */
57 /* Output : */
58 /* Description : SR CRTC GR */
59 /* --------------------------------------------------------------------- */
60 void XGINew_SetReg1( ULONG port , USHORT index , USHORT data )
61 {
62 #ifdef LINUX_XF86
63     OutPortByte( ( PUCHAR )(ULONG)port , index ) ;
64     OutPortByte( ( PUCHAR )(ULONG)port + 1 , data ) ;
65 #else
66     OutPortByte( port , index ) ;
67     OutPortByte( port + 1 , data ) ;
68 #endif
69 }
70
71
72 /* --------------------------------------------------------------------- */
73 /* Function : XGINew_SetReg2 */
74 /* Input : */
75 /* Output : */
76 /* Description : AR( 3C0 ) */
77 /* --------------------------------------------------------------------- */
78 /*void XGINew_SetReg2( ULONG port , USHORT index , USHORT data )
79 {
80     InPortByte( ( PUCHAR )port + 0x3da - 0x3c0 ) ;
81     OutPortByte( XGINew_P3c0 , index ) ;
82     OutPortByte( XGINew_P3c0 , data ) ;
83     OutPortByte( XGINew_P3c0 , 0x20 ) ;
84 }*/
85
86
87 /* --------------------------------------------------------------------- */
88 /* Function : */
89 /* Input : */
90 /* Output : */
91 /* Description : */
92 /* --------------------------------------------------------------------- */
93 void XGINew_SetReg3( ULONG port , USHORT data )
94 {
95     OutPortByte( port , data ) ;
96 }
97
98
99 /* --------------------------------------------------------------------- */
100 /* Function : XGINew_SetReg4 */
101 /* Input : */
102 /* Output : */
103 /* Description : */
104 /* --------------------------------------------------------------------- */
105 void XGINew_SetReg4( ULONG port , ULONG data )
106 {
107     OutPortLong( port , data ) ;
108 }
109
110
111 /* --------------------------------------------------------------------- */
112 /* Function : XGINew_GetReg1 */
113 /* Input : */
114 /* Output : */
115 /* Description : */
116 /* --------------------------------------------------------------------- */
117 UCHAR XGINew_GetReg1( ULONG port , USHORT index )
118 {
119     UCHAR data ;
120
121 #ifdef LINUX_XF86
122     OutPortByte( ( PUCHAR )(ULONG)port , index ) ;
123     data = InPortByte( ( PUCHAR )(ULONG)port + 1 ) ;
124 #else
125     OutPortByte( port , index ) ;
126     data = InPortByte( port + 1 ) ;
127 #endif
128
129     return( data ) ;
130 }
131
132
133 /* --------------------------------------------------------------------- */
134 /* Function : XGINew_GetReg2 */
135 /* Input : */
136 /* Output : */
137 /* Description : */
138 /* --------------------------------------------------------------------- */
139 UCHAR XGINew_GetReg2( ULONG port )
140 {
141     UCHAR data ;
142
143     data = InPortByte( port ) ;
144
145     return( data ) ;
146 }
147
148
149 /* --------------------------------------------------------------------- */
150 /* Function : XGINew_GetReg3 */
151 /* Input : */
152 /* Output : */
153 /* Description : */
154 /* --------------------------------------------------------------------- */
155 ULONG XGINew_GetReg3( ULONG port )
156 {
157     ULONG data ;
158
159     data = InPortLong( port ) ;
160
161     return( data ) ;
162 }
163
164
165
166 /* --------------------------------------------------------------------- */
167 /* Function : XGINew_SetRegANDOR */
168 /* Input : */
169 /* Output : */
170 /* Description : */
171 /* --------------------------------------------------------------------- */
172 void XGINew_SetRegANDOR( ULONG Port , USHORT Index , USHORT DataAND , USHORT DataOR )
173 {
174     USHORT temp ;
175
176     temp = XGINew_GetReg1( Port , Index ) ;             /* XGINew_Part1Port index 02 */
177     temp = ( temp & ( DataAND ) ) | DataOR ;
178     XGINew_SetReg1( Port , Index , temp ) ;
179 }
180
181
182 /* --------------------------------------------------------------------- */
183 /* Function : XGINew_SetRegAND */
184 /* Input : */
185 /* Output : */
186 /* Description : */
187 /* --------------------------------------------------------------------- */
188 void XGINew_SetRegAND(ULONG Port,USHORT Index,USHORT DataAND)
189 {
190     USHORT temp ;
191
192     temp = XGINew_GetReg1( Port , Index ) ;     /* XGINew_Part1Port index 02 */
193     temp &= DataAND ;
194     XGINew_SetReg1( Port , Index , temp ) ;
195 }
196
197
198 /* --------------------------------------------------------------------- */
199 /* Function : XGINew_SetRegOR */
200 /* Input : */
201 /* Output : */
202 /* Description : */
203 /* --------------------------------------------------------------------- */
204 void XGINew_SetRegOR( ULONG Port , USHORT Index , USHORT DataOR )
205 {
206     USHORT temp ;
207
208     temp = XGINew_GetReg1( Port , Index ) ;     /* XGINew_Part1Port index 02 */
209     temp |= DataOR ;
210     XGINew_SetReg1( Port , Index , temp ) ;
211 }
212
213
214 /* --------------------------------------------------------------------- */
215 /* Function : NewDelaySecond */
216 /* Input : */
217 /* Output : */
218 /* Description : */
219 /* --------------------------------------------------------------------- */
220 void NewDelaySeconds( int seconds )
221 {
222 #ifdef WIN2000
223     int j ;
224 #endif
225     int i ;
226
227
228     for( i = 0 ; i < seconds ; i++ )
229     {
230 #ifdef TC
231         delay( 1000 ) ;
232 #endif
233
234 #ifdef WIN2000
235
236         for ( j = 0 ; j < 20000 ; j++ )
237             VideoPortStallExecution( 50 ) ;
238 #endif
239
240 #ifdef WINCE_HEADER
241 #endif
242
243 #ifdef LINUX_KERNEL
244 #endif
245     }
246 }
247
248
249 /* --------------------------------------------------------------------- */
250 /* Function : Newdebugcode */
251 /* Input : */
252 /* Output : */
253 /* Description : */
254 /* --------------------------------------------------------------------- */
255 void Newdebugcode( UCHAR code )
256 {
257 //    OutPortByte ( 0x80 , code ) ;
258     /* OutPortByte ( 0x300 , code ) ; */
259     /* NewDelaySeconds( 0x3 ) ; */
260 }
261
262
263