summaryrefslogtreecommitdiff
path: root/linux-core/xgi_regs.h
blob: 487a7e1532c17be45e0622eee749d1598f2af1f6 (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

/****************************************************************************
 * Copyright (C) 2003-2006 by XGI Technology, Taiwan.			
 *																			*
 * All Rights Reserved.														*
 *																			*
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the	
 * "Software"), to deal in the Software without restriction, including	
 * without limitation on the rights to use, copy, modify, merge,	
 * publish, distribute, sublicense, and/or sell copies of the Software,	
 * and to permit persons to whom the Software is furnished to do so,	
 * subject to the following conditions:					
 *																			*
 * The above copyright notice and this permission notice (including the	
 * next paragraph) shall be included in all copies or substantial	
 * portions of the Software.						
 *																			*
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,	
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF	
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND		
 * NON-INFRINGEMENT.  IN NO EVENT SHALL XGI AND/OR			
 * ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,		
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,		
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER			
 * DEALINGS IN THE SOFTWARE.												
 ***************************************************************************/

#ifndef _XGI_REGS_H_
#define _XGI_REGS_H_

#ifndef XGI_MMIO
#define XGI_MMIO 1
#endif

#if XGI_MMIO
#define OUTB(port, value)   writeb(value, info->mmio.vbase + port)
#define INB(port)           readb(info->mmio.vbase + port)
#define OUTW(port, value)   writew(value, info->mmio.vbase + port)
#define INW(port)           readw(info->mmio.vbase + port)
#define OUTDW(port, value)  writel(value, info->mmio.vbase + port)
#define INDW(port)          readl(info->mmio.vbase + port)
#else
#define OUTB(port, value)   outb(value, port)
#define INB(port)           inb(port)
#define OUTW(port, value)   outw(value, port)
#define INW(port)           inw(port)
#define OUTDW(port, value)  outl(value, port)
#define INDW(port)          inl(port)
#endif

/* Hardware access functions */
static inline void OUT3C5B(xgi_info_t * info, u8 index, u8 data)
{
	OUTB(0x3C4, index);
	OUTB(0x3C5, data);
}

static inline void OUT3X5B(xgi_info_t * info, u8 index, u8 data)
{
	OUTB(0x3D4, index);
	OUTB(0x3D5, data);
}

static inline void OUT3CFB(xgi_info_t * info, u8 index, u8 data)
{
	OUTB(0x3CE, index);
	OUTB(0x3CF, data);
}

static inline u8 IN3C5B(xgi_info_t * info, u8 index)
{
	volatile u8 data = 0;
	OUTB(0x3C4, index);
	data = INB(0x3C5);
	return data;
}

static inline u8 IN3X5B(xgi_info_t * info, u8 index)
{
	volatile u8 data = 0;
	OUTB(0x3D4, index);
	data = INB(0x3D5);
	return data;
}

static inline u8 IN3CFB(xgi_info_t * info, u8 index)
{
	volatile u8 data = 0;
	OUTB(0x3CE, index);
	data = INB(0x3CF);
	return data;
}

static inline void OUT3C5W(xgi_info_t * info, u8 index, u16 data)
{
	OUTB(0x3C4, index);
	OUTB(0x3C5, data);
}

static inline void OUT3X5W(xgi_info_t * info, u8 index, u16 data)
{
	OUTB(0x3D4, index);
	OUTB(0x3D5, data);
}

static inline void OUT3CFW(xgi_info_t * info, u8 index, u8 data)
{
	OUTB(0x3CE, index);
	OUTB(0x3CF, data);
}

static inline u8 IN3C5W(xgi_info_t * info, u8 index)
{
	volatile u8 data = 0;
	OUTB(0x3C4, index);
	data = INB(0x3C5);
	return data;
}

static inline u8 IN3X5W(xgi_info_t * info, u8 index)
{
	volatile u8 data = 0;
	OUTB(0x3D4, index);
	data = INB(0x3D5);
	return data;
}

static inline u8 IN3CFW(xgi_info_t * info, u8 index)
{
	volatile u8 data = 0;
	OUTB(0x3CE, index);
	data = INB(0x3CF);
	return data;
}

static inline u8 readAttr(xgi_info_t * info, u8 index)
{
	INB(0x3DA);		/* flip-flop to index */
	OUTB(0x3C0, index);
	return INB(0x3C1);
}

static inline void writeAttr(xgi_info_t * info, u8 index, u8 value)
{
	INB(0x3DA);		/* flip-flop to index */
	OUTB(0x3C0, index);
	OUTB(0x3C0, value);
}

/*
 * Graphic engine register (2d/3d) acessing interface
 */
static inline void WriteRegDWord(xgi_info_t * info, u32 addr, u32 data)
{
	/* Jong 05/25/2006 */
	XGI_INFO("Jong-WriteRegDWord()-Begin \n");
	XGI_INFO("Jong-WriteRegDWord()-info->mmio.vbase=0x%lx \n",
		 info->mmio.vbase);
	XGI_INFO("Jong-WriteRegDWord()-addr=0x%lx \n", addr);
	XGI_INFO("Jong-WriteRegDWord()-data=0x%lx \n", data);
	/* return; */

	*(volatile u32 *)(info->mmio.vbase + addr) = (data);
	XGI_INFO("Jong-WriteRegDWord()-End \n");
}

static inline void WriteRegWord(xgi_info_t * info, u32 addr, u16 data)
{
	*(volatile u16 *)(info->mmio.vbase + addr) = (data);
}

static inline void WriteRegByte(xgi_info_t * info, u32 addr, u8 data)
{
	*(volatile u8 *)(info->mmio.vbase + addr) = (data);
}

static inline u32 ReadRegDWord(xgi_info_t * info, u32 addr)
{
	volatile u32 data;
	data = *(volatile u32 *)(info->mmio.vbase + addr);
	return data;
}

static inline u16 ReadRegWord(xgi_info_t * info, u32 addr)
{
	volatile u16 data;
	data = *(volatile u16 *)(info->mmio.vbase + addr);
	return data;
}

static inline u8 ReadRegByte(xgi_info_t * info, u32 addr)
{
	volatile u8 data;
	data = *(volatile u8 *)(info->mmio.vbase + addr);
	return data;
}

#if 0
extern void OUT3C5B(xgi_info_t * info, u8 index, u8 data);
extern void OUT3X5B(xgi_info_t * info, u8 index, u8 data);
extern void OUT3CFB(xgi_info_t * info, u8 index, u8 data);
extern u8 IN3C5B(xgi_info_t * info, u8 index);
extern u8 IN3X5B(xgi_info_t * info, u8 index);
extern u8 IN3CFB(xgi_info_t * info, u8 index);
extern void OUT3C5W(xgi_info_t * info, u8 index, u8 data);
extern void OUT3X5W(xgi_info_t * info, u8 index, u8 data);
extern void OUT3CFW(xgi_info_t * info, u8 index, u8 data);
extern u8 IN3C5W(xgi_info_t * info, u8 index);
extern u8 IN3X5W(xgi_info_t * info, u8 index);
extern u8 IN3CFW(xgi_info_t * info, u8 index);

extern void WriteRegDWord(xgi_info_t * info, u32 addr, u32 data);
extern void WriteRegWord(xgi_info_t * info, u32 addr, u16 data);
extern void WriteRegByte(xgi_info_t * info, u32 addr, u8 data);
extern u32 ReadRegDWord(xgi_info_t * info, u32 addr);
extern u16 ReadRegWord(xgi_info_t * info, u32 addr);
extern u8 ReadRegByte(xgi_info_t * info, u32 addr);

extern void EnableProtect();
extern void DisableProtect();
#endif

#define Out(port, data)         OUTB(port, data)
#define bOut(port, data)        OUTB(port, data)
#define wOut(port, data)        OUTW(port, data)
#define dwOut(port, data)       OUTDW(port, data)

#define Out3x5(index, data)     OUT3X5B(info, index, data)
#define bOut3x5(index, data)    OUT3X5B(info, index, data)
#define wOut3x5(index, data)    OUT3X5W(info, index, data)

#define Out3c5(index, data)     OUT3C5B(info, index, data)
#define bOut3c5(index, data)    OUT3C5B(info, index, data)
#define wOut3c5(index, data)    OUT3C5W(info, index, data)

#define Out3cf(index, data)     OUT3CFB(info, index, data)
#define bOut3cf(index, data)    OUT3CFB(info, index, data)
#define wOut3cf(index, data)    OUT3CFW(info, index, data)

#define In(port)                INB(port)
#define bIn(port)               INB(port)
#define wIn(port)               INW(port)
#define dwIn(port)              INDW(port)

#define In3x5(index)            IN3X5B(info, index)
#define bIn3x5(index)           IN3X5B(info, index)
#define wIn3x5(index)           IN3X5W(info, index)

#define In3c5(index)            IN3C5B(info, index)
#define bIn3c5(index)           IN3C5B(info, index)
#define wIn3c5(index)           IN3C5W(info, index)

#define In3cf(index)            IN3CFB(info, index)
#define bIn3cf(index)           IN3CFB(info, index)
#define wIn3cf(index)           IN3CFW(info, index)

#define dwWriteReg(addr, data)  WriteRegDWord(info, addr, data)
#define wWriteReg(addr, data)   WriteRegWord(info, addr, data)
#define bWriteReg(addr, data)   WriteRegByte(info, addr, data)
#define dwReadReg(addr)         ReadRegDWord(info, addr)
#define wReadReg(addr)          ReadRegWord(info, addr)
#define bReadReg(addr)          ReadRegByte(info, addr)

static inline void xgi_protect_all(xgi_info_t * info)
{
	OUTB(0x3C4, 0x11);
	OUTB(0x3C5, 0x92);
}

static inline void xgi_unprotect_all(xgi_info_t * info)
{
	OUTB(0x3C4, 0x11);
	OUTB(0x3C5, 0x92);
}

static inline void xgi_enable_mmio(xgi_info_t * info)
{
	u8 protect = 0;

	/* Unprotect registers */
	outb(0x11, 0x3C4);
	protect = inb(0x3C5);
	outb(0x92, 0x3C5);

	outb(0x3A, 0x3D4);
	outb(inb(0x3D5) | 0x20, 0x3D5);

	/* Enable MMIO */
	outb(0x39, 0x3D4);
	outb(inb(0x3D5) | 0x01, 0x3D5);

	OUTB(0x3C4, 0x11);
	OUTB(0x3C5, protect);
}

static inline void xgi_disable_mmio(xgi_info_t * info)
{
	u8 protect = 0;

	/* unprotect registers */
	OUTB(0x3C4, 0x11);
	protect = INB(0x3C5);
	OUTB(0x3C5, 0x92);

	/* Disable MMIO access */
	OUTB(0x3D4, 0x39);
	OUTB(0x3D5, INB(0x3D5) & 0xFE);

	/* Protect registers */
	outb(0x11, 0x3C4);
	outb(protect, 0x3C5);
}

static inline void xgi_enable_ge(xgi_info_t * info)
{
	unsigned char bOld3cf2a = 0;
	int wait = 0;

	// Enable GE
	OUTW(0x3C4, 0x9211);

	// Save and close dynamic gating
	bOld3cf2a = bIn3cf(0x2a);
	bOut3cf(0x2a, bOld3cf2a & 0xfe);

	// Reset both 3D and 2D engine
	bOut3x5(0x36, 0x84);
	wait = 10;
	while (wait--) {
		bIn(0x36);
	}
	bOut3x5(0x36, 0x94);
	wait = 10;
	while (wait--) {
		bIn(0x36);
	}
	bOut3x5(0x36, 0x84);
	wait = 10;
	while (wait--) {
		bIn(0x36);
	}
	// Enable 2D engine only
	bOut3x5(0x36, 0x80);

	// Enable 2D+3D engine
	bOut3x5(0x36, 0x84);

	// Restore dynamic gating
	bOut3cf(0x2a, bOld3cf2a);
}

static inline void xgi_disable_ge(xgi_info_t * info)
{
	int wait = 0;

	// Reset both 3D and 2D engine
	bOut3x5(0x36, 0x84);

	wait = 10;
	while (wait--) {
		bIn(0x36);
	}
	bOut3x5(0x36, 0x94);

	wait = 10;
	while (wait--) {
		bIn(0x36);
	}
	bOut3x5(0x36, 0x84);

	wait = 10;
	while (wait--) {
		bIn(0x36);
	}

	// Disable 2D engine only
	bOut3x5(0x36, 0);
}

static inline void xgi_enable_dvi_interrupt(xgi_info_t * info)
{
	Out3cf(0x39, In3cf(0x39) & ~0x01);	//Set 3cf.39 bit 0 to 0
	Out3cf(0x39, In3cf(0x39) | 0x01);	//Set 3cf.39 bit 0 to 1
	Out3cf(0x39, In3cf(0x39) | 0x02);
}
static inline void xgi_disable_dvi_interrupt(xgi_info_t * info)
{
	Out3cf(0x39, In3cf(0x39) & ~0x02);
}

static inline void xgi_enable_crt1_interrupt(xgi_info_t * info)
{
	Out3cf(0x3d, In3cf(0x3d) | 0x04);
	Out3cf(0x3d, In3cf(0x3d) & ~0x04);
	Out3cf(0x3d, In3cf(0x3d) | 0x08);
}

static inline void xgi_disable_crt1_interrupt(xgi_info_t * info)
{
	Out3cf(0x3d, In3cf(0x3d) & ~0x08);
}

#endif