summaryrefslogtreecommitdiff
path: root/src/ct_driver.h
blob: 831ac9ba91cc88d05a6d93b2f1c78e8aa82a2660 (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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
/* $XConsortium: ct_driver.h /main/3 1996/10/27 11:49:29 kaleb $ */
/*
 * Modified 1996 by Egbert Eich <eich@xfree86.org>
 * Modified 1996 by David Bateman <dbateman@club-internet.fr>
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the authors not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  The authors makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as is" without express or implied warranty.
 *
 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/ct_driver.h,v 1.34 2002/01/25 21:56:00 tsi Exp $ */


#ifndef _CT_DRIVER_H_
#define _CT_DRIVER_H_

#include "xaa.h"
#include "vbe.h"
#include "xaalocal.h"		/* XAA internals as we replace some of XAA */
#include "xf86Cursor.h"
#include "xf86i2c.h"
#include "xf86DDC.h"
#include "xf86xv.h"
#include "vgaHW.h"

/* Supported chipsets */
typedef enum {
    CHIPS_CT65520,
    CHIPS_CT65525,
    CHIPS_CT65530,
    CHIPS_CT65535,
    CHIPS_CT65540,
    CHIPS_CT65545,
    CHIPS_CT65546,
    CHIPS_CT65548,
    CHIPS_CT65550,
    CHIPS_CT65554,
    CHIPS_CT65555,
    CHIPS_CT68554,
    CHIPS_CT69000,
    CHIPS_CT69030,
    CHIPS_CT64200,
    CHIPS_CT64300
} CHIPSType;

/* Clock related */
typedef struct {
    unsigned char msr;		/* Dot Clock Related */
    unsigned char fcr;
    unsigned char xr02;
    unsigned char xr03;
    unsigned char xr33;
    unsigned char xr54;
    unsigned char fr03;
    int Clock;
    int FPClock;
} CHIPSClockReg, *CHIPSClockPtr;

typedef struct {
    unsigned int ProbedClk;
    unsigned int Max;		/* Memory Clock Related */
    unsigned int Clk;
    unsigned char M;
    unsigned char N;
    unsigned char P;
    unsigned char PSN;
    unsigned char xrCC;
    unsigned char xrCD;
    unsigned char xrCE;
} CHIPSMemClockReg, *CHIPSMemClockPtr;

#define TYPE_HW 0x01
#define TYPE_PROGRAMMABLE 0x02
#define GET_TYPE 0x0F
#define OLD_STYLE 0x10
#define NEW_STYLE 0x20
#define HiQV_STYLE 0x30
#define WINGINE_1_STYLE 0x40        /* 64300: external clock; 4 clocks    */
#define WINGINE_2_STYLE 0x50        /* 64300: internal clock; 2 hw-clocks */
#define GET_STYLE 0xF0
#define LCD_TEXT_CLK_FREQ 25000	    /* lcd textclock if TYPE_PROGRAMMABLE */
#define CRT_TEXT_CLK_FREQ 28322     /* crt textclock if TYPE_PROGRAMMABLE */
#define Fref 14318180               /* The reference clock in Hertz       */

/* The capability flags for the C&T chipsets */
#define ChipsLinearSupport	0x00000001
#define ChipsAccelSupport	0x00000002
#define ChipsFullMMIOSupport	0x00000004
#define ChipsMMIOSupport	0x00000008
#define ChipsHDepthSupport	0x00000010
#define ChipsDPMSSupport	0x00000020
#define ChipsTMEDSupport	0x00000040
#define ChipsGammaSupport	0x00000080
#define ChipsVideoSupport	0x00000100
#define ChipsDualChannelSupport	0x00000200
#define ChipsDualRefresh	0x00000400

/* Options flags for the C&T chipsets */
#define ChipsHWCursor		0x00001000
#define ChipsShadowFB		0x00002000
#define ChipsOverlay8plus16	0x00004000
#define ChipsUseNewFB		0x00008000

/* Architecture type flags */
#define ChipsHiQV		0x00010000
#define ChipsWingine		0x00020000
#define IS_Wingine(x)		((x->Flags) & ChipsWingine)
#define IS_HiQV(x)		((x->Flags) & ChipsHiQV)

/* Acceleration flags for the C&T chipsets */
#define ChipsColorTransparency	0x0100000
#define ChipsImageReadSupport	0x0200000

/* Overlay Transparency Key */
#define TRANSPARENCY_KEY 255

/* Flag Bus Types */
#define ChipsUnknown	0
#define ChipsISA	1
#define ChipsVLB	2
#define ChipsPCI	3
#define ChipsCPUDirect	4
#define ChipsPIB	5
#define ChipsMCB	6

/* Macro's to select the 32 bit acceleration registers */
#define DR(x) cPtr->Regs32[x]	/* For CT655xx naming scheme  */
#define MR(x) cPtr->Regs32[x]	/* CT655xx MMIO naming scheme */
#define BR(x) cPtr->Regs32[x]	/* For HiQV naming scheme     */
#define MMIOmeml(x) *(CARD32 *)(cPtr->MMIOBase + (x))
#if 0
#define MMIOmemw(x) *(CARD16 *)(cPtr->MMIOBase + (x))
#endif
/* Monitor or flat panel type flags */
#define ChipsCRT	0x0010
#define ChipsLCD	0x1000
#define ChipsLCDProbed	0x2000
#define ChipsTFT	0x0100
#define ChipsDS		0x0200
#define ChipsDD		0x0400
#define ChipsSS		0x0800
#define IS_STN(x)	((x) & 0xE00)

/* Dual channel register enable masks */
#define IOSS_MASK	0xE0
#define IOSS_BOTH	0x13
#define IOSS_PIPE_A	0x11
#define IOSS_PIPE_B	0x1E
#define MSS_MASK	0xF0
#define MSS_BOTH	0x0B
#define MSS_PIPE_A	0x02
#define MSS_PIPE_B	0x05
/* Aggregate value of MSS shadow bits -GHB */
#define MSS_SHADOW  0x07

/* Storage for the registers of the C&T chipsets */
typedef struct {
	unsigned char XR[0xFF];
	unsigned char CR[0x80];
	unsigned char FR[0x80];
	unsigned char MR[0x80];
	CHIPSClockReg Clock;
} CHIPSRegRec, *CHIPSRegPtr;

/* Storage for the flat panel size */
typedef struct {
    int HDisplay;
    int HRetraceStart;
    int HRetraceEnd;
    int HTotal;
    int VDisplay;
    int VRetraceStart;
    int VTotal;
} CHIPSPanelSizeRec, *CHIPSPanelSizePtr;

/* Some variables needed in the XAA acceleration */
typedef struct {
    /* General variable */ 
    unsigned int CommandFlags;
    unsigned int BytesPerPixel;
    unsigned int BitsPerPixel;
    unsigned int FbOffset;
    unsigned int PitchInBytes;
    unsigned int ScratchAddress;
    /* 64k for color expansion and imagewrites */
    unsigned char * BltDataWindow;
    /* Hardware cursor address */
    unsigned int CursorAddress;
    Bool UseHWCursor;
    /* Boundaries of the pixmap cache */
    unsigned int CacheStart;
    unsigned int CacheEnd;
    /* Storage for pattern mask */
    int planemask;
    /* Storage for foreground and background color */
    int fgColor;
    int bgColor;
    /* For the 8x8 pattern fills */
    int patternyrot;
    /* For cached stipple fills */
    int SlotWidth;
    /* Variables for the 24bpp fill */
    unsigned char fgpixel;
    unsigned char bgpixel;
    unsigned char xorpixel;
    Bool fastfill;
    Bool rgb24equal;
    int fillindex;
    unsigned int width24bpp;
    unsigned int color24bpp;
    unsigned int rop24bpp;
} CHIPSACLRec, *CHIPSACLPtr;
#define CHIPSACLPTR(p)	&((CHIPSPtr)((p)->driverPrivate))->Accel

/* Storage for some register values that are messed up by suspend/resumes */
typedef struct {
    unsigned char xr02;
    unsigned char xr03;
    unsigned char xr14;
    unsigned char xr15;
    unsigned char vgaIOBaseFlag;
} CHIPSSuspendHackRec, *CHIPSSuspendHackPtr;

/* The functions to access the C&T extended registers */
typedef struct _CHIPSRec *CHIPSPtr;
typedef CARD8 (*chipsReadXRPtr)(CHIPSPtr cPtr, CARD8 index);
typedef void (*chipsWriteXRPtr)(CHIPSPtr cPtr, CARD8 index, CARD8 value);
typedef CARD8 (*chipsReadFRPtr)(CHIPSPtr cPtr, CARD8 index);
typedef void (*chipsWriteFRPtr)(CHIPSPtr cPtr, CARD8 index, CARD8 value);
typedef CARD8 (*chipsReadMRPtr)(CHIPSPtr cPtr, CARD8 index);
typedef void (*chipsWriteMRPtr)(CHIPSPtr cPtr, CARD8 index, CARD8 value);
typedef CARD8 (*chipsReadMSSPtr)(CHIPSPtr cPtr);
typedef void (*chipsWriteMSSPtr)(CHIPSPtr cPtr, vgaHWPtr hwp, CARD8 value);
typedef CARD8 (*chipsReadIOSSPtr)(CHIPSPtr cPtr);
typedef void (*chipsWriteIOSSPtr)(CHIPSPtr cPtr, CARD8 value);

/* The privates of the C&T driver */
#define CHIPSPTR(p)	((CHIPSPtr)((p)->driverPrivate))


typedef struct {
    int			lastInstance;
    int			refCount;
    CARD32		masterFbAddress;
    long		masterFbMapSize;
    CARD32		slaveFbAddress;
    long		slaveFbMapSize;
    int			mastervideoRam;
    int			slavevideoRam;
    Bool		masterOpen;
    Bool		slaveOpen;
    Bool		masterActive;
    Bool		slaveActive;
} CHIPSEntRec, *CHIPSEntPtr;


typedef struct _CHIPSRec {
    pciVideoPtr		PciInfo;
    PCITAG		PciTag;
    int			Chipset;
    EntityInfoPtr       pEnt;
    IOADDRESS		PIOBase;
    CARD32		IOAddress;
    unsigned long	FbAddress;
    unsigned int	IOBase;
    unsigned char *	FbBase;
    unsigned char *	MMIOBase;
    unsigned char *	MMIOBaseVGA;
    unsigned char *	MMIOBasePipeA;
    unsigned char *	MMIOBasePipeB;
    long		FbMapSize;
    unsigned char *	ShadowPtr;
    int			ShadowPitch;
    int                 Rotate;
    void		(*PointerMoved)(int index, int x, int y);
    int                 FbOffset16;
    int                 FbSize16;  
    OptionInfoPtr	Options;
    CHIPSPanelSizeRec	PanelSize;
    int			FrameBufferSize;
    Bool		SyncResetIgn;
    Bool		UseMMIO;
    Bool		UseFullMMIO;
    Bool		UseDualChannel;
    int			Monitor;
    int			MinClock;
    int			MaxClock;
    CHIPSClockReg	SaveClock;		/* Storage for ClockSelect */
    CHIPSMemClockReg	MemClock;
    unsigned char	ClockType;
    unsigned char	CRTClk[4];
    unsigned char       FPClk[4];
    int                 FPclock;
    int                 FPclkInx;
    int                 CRTclkInx;
    Bool                FPClkModified;
    int			ClockMulFactor;
    int			Rounding;
    CHIPSSuspendHackRec	SuspendHack;
    CARD32		PanelType;
    CHIPSRegRec		ModeReg;
    CHIPSRegRec		SavedReg;
    CHIPSRegRec		SavedReg2;
    vgaRegRec		VgaSavedReg2;
    unsigned int *	Regs32;
    unsigned int	Flags;
    CARD32		Bus;
    XAAInfoRecPtr	AccelInfoRec;
    xf86CursorInfoPtr	CursorInfoRec;
    CHIPSACLRec		Accel;
    unsigned int	HWCursorContents;
    Bool		HWCursorShown;
    DGAModePtr		DGAModes;
    int			numDGAModes;
    Bool		DGAactive;
    int			DGAViewportStatus;
    CloseScreenProcPtr	CloseScreen;
    ScreenBlockHandlerProcPtr BlockHandler;
    void		(*VideoTimerCallback)(ScrnInfoPtr, Time);
    int			videoKey;
    XF86VideoAdaptorPtr	adaptor;
    int			OverlaySkewX;
    int			OverlaySkewY;
    int			VideoZoomMax;
    Bool		SecondCrtc;
    CHIPSEntPtr		entityPrivate;
    unsigned char	storeMSS;
    unsigned char	storeIOSS;
#ifdef __arm32__
#ifdef __NetBSD__
    int			TVMode;
#endif
    int			Bank;
#endif
    unsigned char       ddc_mask;
    I2CBusPtr           I2C;
    vbeInfoPtr          pVbe;
    chipsReadXRPtr	readXR;
    chipsWriteXRPtr	writeXR;
    chipsReadFRPtr	readFR;
    chipsWriteFRPtr	writeFR;
    chipsReadMRPtr	readMR;
    chipsWriteMRPtr	writeMR;
    chipsReadMSSPtr	readMSS;
    chipsWriteMSSPtr	writeMSS;
    chipsReadIOSSPtr	readIOSS;
    chipsWriteIOSSPtr	writeIOSS;
    Bool cursorDelay;
    unsigned int viewportMask;
} CHIPSRec;

typedef struct _CHIPSi2c {
  unsigned char i2cClockBit;
  unsigned char i2cDataBit;
  CHIPSPtr cPtr;
} CHIPSI2CRec, *CHIPSI2CPtr;

/* External variables */
extern int ChipsAluConv[];
extern int ChipsAluConv2[];
extern int ChipsAluConv3[];
extern unsigned int ChipsReg32[];
extern unsigned int ChipsReg32HiQV[];

/* Prototypes */

void CHIPSAdjustFrame(int scrnIndex, int x, int y, int flags);
Bool CHIPSSwitchMode(int scrnIndex, DisplayModePtr mode, int flags);

/* video */
void CHIPSInitVideo(ScreenPtr pScreen);
void CHIPSResetVideo(ScrnInfoPtr pScrn);

/* banking */
int CHIPSSetRead(ScreenPtr pScreen, int bank);
int CHIPSSetWrite(ScreenPtr pScreen, int bank);
int CHIPSSetReadWrite(ScreenPtr pScreen, int bank);
int CHIPSSetReadPlanar(ScreenPtr pScreen, int bank);
int CHIPSSetWritePlanar(ScreenPtr pScreen, int bank);
int CHIPSSetReadWritePlanar(ScreenPtr pScreen, int bank);
int CHIPSWINSetRead(ScreenPtr pScreen, int bank);
int CHIPSWINSetWrite(ScreenPtr pScreen, int bank);
int CHIPSWINSetReadWrite(ScreenPtr pScreen, int bank);
int CHIPSWINSetReadPlanar(ScreenPtr pScreen, int bank);
int CHIPSWINSetWritePlanar(ScreenPtr pScreen, int bank);
int CHIPSWINSetReadWritePlanar(ScreenPtr pScreen, int bank);
int CHIPSHiQVSetReadWrite(ScreenPtr pScreen, int bank);
int CHIPSHiQVSetReadWritePlanar(ScreenPtr pScreen, int bank);

/* acceleration */
Bool CHIPSAccelInit(ScreenPtr pScreen);
void CHIPSSync(ScrnInfoPtr pScrn);
Bool CHIPSMMIOAccelInit(ScreenPtr pScreen);
void CHIPSMMIOSync(ScrnInfoPtr pScrn);
Bool CHIPSHiQVAccelInit(ScreenPtr pScreen);
void CHIPSHiQVSync(ScrnInfoPtr pScrn);
Bool CHIPSCursorInit(ScreenPtr pScreen);

/* register access functions */
void CHIPSSetStdExtFuncs(CHIPSPtr cPtr);
void CHIPSSetMmioExtFuncs(CHIPSPtr cPtr);
void CHIPSHWSetMmioFuncs(ScrnInfoPtr pScrn, CARD8 *base, int offset);

/* ddc */
extern void chips_ddc1(ScrnInfoPtr pScrn);
extern Bool chips_i2cInit(ScrnInfoPtr pScrn);

/* dga */
Bool CHIPSDGAInit(ScreenPtr pScreen);

/* shadow fb */
void     chipsRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
void     chipsRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
void     chipsRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
void     chipsRefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
void     chipsRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
void     chipsPointerMoved(int index, int x, int y);


/*
 * Some macros for switching display channels. NOTE... It appears that we
 * can't write to both display channels at the same time, and so the options
 * MSS_BOTH and IOSS_BOTH should not be used. Need to get around this by set
 * dual channel mode to pipe A by default and handling multiple channel writes
 * in ModeInit..
 */

#define DUALOPEN \
    {									      \
        /* Set the IOSS/MSS registers to point to the right register set */   \
	if (xf86IsEntityShared(pScrn->entityList[0])) { 		      \
	    if (cPtr->SecondCrtc == TRUE) {				      \
		cPtr->writeIOSS(cPtr, ((cPtr->storeIOSS & IOSS_MASK) |	      \
					IOSS_PIPE_B));			      \
		cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), ((cPtr->storeMSS &      \
					MSS_MASK) | MSS_PIPE_B));	      \
		cPtrEnt->slaveOpen = TRUE;				      \
		cPtrEnt->slaveActive = TRUE;				      \
		cPtrEnt->masterActive = FALSE;				      \
	    } else {							      \
		cPtr->writeIOSS(cPtr, ((cPtr->storeIOSS & IOSS_MASK) |	      \
					IOSS_PIPE_A));			      \
		cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), ((cPtr->storeMSS &      \
					MSS_MASK) | MSS_PIPE_A));	      \
		cPtrEnt->masterOpen = TRUE;				      \
		cPtrEnt->masterActive = TRUE;				      \
		cPtrEnt->slaveActive = FALSE;				      \
	    }								      \
	} else {							      \
	    cPtr->writeIOSS(cPtr, ((cPtr->storeIOSS & IOSS_MASK) | 	      \
					IOSS_PIPE_A));			      \
	    cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), ((cPtr->storeMSS &	      \
					MSS_MASK) | MSS_PIPE_A));	      \
	}								      \
    }

