summaryrefslogtreecommitdiff
path: root/drivers/staging/xgifb/vb_ext.c
blob: b1a25730b7caa59ecc0029e19ce6fd05d97b1c71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#include <linux/io.h>
#include <linux/types.h>
#include "XGIfb.h"

#include "vb_def.h"
#include "vgatypes.h"
#include "vb_struct.h"
#include "vb_util.h"
#include "vb_setmode.h"
#include "vb_ext.h"

/**************************************************************
 *********************** Dynamic Sense ************************
 *************************************************************/

static unsigned char XGINew_Is301B(struct vb_device_info *pVBInfo)
{
	unsigned short flag;

	flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);

	if (flag > 0x0B0)
		return 0; /* 301b */
	else
		return 1;
}

static unsigned char XGINew_Sense(unsigned short tempbx,
				  unsigned short tempcx,
				  struct vb_device_info *pVBInfo)
{
	unsigned short temp, i, tempch;

	temp = tempbx & 0xFF;
	xgifb_reg_set(pVBInfo->Part4Port, 0x11, temp);
	temp = (tempbx & 0xFF00) >> 8;
	temp |= (tempcx & 0x00FF);
	xgifb_reg_and_or(pVBInfo->Part4Port, 0x10, ~0x1F, temp);

	for (i = 0; i < 10; i++)
		XGI_LongWait(pVBInfo);

	tempch = (tempcx & 0x7F00) >> 8;
	temp = xgifb_reg_get(pVBInfo->Part4Port, 0x03);
	temp = temp ^ (0x0E);
	temp &= tempch;

	if (temp > 0)
		return 1;
	else
		return 0;
}

static unsigned char
XGINew_GetLCDDDCInfo(struct xgi_hw_device_info *HwDeviceExtension,
		     struct vb_device_info *pVBInfo)
{
	unsigned short temp;

	/* add lcd sense */
	if (HwDeviceExtension->ulCRT2LCDType == LCD_UNKNOWN) {
		return 0;
	} else {
		temp = (unsigned short) HwDeviceExtension->ulCRT2LCDType;
		switch (HwDeviceExtension->ulCRT2LCDType) {
		case LCD_INVALID:
		case LCD_800x600:
		case LCD_1024x768:
		case LCD_1280x1024:
			break;

		case LCD_640x480:
		case LCD_1024x600:
		case LCD_1152x864:
		case LCD_1280x960:
		case LCD_1152x768:
			temp = 0;
			break;

		case LCD_1400x1050:
		case LCD_1280x768:
		case LCD_1600x1200:
			break;

		case LCD_1920x1440:
		case LCD_2048x1536:
			temp = 0;
			break;

		default:
			break;
		}
		xgifb_reg_and_or(pVBInfo->P3d4, 0x36, 0xF0, temp);
		return 1;
	}
}

