summaryrefslogtreecommitdiff
path: root/src/impact_regs.c
blob: 847946931032c67e3f3998fc506be49f975bcf14 (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
/*
 * impact_regs.c 2005/07/15 23:36:16, Copyright (c) 2005 peter fuerst
 *
 * Based on:
 * - linux/drivers/video/impact.c, 2005 pf.
 * - linux/drivers/video/impactsr.c, (c) 2004 by Stanislaw Skowronek.
 * - newport_regs.c
 *   # newport_regs.c,v 1.3 2000/11/29 20:58:10 agx Exp #
 *   # xc/programs/Xserver/hw/xfree86/drivers/newport/newport_regs.c,v
 *     1.6 2001/12/21 15:37:23 tsi Exp #
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "impact.h"

/* FIFO status */
#define MSK_I2_CFIFO_CNT    0x7f
#define MSK_SR_CFIFO_CNT    0xff
#define IMPACTI2_CFIFO_MAX	64
#define IMPACTSR_CFIFO_MAX	128
#define IMPACT_BFIFO_MAX	16

/* Sometimes we just have to wait until we can do anything */

/*
 * ImpactWaitCfifo
 */
unsigned
ImpactI2WaitCfifo(ImpactRegsPtr pImpactRegs, int nslots)
{
	unsigned x;
	while (((x = pImpactRegs->i2.fifostatus) & MSK_I2_CFIFO_CNT)
		> IMPACTI2_CFIFO_MAX-nslots);
	return x;
}

unsigned
ImpactSRWaitCfifo(ImpactRegsPtr pImpactRegs, int nslots)
{
	unsigned x;
	while (((x = pImpactRegs->sr.fifostatus) & MSK_SR_CFIFO_CNT)
		> IMPACTSR_CFIFO_MAX-nslots);
	return x;
}

/*
 * ImpactWaitCfifoEmpty
 */
void
ImpactI2WaitCfifoEmpty(ImpactRegsPtr pImpactRegs)
{
	while (pImpactRegs->i2.fifostatus & MSK_I2_CFIFO_CNT);
}

void
ImpactSRWaitCfifoEmpty(ImpactRegsPtr pImpactRegs)
{
	while (pImpactRegs->sr.fifostatus & MSK_SR_CFIFO_CNT);
}

/*
 * ImpactWaitDMAOver
 */
void
ImpactI2WaitDMAOver(ImpactRegsPtr pImpactRegs)
{
	while (pImpactRegs->i2.dmabusy & 0x1F);
	while (!(pImpactRegs->i2.status & 1));
	while (!(pImpactRegs->i2.status & 2));
	while (!(pImpactRegs->i2.rss.status & 0x100));
}

void
ImpactSRWaitDMAOver(ImpactRegsPtr pImpactRegs)
{
	while (pImpactRegs->sr.dmabusy & 0x1F);
	while (!(pImpactRegs->sr.status & 1));
	while (!(pImpactRegs->sr.status & 2));
	while (!(pImpactRegs->sr.rss.status & 0x100));
}

/*
 * ImpactWaitDMAReady
 */
void
ImpactI2WaitDMAReady(ImpactRegsPtr pImpactRegs)
{
	ImpactFifoCmd32(&pImpactRegs->i2.cfifo, 0x000e0100, 0);
	while (pImpactRegs->i2.dmabusy & 0x1EFF);
	while (!(pImpactRegs->i2.status & 2));
}

void
ImpactSRWaitDMAReady(ImpactRegsPtr pImpactRegs)
{
	ImpactFifoCmd32(&pImpactRegs->sr.cfifo, 0x000e0100, 0);
	while (pImpactRegs->sr.dmabusy & 0x1EFF);
	while (!(pImpactRegs->sr.status & 2));
}

/*
 * ImpactWaitBfifo
 */
static __inline__ unsigned
ImpactWaitBfifo(mgireg32_t *giostatus, int nslots)
{
	unsigned x;
	while (((x = *giostatus) & 0x1f) > IMPACT_BFIFO_MAX-nslots);
	return x;
}

unsigned
ImpactI2WaitBfifo(ImpactRegsPtr pImpactRegs, int nslots)
{
	return ImpactWaitBfifo(&pImpactRegs->i2.giostatus, nslots);
}

unsigned
ImpactSRWaitBfifo(ImpactRegsPtr pImpactRegs, int nslots)
{
	return ImpactWaitBfifo(&pImpactRegs->sr.giostatus, nslots);
}

/*
 * ImpactWaitBfifoEmpty
 */
static __inline__ void
ImpactWaitBfifoEmpty(mgireg32_t *giostatus)
{
	while (*giostatus & 0x1f);
}

void
ImpactI2WaitBfifoEmpty(ImpactRegsPtr pImpactRegs)
{
	ImpactWaitBfifoEmpty(&pImpactRegs->i2.giostatus);
}

void
ImpactSRWaitBfifoEmpty(ImpactRegsPtr pImpactRegs)
{
	ImpactWaitBfifoEmpty(&pImpactRegs->sr.giostatus);
}

/*
 * ImpactVc3[GS]et
 */
static __inline__ void
ImpactVc3Set(Impact_vc3regs_t* vc3, CARD8 idx, unsigned short val)
{
	vc3->indexdata = (idx << 24) | (val << 8);
}

void 
ImpactI2Vc3Set(ImpactRegsPtr pImpactRegs, CARD8 idx, unsigned short val)
{
	ImpactVc3Set(&pImpactRegs->i2.vc3, idx, val);
}

void 
ImpactSRVc3Set(ImpactRegsPtr pImpactRegs, CARD8 idx, unsigned short val)
{
	ImpactVc3Set(&pImpactRegs->sr.vc3, idx, val);
}

static __inline__ unsigned short 
ImpactVc3Get(Impact_vc3regs_t* vc3, CARD8 idx)
{
	vc3->index = idx;
	return vc3->data;
}

unsigned short 
ImpactI2Vc3Get(ImpactRegsPtr pImpactRegs, CARD8 idx)
{
	return ImpactVc3Get(&pImpactRegs->i2.vc3, idx);
}

unsigned short 
ImpactSRVc3Get(ImpactRegsPtr pImpactRegs, CARD8 idx)
{
	return ImpactVc3Get(&pImpactRegs->sr.vc3, idx);
}


/*
 * ImpactXmap[GS]etModeRegister
 */
static __inline__ void
ImpactXmapSetModeRegister(Impact_xmapregs_t *xmap, CARD8 address, CARD32 mode)
{
	xmap->index = address << 2;
	xmap->main_mode = mode;
}

void
ImpactI2XmapSetModeRegister(ImpactRegsPtr pImpactRegs, CARD8 address, CARD32 mode)
{
	ImpactXmapSetModeRegister(&pImpactRegs->i2.xmap, address, mode);
}

void
ImpactSRXmapSetModeRegister(ImpactRegsPtr pImpactRegs, CARD8 address, CARD32 mode)
{
	ImpactXmapSetModeRegister(&pImpactRegs->sr.xmap, address, mode);
}

static __inline__ CARD32
ImpactXmapGetModeRegister(Impact_xmapregs_t *xmap, CARD8 address)
{
	xmap->index = address << 2;
	return xmap->main_mode;
}

CARD32
ImpactI2XmapGetModeRegister(ImpactRegsPtr pImpactRegs, CARD8 address)
{
	return ImpactXmapGetModeRegister(&pImpactRegs->i2.xmap, address);
}

CARD32
ImpactSRXmapGetModeRegister(ImpactRegsPtr pImpactRegs, CARD8 address)
{
	return ImpactXmapGetModeRegister(&pImpactRegs->sr.xmap, address);
}

/*
 * ImpactBackup.../ImpactRestore...
 */
void 
ImpactBackupVc3( ScrnInfoPtr pScrn )
{
	ImpactPtr pImpact = IMPACTPTR(pScrn);
	ImpactRegsPtr pImpactRegs = pImpact->pImpactRegs;

	CARD8 i = sizeof(pImpact->txt_vc3)/sizeof(*pImpact->txt_vc3);
	while (i--)
		pImpact->txt_vc3[i] = (*pImpact->Vc3Get)( pImpactRegs, i );
}

void
ImpactRestoreVc3( ScrnInfoPtr pScrn )
{
	ImpactPtr pImpact = IMPACTPTR(pScrn);
	ImpactRegsPtr pImpactRegs = pImpact->pImpactRegs;

	CARD8 i = sizeof(pImpact->txt_vc3)/sizeof(*pImpact->txt_vc3);
	while (i--)
		(*pImpact->Vc3Set)( pImpactRegs, i, pImpact->txt_vc3[i] );
}

void
ImpactVc3DisableCursor( ScrnInfoPtr pScrn )
{
	ImpactPtr pImpact = IMPACTPTR(pScrn);
	ImpactRegsPtr pImpactRegs = pImpact->pImpactRegs;

	unsigned short val = (*pImpact->Vc3Get)( pImpactRegs, VC3_IREG_CURSOR );
	(*pImpact->Vc3Set)(pImpactRegs, VC3_IREG_CURSOR, val & ~VC3_CTRL_ECURS);
}

void 
ImpactVc3BlankScreen( ScrnInfoPtr pScrn, int blank )
{/*                                                 
	ImpactPtr pImpact = IMPACTPTR(pScrn);
	ImpactRegsPtr pImpactRegs = pImpact->pImpactRegs;

	unsigned short treg = (*pImpact->Vc3Get)( pImpactRegs, VC3_IREG_CONTROL );
	if (blank)
		treg &= ~VC3_CTRL_EDISP;
	else
		treg |= VC3_CTRL_EDISP;
	(*pImpact->Vc3Set)( pImpactRegs, VC3_IREG_CONTROL, treg );
*/}

void 
ImpactBackupRex( ScrnInfoPtr pScrn )
{
}

void
ImpactRestoreRex( ScrnInfoPtr pScrn )
{
}

void ImpactBackupXmap( ScrnInfoPtr pScrn )
{
	ImpactPtr pImpact = IMPACTPTR(pScrn);
	ImpactRegsPtr pImpactRegs = pImpact->pImpactRegs;
	Impact_xmapregs_t *xmap =
		(&ImpactSRXmapGetModeRegister != pImpact->XmapGetModeRegister)
			? &pImpactRegs->i2.xmap
			: &pImpactRegs->sr.xmap;

	pImpact->txt_xmap.pp1select = xmap->pp1select;
	pImpact->txt_xmap.main_mode =
			(*pImpact->XmapGetModeRegister)( pImpactRegs, 0 );
}

void ImpactRestoreXmap( ScrnInfoPtr pScrn )
{
	ImpactPtr pImpact = IMPACTPTR(pScrn);
	ImpactRegsPtr pImpactRegs = pImpact->pImpactRegs;
	Impact_xmapregs_t *xmap =
		(&ImpactSRXmapGetModeRegister != pImpact->XmapGetModeRegister)
			? &pImpactRegs->i2.xmap
			: &pImpactRegs->sr.xmap;

	xmap->pp1select = pImpact->txt_xmap.pp1select;
	(*pImpact->XmapSetModeRegister)(
			pImpactRegs, 0, pImpact->txt_xmap.main_mode );
}

/* set XMAP into 24-bpp mode */

void
ImpactXmapSet24bpp( ScrnInfoPtr pScrn )
{
	ImpactPtr pImpact = IMPACTPTR(pScrn);
	ImpactRegsPtr pImpactRegs = pImpact->pImpactRegs;
	Impact_xmapregs_t *xmap =
		(&ImpactSRXmapGetModeRegister != pImpact->XmapGetModeRegister)
			? &pImpactRegs->i2.xmap
			: &pImpactRegs->sr.xmap;
	xmap->pp1select = 1;
	(*pImpact->XmapSetModeRegister)( pImpactRegs, 0, 0x07a4 );
}

/* eof */