#define DUALREOPEN							      \
    {									      \
	if (xf86IsEntityShared(pScrn->entityList[0])) { 		      \
	    if (cPtr->SecondCrtc == TRUE) {				      \
		if (! cPtrEnt->slaveActive) {				      \
		    cPtr->writeIOSS(cPtr, ((cPtr->storeIOSS & IOSS_MASK) |    \
					IOSS_PIPE_B));			      \
		    cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), ((cPtr->storeMSS &  \
					MSS_MASK) | MSS_PIPE_B));	      \
		    cPtrEnt->slaveOpen = TRUE;				      \
		    cPtrEnt->slaveActive = TRUE;			      \
		    cPtrEnt->masterActive = FALSE;			      \
		}							      \
	    } else {							      \
		if (! cPtrEnt->masterActive) {				      \
		    cPtr->writeIOSS(cPtr, ((cPtr->storeIOSS & IOSS_MASK) |    \
					IOSS_PIPE_A));			      \
		    cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), ((cPtr->storeMSS &  \
					MSS_MASK) | MSS_PIPE_A));	      \
		    cPtrEnt->masterOpen = TRUE;				      \
		    cPtrEnt->masterActive = TRUE;			      \
		    cPtrEnt->slaveActive = FALSE;			      \
		}							      \
	    }								      \
	}								      \
    }

