2 * Copyright © 2001 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
24 #include <kdrive-config.h>
30 mach64CardInit (KdCardInfo
*card
)
32 Mach64CardInfo
*mach64c
;
34 mach64c
= (Mach64CardInfo
*) xalloc (sizeof (Mach64CardInfo
));
38 (void) mach64MapReg (card
, mach64c
);
39 mach64c
->lcdEnabled
= FALSE
;
41 if (!vesaInitialize (card
, &mach64c
->vesa
))
47 card
->driver
= mach64c
;
53 mach64ScreenInit (KdScreenInfo
*screen
)
55 Mach64CardInfo
*mach64c
= screen
->card
->driver
;
56 Mach64ScreenInfo
*mach64s
;
58 mach64s
= (Mach64ScreenInfo
*) xalloc (sizeof (Mach64ScreenInfo
));
61 memset (mach64s
, '\0', sizeof (Mach64ScreenInfo
));
62 if (!vesaScreenInitialize (screen
, &mach64s
->vesa
))
69 if (mach64s
->vesa
.mapping
!= VESA_LINEAR
)
71 switch (screen
->fb
[0].depth
) {
73 mach64s
->colorKey
= 0xff;
77 mach64s
->colorKey
= 0x001e;
80 mach64s
->colorKey
= 0x0000fe;
83 mach64s
->colorKey
= 1;
86 screen
->driver
= mach64s
;
91 mach64InitScreen (ScreenPtr pScreen
)
94 mach64InitVideo(pScreen
);
96 return vesaInitScreen (pScreen
);
101 mach64RandRSetConfig (ScreenPtr pScreen
,
104 RRScreenSizePtr pSize
)
106 kaaWaitSync (pScreen
);
108 if (!vesaRandRSetConfig (pScreen
, rotation
, rate
, pSize
))
115 mach64RandRInit (ScreenPtr pScreen
)
119 pScrPriv
->rrSetConfig
= mach64RandRSetConfig
;
124 mach64FinishInitScreen (ScreenPtr pScreen
)
127 ret
= vesaFinishInitScreen (pScreen
);
129 mach64RandRInit (pScreen
);
135 mach64CreateResources (ScreenPtr pScreen
)
137 return vesaCreateResources (pScreen
);
141 mach64ReadLCD (Reg
*reg
, int id
)
145 LCD_INDEX
= reg
->LCD_INDEX
& ~(0x3f);
146 reg
->LCD_INDEX
= (LCD_INDEX
| id
);
147 return reg
->LCD_DATA
;
151 mach64WriteLCD (Reg
*reg
, int id
, CARD32 data
)
155 LCD_INDEX
= reg
->LCD_INDEX
& ~(0x3f);
156 reg
->LCD_INDEX
= (LCD_INDEX
| id
);
157 reg
->LCD_DATA
= data
;
161 mach64Preserve (KdCardInfo
*card
)
163 Mach64CardInfo
*mach64c
= card
->driver
;
164 Reg
*reg
= mach64c
->reg
;
169 mach64c
->save
.LCD_GEN_CTRL
= mach64ReadLCD (reg
, 1);
174 mach64MapReg (KdCardInfo
*card
, Mach64CardInfo
*mach64c
)
176 mach64c
->reg_base
= (CARD8
*) KdMapDevice (MACH64_REG_BASE(card
),
177 MACH64_REG_SIZE(card
));
179 if (!mach64c
->reg_base
)
182 mach64c
->media_reg
= 0;
186 KdSetMappedMode (MACH64_REG_BASE(card
),
187 MACH64_REG_SIZE(card
),
188 KD_MAPPED_MODE_REGISTERS
);
189 mach64c
->reg
= (Reg
*) (mach64c
->reg_base
+ MACH64_REG_OFF(card
));
190 mach64c
->media_reg
= (MediaReg
*) (mach64c
->reg_base
+ MACH64_MEDIA_REG_OFF(card
));
195 mach64UnmapReg (KdCardInfo
*card
, Mach64CardInfo
*mach64c
)
197 if (mach64c
->reg_base
)
199 KdResetMappedMode (MACH64_REG_BASE(card
),
200 MACH64_REG_SIZE(card
),
201 KD_MAPPED_MODE_REGISTERS
);
202 KdUnmapDevice ((void *) mach64c
->reg_base
, MACH64_REG_SIZE(card
));
203 mach64c
->reg_base
= 0;
205 mach64c
->media_reg
= 0;
210 mach64SetMMIO (KdCardInfo
*card
, Mach64CardInfo
*mach64c
)
212 if (!mach64c
->reg_base
)
213 mach64MapReg (card
, mach64c
);
216 if (mach64c
->reg
->GUI_STAT
== 0xffffffff)
217 FatalError ("Mach64 REG not visible\n");
222 mach64ResetMMIO (KdCardInfo
*card
, Mach64CardInfo
*mach64c
)
224 mach64UnmapReg (card
, mach64c
);
228 mach64Enable (ScreenPtr pScreen
)
230 KdScreenPriv(pScreen
);
231 Mach64CardInfo
*mach64c
= pScreenPriv
->card
->driver
;
233 if (!vesaEnable (pScreen
))
236 mach64SetMMIO (pScreenPriv
->card
, mach64c
);
237 mach64DPMS (pScreen
, KD_DPMS_NORMAL
);
239 KdXVEnable (pScreen
);
245 mach64Disable (ScreenPtr pScreen
)
247 KdScreenPriv(pScreen
);
248 Mach64CardInfo
*mach64c
= pScreenPriv
->card
->driver
;
251 KdXVDisable (pScreen
);
253 mach64ResetMMIO (pScreenPriv
->card
, mach64c
);
254 vesaDisable (pScreen
);
257 const CARD8 mach64DPMSModes
[4] = {
258 0x80, /* KD_DPMS_NORMAL */
259 0x8c, /* KD_DPMS_STANDBY */
260 0x8c, /* KD_DPMS_STANDBY */
261 0x8c, /* KD_DPMS_STANDBY */
262 /* 0xb0, KD_DPMS_SUSPEND */
263 /* 0xbc, KD_DPMS_POWERDOWN */
266 #define PWR_MGT_ON (1 << 0)
267 #define PWR_MGT_MODE (3 << 1)
268 #define PWR_MGT_MODE_PIN (0 << 1)
269 #define PWR_MGT_MODE_REG (1 << 1)
270 #define PWR_MGT_MODE_TIMER (2 << 1)
271 #define PWR_MGR_MODE_PCI (3 << 1)
272 #define AUTO_PWRUP_EN (1 << 3)
273 #define ACTIVITY_PIN_ON (1 << 4)
274 #define STANDBY_POL (1 << 5)
275 #define SUSPEND_POL (1 << 6)
276 #define SELF_REFRESH (1 << 7)
277 #define ACTIVITY_PIN_EN (1 << 8)
278 #define KEYBD_SNOOP (1 << 9)
279 #define DONT_USE_F32KHZ (1 << 10)
280 #define TRISTATE_MEM_EN (1 << 11)
281 #define LCDENG_TEST_MODE (0xf << 12)
282 #define STANDBY_COUNT (0xf << 16)
283 #define SUSPEND_COUNT (0xf << 20)
284 #define BIASON (1 << 24)
285 #define BLON (1 << 25)
286 #define DIGON (1 << 26)
287 #define PM_D3_RST_ENB (1 << 27)
288 #define STANDBY_NOW (1 << 28)
289 #define SUSPEND_NOW (1 << 29)
290 #define PWR_MGT_STATUS (3 << 30)
291 #define PWR_MGT_STATUS_ON (0 << 30)
292 #define PWR_MGT_STATUS_STANDBY (1 << 30)
293 #define PWR_MGT_STATUS_SUSPEND (2 << 30)
294 #define PWR_MGT_STATUS_TRANSITION (3 << 30)
297 mach64DPMS (ScreenPtr pScreen
, int mode
)
299 KdScreenPriv(pScreen
);
300 Mach64CardInfo
*mach64c
= pScreenPriv
->card
->driver
;
301 int hsync_off
= 0, vsync_off
= 0, blank
= 0;
302 CARD32 CRTC_GEN_CNTL
;
304 Reg
*reg
= mach64c
->reg
;
309 CRTC_GEN_CNTL
= reg
->CRTC_GEN_CNTL
;
310 LCD_GEN_CTRL
= mach64ReadLCD (reg
, 1);
318 case KD_DPMS_STANDBY
:
323 case KD_DPMS_SUSPEND
:
328 case KD_DPMS_POWERDOWN
:
335 CRTC_GEN_CNTL
|= (1 << 2);
337 CRTC_GEN_CNTL
&= ~(1 << 2);
339 CRTC_GEN_CNTL
|= (1 << 3);
341 CRTC_GEN_CNTL
&= ~(1 << 3);
344 mach64c
->lcdEnabled
= (LCD_GEN_CTRL
& (1 << 1)) != 0;
345 LCD_GEN_CTRL
&= ~(1 << 1);
346 CRTC_GEN_CNTL
|= (1 << 6);
351 if (!(LCD_GEN_CTRL
& 3) || mach64c
->lcdEnabled
)
352 LCD_GEN_CTRL
|= (1 << 1);
353 CRTC_GEN_CNTL
&= ~(1 << 6);
356 kaaWaitSync (pScreen
);
358 mach64WriteLCD (reg
, 1, LCD_GEN_CTRL
);
360 reg
->CRTC_GEN_CNTL
= CRTC_GEN_CNTL
;
365 mach64Restore (KdCardInfo
*card
)
367 Mach64CardInfo
*mach64c
= card
->driver
;
368 Reg
*reg
= mach64c
->reg
;
372 mach64WriteLCD (reg
, 1, mach64c
->save
.LCD_GEN_CTRL
);
374 mach64ResetMMIO (card
, mach64c
);
379 mach64ScreenFini (KdScreenInfo
*screen
)
381 Mach64ScreenInfo
*mach64s
= (Mach64ScreenInfo
*) screen
->driver
;
383 mach64FiniVideo(screen
->pScreen
);
385 vesaScreenFini (screen
);
391 mach64CardFini (KdCardInfo
*card
)
393 Mach64CardInfo
*mach64c
= card
->driver
;
395 mach64UnmapReg (card
, mach64c
);
400 #define mach64CursorInit 0 /* initCursor */
401 #define mach64CursorEnable 0 /* enableCursor */
402 #define mach64CursorDisable 0 /* disableCursor */
403 #define mach64CursorFini 0 /* finiCursor */
404 #define mach64RecolorCursor 0 /* recolorCursor */
406 KdCardFuncs mach64Funcs
= {
407 mach64CardInit
, /* cardinit */
408 mach64ScreenInit
, /* scrinit */
409 mach64InitScreen
, /* initScreen */
410 mach64FinishInitScreen
, /* finishInitScreen */
411 mach64CreateResources
, /* createRes */
412 mach64Preserve
, /* preserve */
413 mach64Enable
, /* enable */
414 mach64DPMS
, /* dpms */
415 mach64Disable
, /* disable */
416 mach64Restore
, /* restore */
417 mach64ScreenFini
, /* scrfini */
418 mach64CardFini
, /* cardfini */
420 mach64CursorInit
, /* initCursor */
421 mach64CursorEnable
, /* enableCursor */
422 mach64CursorDisable
, /* disableCursor */
423 mach64CursorFini
, /* finiCursor */
424 mach64RecolorCursor
, /* recolorCursor */
426 mach64DrawInit
, /* initAccel */
427 mach64DrawEnable
, /* enableAccel */
428 mach64DrawDisable
, /* disableAccel */
429 mach64DrawFini
, /* finiAccel */
431 vesaGetColors
, /* getColors */
432 vesaPutColors
, /* putColors */