First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / mach64 / mach64.c
blob3c513ba17f50e1eafa2b709dc9d08adf5e39939e
1 /*
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.
23 #ifdef HAVE_CONFIG_H
24 #include <kdrive-config.h>
25 #endif
26 #include "mach64.h"
27 #include "kaa.h"
29 static Bool
30 mach64CardInit (KdCardInfo *card)
32 Mach64CardInfo *mach64c;
34 mach64c = (Mach64CardInfo *) xalloc (sizeof (Mach64CardInfo));
35 if (!mach64c)
36 return FALSE;
38 (void) mach64MapReg (card, mach64c);
39 mach64c->lcdEnabled = FALSE;
41 if (!vesaInitialize (card, &mach64c->vesa))
43 xfree (mach64c);
44 return FALSE;
47 card->driver = mach64c;
49 return TRUE;
52 static Bool
53 mach64ScreenInit (KdScreenInfo *screen)
55 Mach64CardInfo *mach64c = screen->card->driver;
56 Mach64ScreenInfo *mach64s;
58 mach64s = (Mach64ScreenInfo *) xalloc (sizeof (Mach64ScreenInfo));
59 if (!mach64s)
60 return FALSE;
61 memset (mach64s, '\0', sizeof (Mach64ScreenInfo));
62 if (!vesaScreenInitialize (screen, &mach64s->vesa))
64 xfree (mach64s);
65 return FALSE;
67 if (!mach64c->reg)
68 screen->dumb = TRUE;
69 if (mach64s->vesa.mapping != VESA_LINEAR)
70 screen->dumb = TRUE;
71 switch (screen->fb[0].depth) {
72 case 8:
73 mach64s->colorKey = 0xff;
74 break;
75 case 15:
76 case 16:
77 mach64s->colorKey = 0x001e;
78 break;
79 case 24:
80 mach64s->colorKey = 0x0000fe;
81 break;
82 default:
83 mach64s->colorKey = 1;
84 break;
86 screen->driver = mach64s;
87 return TRUE;
90 static Bool
91 mach64InitScreen (ScreenPtr pScreen)
93 #ifdef XV
94 mach64InitVideo(pScreen);
95 #endif
96 return vesaInitScreen (pScreen);
99 #ifdef RANDR
100 static Bool
101 mach64RandRSetConfig (ScreenPtr pScreen,
102 Rotation rotation,
103 int rate,
104 RRScreenSizePtr pSize)
106 kaaWaitSync (pScreen);
108 if (!vesaRandRSetConfig (pScreen, rotation, rate, pSize))
109 return FALSE;
111 return TRUE;
114 static void
115 mach64RandRInit (ScreenPtr pScreen)
117 rrScrPriv(pScreen);
119 pScrPriv->rrSetConfig = mach64RandRSetConfig;
121 #endif
123 static Bool
124 mach64FinishInitScreen (ScreenPtr pScreen)
126 Bool ret;
127 ret = vesaFinishInitScreen (pScreen);
128 #ifdef RANDR
129 mach64RandRInit (pScreen);
130 #endif
131 return ret;
134 static Bool
135 mach64CreateResources (ScreenPtr pScreen)
137 return vesaCreateResources (pScreen);
140 CARD32
141 mach64ReadLCD (Reg *reg, int id)
143 CARD32 LCD_INDEX;
145 LCD_INDEX = reg->LCD_INDEX & ~(0x3f);
146 reg->LCD_INDEX = (LCD_INDEX | id);
147 return reg->LCD_DATA;
150 void
151 mach64WriteLCD (Reg *reg, int id, CARD32 data)
153 CARD32 LCD_INDEX;
155 LCD_INDEX = reg->LCD_INDEX & ~(0x3f);
156 reg->LCD_INDEX = (LCD_INDEX | id);
157 reg->LCD_DATA = data;
160 void
161 mach64Preserve (KdCardInfo *card)
163 Mach64CardInfo *mach64c = card->driver;
164 Reg *reg = mach64c->reg;
166 vesaPreserve(card);
167 if (reg)
169 mach64c->save.LCD_GEN_CTRL = mach64ReadLCD (reg, 1);
173 Bool
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)
181 mach64c->reg = 0;
182 mach64c->media_reg = 0;
183 return FALSE;
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));
191 return TRUE;
194 void
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;
204 mach64c->reg = 0;
205 mach64c->media_reg = 0;
209 void
210 mach64SetMMIO (KdCardInfo *card, Mach64CardInfo *mach64c)
212 if (!mach64c->reg_base)
213 mach64MapReg (card, mach64c);
214 if (mach64c->reg)
216 if (mach64c->reg->GUI_STAT == 0xffffffff)
217 FatalError ("Mach64 REG not visible\n");
221 void
222 mach64ResetMMIO (KdCardInfo *card, Mach64CardInfo *mach64c)
224 mach64UnmapReg (card, mach64c);
227 Bool
228 mach64Enable (ScreenPtr pScreen)
230 KdScreenPriv(pScreen);
231 Mach64CardInfo *mach64c = pScreenPriv->card->driver;
233 if (!vesaEnable (pScreen))
234 return FALSE;
236 mach64SetMMIO (pScreenPriv->card, mach64c);
237 mach64DPMS (pScreen, KD_DPMS_NORMAL);
238 #ifdef XV
239 KdXVEnable (pScreen);
240 #endif
241 return TRUE;
244 void
245 mach64Disable (ScreenPtr pScreen)
247 KdScreenPriv(pScreen);
248 Mach64CardInfo *mach64c = pScreenPriv->card->driver;
250 #ifdef XV
251 KdXVDisable (pScreen);
252 #endif
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)
296 Bool
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;
303 CARD32 LCD_GEN_CTRL;
304 Reg *reg = mach64c->reg;
306 if (!reg)
307 return FALSE;
309 CRTC_GEN_CNTL = reg->CRTC_GEN_CNTL;
310 LCD_GEN_CTRL = mach64ReadLCD (reg, 1);
312 switch (mode) {
313 case KD_DPMS_NORMAL:
314 hsync_off = 0;
315 vsync_off = 0;
316 blank = 0;
317 break;
318 case KD_DPMS_STANDBY:
319 hsync_off = 1;
320 vsync_off = 0;
321 blank = 1;
322 break;
323 case KD_DPMS_SUSPEND:
324 hsync_off = 0;
325 vsync_off = 1;
326 blank = 1;
327 break;
328 case KD_DPMS_POWERDOWN:
329 hsync_off = 1;
330 vsync_off = 1;
331 blank = 1;
334 if (hsync_off)
335 CRTC_GEN_CNTL |= (1 << 2);
336 else
337 CRTC_GEN_CNTL &= ~(1 << 2);
338 if (vsync_off)
339 CRTC_GEN_CNTL |= (1 << 3);
340 else
341 CRTC_GEN_CNTL &= ~(1 << 3);
342 if (blank)
344 mach64c->lcdEnabled = (LCD_GEN_CTRL & (1 << 1)) != 0;
345 LCD_GEN_CTRL &= ~(1 << 1);
346 CRTC_GEN_CNTL |= (1 << 6);
349 else
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;
361 return TRUE;
364 static void
365 mach64Restore (KdCardInfo *card)
367 Mach64CardInfo *mach64c = card->driver;
368 Reg *reg = mach64c->reg;
370 if (reg)
372 mach64WriteLCD (reg, 1, mach64c->save.LCD_GEN_CTRL);
374 mach64ResetMMIO (card, mach64c);
375 vesaRestore (card);
378 static void
379 mach64ScreenFini (KdScreenInfo *screen)
381 Mach64ScreenInfo *mach64s = (Mach64ScreenInfo *) screen->driver;
382 #ifdef XV
383 mach64FiniVideo(screen->pScreen);
384 #endif
385 vesaScreenFini (screen);
386 xfree (mach64s);
387 screen->driver = 0;
390 static void
391 mach64CardFini (KdCardInfo *card)
393 Mach64CardInfo *mach64c = card->driver;
395 mach64UnmapReg (card, mach64c);
396 vesaCardFini (card);
397 xfree (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 */