#define DUALCLOSE							      \
    {									      \
	if (! xf86IsEntityShared(pScrn->entityList[0])) {		      \
	    cPtr->writeIOSS(cPtr, ((cPtr->storeIOSS & IOSS_MASK) |	      \
			       IOSS_PIPE_A));				      \
	    cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), ((cPtr->storeMSS &	      \
				MSS_MASK) | MSS_PIPE_A));		      \
	    chipsHWCursorOff(cPtr, pScrn);				      \
	    chipsRestore(pScrn, &(VGAHWPTR(pScrn))->SavedReg,		      \
				&cPtr->SavedReg, TRUE);			      \
	    chipsLock(pScrn);						      \
	    cPtr->writeIOSS(cPtr, ((cPtr->storeIOSS & IOSS_MASK) |	      \
			       IOSS_PIPE_B));				      \
	    cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), ((cPtr->storeMSS &	      \
				MSS_MASK) | MSS_PIPE_B)); 		      \
	    chipsHWCursorOff(cPtr, pScrn);				      \
	    chipsRestore(pScrn, &cPtr->VgaSavedReg2, &cPtr->SavedReg2, TRUE); \
	    cPtr->writeIOSS(cPtr, cPtr->storeIOSS);			      \
	    cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), cPtr->storeMSS);	      \
	    chipsLock(pScrn);						      \
	} else {							      \
	    chipsHWCursorOff(cPtr, pScrn);				      \
	    chipsRestore(pScrn, &(VGAHWPTR(pScrn))->SavedReg, &cPtr->SavedReg,\
					TRUE);				      \
	    if (cPtr->SecondCrtc == TRUE) {				      \
		cPtrEnt->slaveActive = FALSE;				      \
		cPtrEnt->slaveOpen = FALSE;				      \
		if (! cPtrEnt->masterActive) {				      \
		    cPtr->writeIOSS(cPtr, cPtr->storeIOSS);		      \
		    cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), cPtr->storeMSS);    \
		    chipsLock(pScrn);					      \
		}							      \
	    } else {							      \
		cPtrEnt->masterActive = FALSE;				      \
		cPtrEnt->masterOpen = FALSE;				      \
		if (! cPtrEnt->slaveActive) {				      \
		    cPtr->writeIOSS(cPtr, cPtr->storeIOSS);		      \
		    cPtr->writeMSS(cPtr, VGAHWPTR(pScrn), cPtr->storeMSS);    \
		    chipsLock(pScrn);					      \
		}							      \
	    }								      \
	}								      \
    }


/* To aid debugging of 32 bit register access we make the following defines */
/*
#define DEBUG
#define CT_HW_DEBUG 
*/
#if defined(DEBUG) & defined(CT_HW_DEBUG)
#define HW_DEBUG(x) {usleep(500000); ErrorF("Register/Address: 0x%X\n",x);}
#else
#define HW_DEBUG(x) 
#endif
#endif