static unsigned char XGINew_GetPanelID(struct vb_device_info *pVBInfo)
{
	unsigned short PanelTypeTable[16] = { SyncNN | PanelRGB18Bit
			| Panel800x600  | _PanelType00, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType01, SyncNN | PanelRGB18Bit
			| Panel800x600  | _PanelType02, SyncNN | PanelRGB18Bit
			| Panel640x480  | _PanelType03, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType04, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType05, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType06, SyncNN | PanelRGB24Bit
			| Panel1024x768 | _PanelType07, SyncNN | PanelRGB18Bit
			| Panel800x600  | _PanelType08, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType09, SyncNN | PanelRGB18Bit
			| Panel800x600  | _PanelType0A, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType0B, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType0C, SyncNN | PanelRGB24Bit
			| Panel1024x768 | _PanelType0D, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType0E, SyncNN | PanelRGB18Bit
			| Panel1024x768 | _PanelType0F };
	unsigned short tempax, tempbx, temp;
	/* unsigned short return_flag; */

	tempax = xgifb_reg_get(pVBInfo->P3c4, 0x1A);
	tempbx = tempax & 0x1E;

	if (tempax == 0)
		return 0;
	else {
		/*
		if (!(tempax & 0x10)) {
			if (pVBInfo->IF_DEF_LVDS == 1) {
				tempbx = 0;
				temp = xgifb_reg_get(pVBInfo->P3c4, 0x38);
				if (temp & 0x40)
					tempbx |= 0x08;
				if (temp & 0x20)
					tempbx |= 0x02;
				if (temp & 0x01)
					tempbx |= 0x01;

				temp = xgifb_reg_get(pVBInfo->P3c4, 0x39);
				if (temp & 0x80)
					tempbx |= 0x04;
			 } else {
				return(0);
			 }
		}
		*/

		tempbx = tempbx >> 1;
		temp = tempbx & 0x00F;
		xgifb_reg_set(pVBInfo->P3d4, 0x36, temp);
		tempbx--;
		tempbx = PanelTypeTable[tempbx];

		temp = (tempbx & 0xFF00) >> 8;
		xgifb_reg_and_or(pVBInfo->P3d4, 0x37, ~(LCDSyncBit
				| LCDRGB18Bit), temp);
		return 1;
	}
}

static unsigned char
XGINew_BridgeIsEnable(struct xgi_hw_device_info *HwDeviceExtension,
		      struct vb_device_info *pVBInfo)
{
	unsigned short flag;

	if (XGI_BridgeIsOn(pVBInfo) == 0) {
		flag = xgifb_reg_get(pVBInfo->Part1Port, 0x0);

		if (flag & 0x050)
			return 1;
		else
			return 0;

	}
	return 0;
}

static unsigned char
XGINew_SenseHiTV(struct xgi_hw_device_info *HwDeviceExtension,
		 struct vb_device_info *pVBInfo)
{
	unsigned short tempbx, tempcx, temp, i, tempch;

	tempbx = *pVBInfo->pYCSenseData2;

	tempcx = 0x0604;

	temp = tempbx & 0xFF;
	xgifb_reg_set(pVBInfo->Part4Port, 0x11, temp);
	temp = (tempbx & 0xFF00) >> 8;
	temp |= (tempcx & 0x00FF);
	xgifb_reg_and_or(pVBInfo->Part4Port, 0x10, ~0x1F, temp);

	for (i = 0; i < 10; i++)
		XGI_LongWait(pVBInfo);

	tempch = (tempcx & 0xFF00) >> 8;
	temp = xgifb_reg_get(pVBInfo->Part4Port, 0x03);
	temp = temp ^ (0x0E);
	temp &= tempch;

	if (temp != tempch)
		return 0;

	tempbx = *pVBInfo->pVideoSenseData2;

	tempcx = 0x0804;
	temp = tempbx & 0xFF;
	xgifb_reg_set(pVBInfo->Part4Port, 0x11, temp);
	temp = (tempbx & 0xFF00) >> 8;
	temp |= (tempcx & 0x00FF);
	xgifb_reg_and_or(pVBInfo->Part4Port, 0x10, ~0x1F, temp);

	for (i = 0; i < 10; i++)
		XGI_LongWait(pVBInfo);

	tempch = (tempcx & 0xFF00) >> 8;
	temp = xgifb_reg_get(pVBInfo->Part4Port, 0x03);
	temp = temp ^ (0x0E);
	temp &= tempch;

	if (temp != tempch) {
		return 0;
	} else {
		tempbx = 0x3FF;
		tempcx = 0x0804;
		temp = tempbx & 0xFF;
		xgifb_reg_set(pVBInfo->Part4Port, 0x11, temp);
		temp = (tempbx & 0xFF00) >> 8;
		temp |= (tempcx & 0x00FF);
		xgifb_reg_and_or(pVBInfo->Part4Port, 0x10, ~0x1F, temp);

		for (i = 0; i < 10; i++)
			XGI_LongWait(pVBInfo);

		tempch = (tempcx & 0xFF00) >> 8;
		temp = xgifb_reg_get(pVBInfo->Part4Port, 0x03);
		temp = temp ^ (0x0E);
		temp &= tempch;

		if (temp != tempch)
			return 1;
		else
			return 0;
	}
}

