]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/xgifb/vb_ext.c
staging: xgifb: vb_ext: make internal functions static
[karo-tx-linux.git] / drivers / staging / xgifb / vb_ext.c
1 #include <linux/version.h>
2 #include <asm/io.h>
3 #include <linux/types.h>
4 #include "XGIfb.h"
5
6 #include "vb_def.h"
7 #include "vgatypes.h"
8 #include "vb_struct.h"
9 #include "vb_util.h"
10 #include "vb_setmode.h"
11 #include "vb_ext.h"
12 static unsigned char XGINew_GetPanelID(struct vb_device_info *pVBInfo);
13 static unsigned char XGINew_GetLCDDDCInfo(
14                 struct xgi_hw_device_info *HwDeviceExtension,
15                 struct vb_device_info *pVBInfo);
16 static unsigned char XGINew_BridgeIsEnable(struct xgi_hw_device_info *,
17                 struct vb_device_info *pVBInfo);
18 static unsigned char XGINew_SenseHiTV(struct xgi_hw_device_info *HwDeviceExtension,
19                 struct vb_device_info *pVBInfo);
20
21 /**************************************************************
22  *********************** Dynamic Sense ************************
23  *************************************************************/
24
25 static unsigned char XGINew_Is301B(struct vb_device_info *pVBInfo)
26 {
27         unsigned short flag;
28
29         flag = XGINew_GetReg1(pVBInfo->Part4Port, 0x01);
30
31         if (flag > 0x0B0)
32                 return 0; /* 301b */
33         else
34                 return 1;
35 }
36
37 static unsigned char XGINew_Sense(unsigned short tempbx, unsigned short tempcx, struct vb_device_info *pVBInfo)
38 {
39         unsigned short temp, i, tempch;
40
41         temp = tempbx & 0xFF;
42         XGINew_SetReg1(pVBInfo->Part4Port, 0x11, temp);
43         temp = (tempbx & 0xFF00) >> 8;
44         temp |= (tempcx & 0x00FF);
45         XGINew_SetRegANDOR(pVBInfo->Part4Port, 0x10, ~0x1F, temp);
46
47         for (i = 0; i < 10; i++)
48                 XGI_LongWait(pVBInfo);
49
50         tempch = (tempcx & 0x7F00) >> 8;
51         temp = XGINew_GetReg1(pVBInfo->Part4Port, 0x03);
52         temp = temp ^ (0x0E);
53         temp &= tempch;
54
55         if (temp > 0)
56                 return 1;
57         else
58                 return 0;
59 }
60
61 void XGI_GetSenseStatus(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
62 {
63         unsigned short tempax = 0, tempbx, tempcx, temp, P2reg0 = 0, SenseModeNo = 0,
64                         OutputSelect = *pVBInfo->pOutputSelect, ModeIdIndex, i;
65         pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
66
67         if (pVBInfo->IF_DEF_LVDS == 1) {
68                 tempax = XGINew_GetReg1(pVBInfo->P3c4, 0x1A); /* ynlai 02/27/2002 */
69                 tempbx = XGINew_GetReg1(pVBInfo->P3c4, 0x1B);
70                 tempax = ((tempax & 0xFE) >> 1) | (tempbx << 8);
71                 if (tempax == 0x00) { /* Get Panel id from DDC */
72                         temp = XGINew_GetLCDDDCInfo(HwDeviceExtension, pVBInfo);
73                         if (temp == 1) { /* LCD connect */
74                                 XGINew_SetRegANDOR(pVBInfo->P3d4, 0x39, 0xFF, 0x01); /* set CR39 bit0="1" */
75                                 XGINew_SetRegANDOR(pVBInfo->P3d4, 0x37, 0xEF, 0x00); /* clean CR37 bit4="0" */
76                                 temp = LCDSense;
77                         } else { /* LCD don't connect */
78                                 temp = 0;
79                         }
80                 } else {
81                         XGINew_GetPanelID(pVBInfo);
82                         temp = LCDSense;
83                 }
84
85                 tempbx = ~(LCDSense | AVIDEOSense | SVIDEOSense);
86                 XGINew_SetRegANDOR(pVBInfo->P3d4, 0x32, tempbx, temp);
87         } else { /* for 301 */
88                 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiVision */
89                         tempax = XGINew_GetReg1(pVBInfo->P3c4, 0x38);
90                         temp = tempax & 0x01;
91                         tempax = XGINew_GetReg1(pVBInfo->P3c4, 0x3A);
92                         temp = temp | (tempax & 0x02);
93                         XGINew_SetRegANDOR(pVBInfo->P3d4, 0x32, 0xA0, temp);
94                 } else {
95                         if (XGI_BridgeIsOn(pVBInfo)) {
96                                 P2reg0 = XGINew_GetReg1(pVBInfo->Part2Port, 0x00);
97                                 if (!XGINew_BridgeIsEnable(HwDeviceExtension, pVBInfo)) {
98                                         SenseModeNo = 0x2e;
99                                         /* XGINew_SetReg1(pVBInfo->P3d4, 0x30, 0x41); */
100                                         /* XGISetModeNew(HwDeviceExtension, 0x2e); // ynlai InitMode */
101
102                                         temp = XGI_SearchModeID(SenseModeNo, &ModeIdIndex, pVBInfo);
103                                         XGI_GetVGAType(HwDeviceExtension, pVBInfo);
104                                         XGI_GetVBType(pVBInfo);
105                                         pVBInfo->SetFlag = 0x00;
106                                         pVBInfo->ModeType = ModeVGA;
107                                         pVBInfo->VBInfo = SetCRT2ToRAMDAC | LoadDACFlag | SetInSlaveMode;
108                                         XGI_GetLCDInfo(0x2e, ModeIdIndex, pVBInfo);
109                                         XGI_GetTVInfo(0x2e, ModeIdIndex, pVBInfo);
110                                         XGI_EnableBridge(HwDeviceExtension, pVBInfo);
111                                         XGI_SetCRT2Group301(SenseModeNo, HwDeviceExtension, pVBInfo);
112                                         XGI_SetCRT2ModeRegs(0x2e, HwDeviceExtension, pVBInfo);
113                                         /* XGI_DisableBridge( HwDeviceExtension, pVBInfo ) ; */
114                                         XGINew_SetRegANDOR(pVBInfo->P3c4, 0x01, 0xDF, 0x20); /* Display Off 0212 */
115                                         for (i = 0; i < 20; i++)
116                                                 XGI_LongWait(pVBInfo);
117                                 }
118                                 XGINew_SetReg1(pVBInfo->Part2Port, 0x00, 0x1c);
119                                 tempax = 0;
120                                 tempbx = *pVBInfo->pRGBSenseData;
121
122                                 if (!(XGINew_Is301B(pVBInfo)))
123                                         tempbx = *pVBInfo->pRGBSenseData2;
124
125                                 tempcx = 0x0E08;
126                                 if (XGINew_Sense(tempbx, tempcx, pVBInfo)) {
127                                         if (XGINew_Sense(tempbx, tempcx, pVBInfo))
128                                                 tempax |= Monitor2Sense;
129                                 }
130
131                                 if (pVBInfo->VBType & VB_XGI301C)
132                                         XGINew_SetRegOR(pVBInfo->Part4Port, 0x0d, 0x04);
133
134                                 if (XGINew_SenseHiTV(HwDeviceExtension, pVBInfo)) { /* add by kuku for Multi-adapter sense HiTV */
135                                         tempax |= HiTVSense;
136                                         if ((pVBInfo->VBType & VB_XGI301C))
137                                                 tempax ^= (HiTVSense | YPbPrSense);
138                                 }
139
140                                 if (!(tempax & (HiTVSense | YPbPrSense))) { /* start */
141
142                                         tempbx = *pVBInfo->pYCSenseData;
143
144                                         if (!(XGINew_Is301B(pVBInfo)))
145                                                 tempbx = *pVBInfo->pYCSenseData2;
146
147                                         tempcx = 0x0604;
148                                         if (XGINew_Sense(tempbx, tempcx, pVBInfo)) {
149                                                 if (XGINew_Sense(tempbx, tempcx, pVBInfo))
150                                                         tempax |= SVIDEOSense;
151                                         }
152
153                                         if (OutputSelect & BoardTVType) {
154                                                 tempbx = *pVBInfo->pVideoSenseData;
155
156                                                 if (!(XGINew_Is301B(pVBInfo)))
157                                                         tempbx = *pVBInfo->pVideoSenseData2;
158
159                                                 tempcx = 0x0804;
160                                                 if (XGINew_Sense(tempbx, tempcx, pVBInfo)) {
161                                                         if (XGINew_Sense(tempbx, tempcx, pVBInfo))
162                                                                 tempax |= AVIDEOSense;
163                                                 }
164                                         } else {
165                                                 if (!(tempax & SVIDEOSense)) {
166                                                         tempbx = *pVBInfo->pVideoSenseData;
167
168                                                         if (!(XGINew_Is301B(pVBInfo)))
169                                                                 tempbx = *pVBInfo->pVideoSenseData2;
170
171                                                         tempcx = 0x0804;
172                                                         if (XGINew_Sense(tempbx, tempcx, pVBInfo)) {
173                                                                 if (XGINew_Sense(tempbx, tempcx, pVBInfo))
174                                                                         tempax |= AVIDEOSense;
175                                                         }
176                                                 }
177                                         }
178                                 }
179                         } /* end */
180                         if (!(tempax & Monitor2Sense)) {
181                                 if (XGINew_SenseLCD(HwDeviceExtension, pVBInfo))
182                                         tempax |= LCDSense;
183                         }
184                         tempbx = 0;
185                         tempcx = 0;
186                         XGINew_Sense(tempbx, tempcx, pVBInfo);
187
188                         XGINew_SetRegANDOR(pVBInfo->P3d4, 0x32, ~0xDF, tempax);
189                         XGINew_SetReg1(pVBInfo->Part2Port, 0x00, P2reg0);
190
191                         if (!(P2reg0 & 0x20)) {
192                                 pVBInfo->VBInfo = DisableCRT2Display;
193                                 /* XGI_SetCRT2Group301(SenseModeNo, HwDeviceExtension, pVBInfo); */
194                         }
195                 }
196         }
197         XGI_DisableBridge(HwDeviceExtension, pVBInfo); /* shampoo 0226 */
198
199 }
200
201 unsigned short XGINew_SenseLCD(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
202 {
203         /* unsigned short SoftSetting ; */
204         unsigned short temp;
205
206         if ((HwDeviceExtension->jChipType >= XG20) || (HwDeviceExtension->jChipType >= XG40))
207                 temp = 0;
208         else
209                 temp = XGINew_GetPanelID(pVBInfo);
210
211         if (!temp)
212                 temp = XGINew_GetLCDDDCInfo(HwDeviceExtension, pVBInfo);
213
214         return temp;
215 }
216
217 static unsigned char XGINew_GetLCDDDCInfo(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
218 {
219         unsigned short temp;
220
221         /* add lcd sense */
222         if (HwDeviceExtension->ulCRT2LCDType == LCD_UNKNOWN) {
223                 return 0;
224         } else {
225                 temp = (unsigned short) HwDeviceExtension->ulCRT2LCDType;
226                 switch (HwDeviceExtension->ulCRT2LCDType) {
227                 case LCD_INVALID:
228                 case LCD_800x600:
229                 case LCD_1024x768:
230                 case LCD_1280x1024:
231                         break;
232
233                 case LCD_640x480:
234                 case LCD_1024x600:
235                 case LCD_1152x864:
236                 case LCD_1280x960:
237                 case LCD_1152x768:
238                         temp = 0;
239                         break;
240
241                 case LCD_1400x1050:
242                 case LCD_1280x768:
243                 case LCD_1600x1200:
244                         break;
245
246                 case LCD_1920x1440:
247                 case LCD_2048x1536:
248                         temp = 0;
249                         break;
250
251                 default:
252                         break;
253                 }
254                 XGINew_SetRegANDOR(pVBInfo->P3d4, 0x36, 0xF0, temp);
255                 return 1;
256         }
257 }
258
259 static unsigned char XGINew_GetPanelID(struct vb_device_info *pVBInfo)
260 {
261         unsigned short PanelTypeTable[16] = { SyncNN | PanelRGB18Bit
262                         | Panel800x600  | _PanelType00, SyncNN | PanelRGB18Bit
263                         | Panel1024x768 | _PanelType01, SyncNN | PanelRGB18Bit
264                         | Panel800x600  | _PanelType02, SyncNN | PanelRGB18Bit
265                         | Panel640x480  | _PanelType03, SyncNN | PanelRGB18Bit
266                         | Panel1024x768 | _PanelType04, SyncNN | PanelRGB18Bit
267                         | Panel1024x768 | _PanelType05, SyncNN | PanelRGB18Bit
268                         | Panel1024x768 | _PanelType06, SyncNN | PanelRGB24Bit
269                         | Panel1024x768 | _PanelType07, SyncNN | PanelRGB18Bit
270                         | Panel800x600  | _PanelType08, SyncNN | PanelRGB18Bit
271                         | Panel1024x768 | _PanelType09, SyncNN | PanelRGB18Bit
272                         | Panel800x600  | _PanelType0A, SyncNN | PanelRGB18Bit
273                         | Panel1024x768 | _PanelType0B, SyncNN | PanelRGB18Bit
274                         | Panel1024x768 | _PanelType0C, SyncNN | PanelRGB24Bit
275                         | Panel1024x768 | _PanelType0D, SyncNN | PanelRGB18Bit
276                         | Panel1024x768 | _PanelType0E, SyncNN | PanelRGB18Bit
277                         | Panel1024x768 | _PanelType0F };
278         unsigned short tempax, tempbx, temp;
279         /* unsigned short return_flag; */
280
281         tempax = XGINew_GetReg1(pVBInfo->P3c4, 0x1A);
282         tempbx = tempax & 0x1E;
283
284         if (tempax == 0)
285                 return 0;
286         else {
287                 /*
288                 if (!(tempax & 0x10)) {
289                         if (pVBInfo->IF_DEF_LVDS == 1) {
290                                 tempbx = 0;
291                                 temp = XGINew_GetReg1(pVBInfo->P3c4, 0x38);
292                                 if (temp & 0x40)
293                                         tempbx |= 0x08;
294                                 if (temp & 0x20)
295                                         tempbx |= 0x02;
296                                 if (temp & 0x01)
297                                         tempbx |= 0x01;
298
299                                 temp = XGINew_GetReg1(pVBInfo->P3c4, 0x39);
300                                 if (temp & 0x80)
301                                         tempbx |= 0x04;
302                          } else {
303                                 return(0);
304                          }
305                 }
306                 */
307
308                 tempbx = tempbx >> 1;
309                 temp = tempbx & 0x00F;
310                 XGINew_SetReg1(pVBInfo->P3d4, 0x36, temp);
311                 tempbx--;
312                 tempbx = PanelTypeTable[tempbx];
313
314                 temp = (tempbx & 0xFF00) >> 8;
315                 XGINew_SetRegANDOR(pVBInfo->P3d4, 0x37, ~(LCDSyncBit
316                                 | LCDRGB18Bit), temp);
317                 return 1;
318         }
319 }
320
321 static unsigned char XGINew_BridgeIsEnable(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
322 {
323         unsigned short flag;
324
325         if (XGI_BridgeIsOn(pVBInfo) == 0) {
326                 flag = XGINew_GetReg1(pVBInfo->Part1Port, 0x0);
327
328                 if (flag & 0x050)
329                         return 1;
330                 else
331                         return 0;
332
333         }
334         return 0;
335 }
336
337 static unsigned char XGINew_SenseHiTV(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
338 {
339         unsigned short tempbx, tempcx, temp, i, tempch;
340
341         tempbx = *pVBInfo->pYCSenseData2;
342
343         tempcx = 0x0604;
344
345         temp = tempbx & 0xFF;
346         XGINew_SetReg1(pVBInfo->Part4Port, 0x11, temp);
347         temp = (tempbx & 0xFF00) >> 8;
348         temp |= (tempcx & 0x00FF);
349         XGINew_SetRegANDOR(pVBInfo->Part4Port, 0x10, ~0x1F, temp);
350
351         for (i = 0; i < 10; i++)
352                 XGI_LongWait(pVBInfo);
353
354         tempch = (tempcx & 0xFF00) >> 8;
355         temp = XGINew_GetReg1(pVBInfo->Part4Port, 0x03);
356         temp = temp ^ (0x0E);
357         temp &= tempch;
358
359         if (temp != tempch)
360                 return 0;
361
362         tempbx = *pVBInfo->pVideoSenseData2;
363
364         tempcx = 0x0804;
365         temp = tempbx & 0xFF;
366         XGINew_SetReg1(pVBInfo->Part4Port, 0x11, temp);
367         temp = (tempbx & 0xFF00) >> 8;
368         temp |= (tempcx & 0x00FF);
369         XGINew_SetRegANDOR(pVBInfo->Part4Port, 0x10, ~0x1F, temp);
370
371         for (i = 0; i < 10; i++)
372                 XGI_LongWait(pVBInfo);
373
374         tempch = (tempcx & 0xFF00) >> 8;
375         temp = XGINew_GetReg1(pVBInfo->Part4Port, 0x03);
376         temp = temp ^ (0x0E);
377         temp &= tempch;
378
379         if (temp != tempch) {
380                 return 0;
381         } else {
382                 tempbx = 0x3FF;
383                 tempcx = 0x0804;
384                 temp = tempbx & 0xFF;
385                 XGINew_SetReg1(pVBInfo->Part4Port, 0x11, temp);
386                 temp = (tempbx & 0xFF00) >> 8;
387                 temp |= (tempcx & 0x00FF);
388                 XGINew_SetRegANDOR(pVBInfo->Part4Port, 0x10, ~0x1F, temp);
389
390                 for (i = 0; i < 10; i++)
391                         XGI_LongWait(pVBInfo);
392
393                 tempch = (tempcx & 0xFF00) >> 8;
394                 temp = XGINew_GetReg1(pVBInfo->Part4Port, 0x03);
395                 temp = temp ^ (0x0E);
396                 temp &= tempch;
397
398                 if (temp != tempch)
399                         return 1;
400                 else
401                         return 0;
402         }
403 }