void XGI_GetSenseStatus(struct xgi_hw_device_info *HwDeviceExtension,
			struct vb_device_info *pVBInfo)
{
	unsigned short  tempax = 0, tempbx, tempcx, temp,
			P2reg0 = 0, SenseModeNo = 0,
			OutputSelect = *pVBInfo->pOutputSelect,
			ModeIdIndex, i;
	pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;

	if (pVBInfo->IF_DEF_LVDS == 1) {
		/* ynlai 02/27/2002 */
		tempax = xgifb_reg_get(pVBInfo->P3c4, 0x1A);
		tempbx = xgifb_reg_get(pVBInfo->P3c4, 0x1B);
		tempax = ((tempax & 0xFE) >> 1) | (tempbx << 8);
		if (tempax == 0x00) { /* Get Panel id from DDC */
			temp = XGINew_GetLCDDDCInfo(HwDeviceExtension, pVBInfo);
			if (temp == 1) { /* LCD connect */
				/* set CR39 bit0="1" */
				xgifb_reg_and_or(pVBInfo->P3d4,
						 0x39, 0xFF, 0x01);
				/* clean CR37 bit4="0" */
				xgifb_reg_and_or(pVBInfo->P3d4,
						 0x37, 0xEF, 0x00);
				temp = LCDSense;
			} else { /* LCD don't connect */
				temp = 0;
			}
		} else {
			XGINew_GetPanelID(pVBInfo);
			temp = LCDSense;
		}

		tempbx = ~(LCDSense | AVIDEOSense | SVIDEOSense);
		xgifb_reg_and_or(pVBInfo->P3d4, 0x32, tempbx, temp);
	} else { /* for 301 */
		if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiVision */
			tempax = xgifb_reg_get(pVBInfo->P3c4, 0x38);
			temp = tempax & 0x01;
			tempax = xgifb_reg_get(pVBInfo->P3c4, 0x3A);
			temp = temp | (tempax & 0x02);
			xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xA0, temp);
		} else {
			if (XGI_BridgeIsOn(pVBInfo)) {
				P2reg0 = xgifb_reg_get(pVBInfo->Part2Port,
						       0x00);
				if (!XGINew_BridgeIsEnable(HwDeviceExtension,
							   pVBInfo)) {
					SenseModeNo = 0x2e;
				/* xgifb_reg_set(pVBInfo->P3d4, 0x30, 0x41);
				 * XGISetModeNew(HwDeviceExtension, 0x2e);
				 * // ynlai InitMode */

					temp = XGI_SearchModeID(SenseModeNo,
								&ModeIdIndex,
								pVBInfo);
					XGI_GetVGAType(HwDeviceExtension,
						       pVBInfo);
					XGI_GetVBType(pVBInfo);
					pVBInfo->SetFlag = 0x00;
					pVBInfo->ModeType = ModeVGA;
					pVBInfo->VBInfo = SetCRT2ToRAMDAC |
							  LoadDACFlag |
							  SetInSlaveMode;
					XGI_GetLCDInfo(0x2e,
						       ModeIdIndex,
						       pVBInfo);
					XGI_GetTVInfo(0x2e,
						      ModeIdIndex,
						      pVBInfo);
					XGI_EnableBridge(HwDeviceExtension,
							 pVBInfo);
					XGI_SetCRT2Group301(SenseModeNo,
							    HwDeviceExtension,
							    pVBInfo);
					XGI_SetCRT2ModeRegs(0x2e,
							    HwDeviceExtension,
							    pVBInfo);
					/* XGI_DisableBridge(HwDeviceExtension,
					 *		     pVBInfo ) ; */
					/* Display Off 0212 */
					xgifb_reg_and_or(pVBInfo->P3c4,
							 0x01,
							 0xDF,
							 0x20);
					for (i = 0; i < 20; i++)
						XGI_LongWait(pVBInfo);
				}
				xgifb_reg_set(pVBInfo->Part2Port, 0x00, 0x1c);
				tempax = 0;
				tempbx = *pVBInfo->pRGBSenseData;

				if (!(XGINew_Is301B(pVBInfo)))
					tempbx = *pVBInfo->pRGBSenseData2;

				tempcx = 0x0E08;
				if (XGINew_Sense(tempbx, tempcx, pVBInfo)) {
					if (XGINew_Sense(tempbx,
							 tempcx,
							 pVBInfo))
						tempax |= Monitor2Sense;
				}

				if (pVBInfo->VBType & VB_XGI301C)
					xgifb_reg_or(pVBInfo->Part4Port,
						     0x0d,
						     0x04);

				/* add by kuku for Multi-adapter sense HiTV */
				if (XGINew_SenseHiTV(HwDeviceExtension,
						     pVBInfo)) {
					tempax |= HiTVSense;
					if ((pVBInfo->VBType & VB_XGI301C))
						tempax ^= (HiTVSense |
							   YPbPrSense);
				}

				/* start */
				if (!(tempax & (HiTVSense | YPbPrSense))) {
					tempbx = *pVBInfo->pYCSenseData;
					if (!(XGINew_Is301B(pVBInfo)))
						tempbx = *pVBInfo->pYCSenseData2;
					tempcx = 0x0604;
					if (XGINew_Sense(tempbx,
							 tempcx,
							 pVBInfo)) {
						if (XGINew_Sense(tempbx,
								 tempcx,
								 pVBInfo))
							tempax |= SVIDEOSense;
					}

					if (OutputSelect & BoardTVType) {
						tempbx = *pVBInfo->pVideoSenseData;

						if (!(XGINew_Is301B(pVBInfo)))
							tempbx = *pVBInfo->pVideoSenseData2;

						tempcx = 0x0804;
						if (XGINew_Sense(tempbx,
								 tempcx,
								 pVBInfo)) {
							if (XGINew_Sense(tempbx,
									 tempcx,
									 pVBInfo))
								tempax |= AVIDEOSense;
						}
					} else {
						if (!(tempax & SVIDEOSense)) {
							tempbx = *pVBInfo->pVideoSenseData;

							if (!(XGINew_Is301B(pVBInfo)))
								tempbx = *pVBInfo->pVideoSenseData2;

							tempcx = 0x0804;
							if (XGINew_Sense(tempbx,
									 tempcx,
									 pVBInfo)) {
								if (XGINew_Sense(tempbx, tempcx, pVBInfo))
									tempax |= AVIDEOSense;
							}
						}
					}
				}
			} /* end */
			if (!(tempax & Monitor2Sense)) {
				if (XGINew_SenseLCD(HwDeviceExtension, pVBInfo))
					tempax |= LCDSense;
			}
			tempbx = 0;
			tempcx = 0;
			XGINew_Sense(tempbx, tempcx, pVBInfo);

			xgifb_reg_and_or(pVBInfo->P3d4, 0x32, ~0xDF, tempax);
			xgifb_reg_set(pVBInfo->Part2Port, 0x00, P2reg0);

			if (!(P2reg0 & 0x20)) {
				pVBInfo->VBInfo = DisableCRT2Display;
				/* XGI_SetCRT2Group301(SenseModeNo,
				 *		       HwDeviceExtension,
				 *		       pVBInfo); */
			}
		}
	}
	XGI_DisableBridge(HwDeviceExtension, pVBInfo); /* shampoo 0226 */

}

unsigned short XGINew_SenseLCD(struct xgi_hw_device_info *HwDeviceExtension,
			       struct vb_device_info *pVBInfo)
{
	/* unsigned short SoftSetting ; */
	unsigned short temp;

	temp = XGINew_GetLCDDDCInfo(HwDeviceExtension, pVBInfo);

	return temp;
}