2 * Copyright 2006 Dave Airlie
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECT
23 * this code uses ideas taken from the NVIDIA nv driver - the nvidia license
24 * decleration is at the bottom of this file as it is rather ugly
42 #include "mipointer.h"
43 #include "windowstr.h"
45 #include <X11/extensions/render.h>
48 #include "nv_include.h"
52 #define CRTC_INDEX 0x3d4
53 #define CRTC_DATA 0x3d5
54 #define CRTC_IN_STAT_1 0x3da
56 #define WHITE_VALUE 0x3F
57 #define BLACK_VALUE 0x00
58 #define OVERSCAN_VALUE 0x01
60 static void nv_crtc_load_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
61 static void nv_crtc_load_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
62 static void nv_crtc_save_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
63 static void nv_crtc_save_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state);
65 static void NVWriteMiscOut(xf86CrtcPtr crtc, CARD8 value)
67 ScrnInfoPtr pScrn = crtc->scrn;
68 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
69 NVPtr pNv = NVPTR(pScrn);
71 NV_WR08(pNv->PVIO, VGA_MISC_OUT_W, value);
74 static CARD8 NVReadMiscOut(xf86CrtcPtr crtc)
76 ScrnInfoPtr pScrn = crtc->scrn;
77 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
78 NVPtr pNv = NVPTR(pScrn);
80 return NV_RD08(pNv->PVIO, VGA_MISC_OUT_R);
84 void NVWriteVgaCrtc(xf86CrtcPtr crtc, CARD8 index, CARD8 value)
86 ScrnInfoPtr pScrn = crtc->scrn;
87 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
88 NVPtr pNv = NVPTR(pScrn);
89 volatile CARD8 *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
91 NV_WR08(pCRTCReg, CRTC_INDEX, index);
92 NV_WR08(pCRTCReg, CRTC_DATA, value);
95 CARD8 NVReadVgaCrtc(xf86CrtcPtr crtc, CARD8 index)
97 ScrnInfoPtr pScrn = crtc->scrn;
98 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
99 NVPtr pNv = NVPTR(pScrn);
100 volatile CARD8 *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
102 NV_WR08(pCRTCReg, CRTC_INDEX, index);
103 return NV_RD08(pCRTCReg, CRTC_DATA);
106 static void NVWriteVgaSeq(xf86CrtcPtr crtc, CARD8 index, CARD8 value)
108 ScrnInfoPtr pScrn = crtc->scrn;
109 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
110 NVPtr pNv = NVPTR(pScrn);
112 NV_WR08(pNv->PVIO, VGA_SEQ_INDEX, index);
113 NV_WR08(pNv->PVIO, VGA_SEQ_DATA, value);
116 static CARD8 NVReadVgaSeq(xf86CrtcPtr crtc, CARD8 index)
118 ScrnInfoPtr pScrn = crtc->scrn;
119 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
120 NVPtr pNv = NVPTR(pScrn);
121 volatile CARD8 *pVGAReg = pNv->PVIO;
123 NV_WR08(pNv->PVIO, VGA_SEQ_INDEX, index);
124 return NV_RD08(pNv->PVIO, VGA_SEQ_DATA);
127 static void NVWriteVgaGr(xf86CrtcPtr crtc, CARD8 index, CARD8 value)
129 ScrnInfoPtr pScrn = crtc->scrn;
130 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
131 NVPtr pNv = NVPTR(pScrn);
133 NV_WR08(pNv->PVIO, VGA_GRAPH_INDEX, index);
134 NV_WR08(pNv->PVIO, VGA_GRAPH_DATA, value);
137 static CARD8 NVReadVgaGr(xf86CrtcPtr crtc, CARD8 index)
139 ScrnInfoPtr pScrn = crtc->scrn;
140 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
141 NVPtr pNv = NVPTR(pScrn);
142 volatile CARD8 *pVGAReg = pNv->PVIO;
144 NV_WR08(pVGAReg, VGA_GRAPH_INDEX, index);
145 return NV_RD08(pVGAReg, VGA_GRAPH_DATA);
149 static void NVWriteVgaAttr(xf86CrtcPtr crtc, CARD8 index, CARD8 value)
151 ScrnInfoPtr pScrn = crtc->scrn;
152 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
153 NVPtr pNv = NVPTR(pScrn);
154 volatile CARD8 *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
156 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
157 if (nv_crtc->paletteEnabled)
161 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, index);
162 NV_WR08(pCRTCReg, VGA_ATTR_DATA_W, value);
165 static CARD8 NVReadVgaAttr(xf86CrtcPtr crtc, CARD8 index)
167 ScrnInfoPtr pScrn = crtc->scrn;
168 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
169 NVPtr pNv = NVPTR(pScrn);
170 volatile CARD8 *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
172 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
173 if (nv_crtc->paletteEnabled)
177 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, index);
178 return NV_RD08(pCRTCReg, VGA_ATTR_DATA_R);
181 void NVCrtcSetOwner(xf86CrtcPtr crtc)
183 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
184 ScrnInfoPtr pScrn = crtc->scrn;
185 NVPtr pNv = NVPTR(pScrn);
186 /* Non standard beheaviour required by NV11 */
188 uint8_t owner = NVReadVGA0(pNv, NV_VGA_CRTCX_OWNER);
189 ErrorF("pre-Owner: 0x%X\n", owner);
191 uint32_t pbus84 = nvReadMC(pNv, 0x1084);
192 ErrorF("pbus84: 0x%X\n", pbus84);
194 ErrorF("pbus84: 0x%X\n", pbus84);
195 nvWriteMC(pNv, 0x1084, pbus84);
197 /* The blob never writes owner to pcio1, so should we */
198 if (pNv->NVArch == 0x11) {
199 NVWriteVGA0(pNv, NV_VGA_CRTCX_OWNER, 0xff);
201 NVWriteVGA0(pNv, NV_VGA_CRTCX_OWNER, nv_crtc->crtc * 0x3);
202 owner = NVReadVGA0(pNv, NV_VGA_CRTCX_OWNER);
203 ErrorF("post-Owner: 0x%X\n", owner);
205 ErrorF("pNv pointer is NULL\n");
210 NVEnablePalette(xf86CrtcPtr crtc)
212 ScrnInfoPtr pScrn = crtc->scrn;
213 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
214 NVPtr pNv = NVPTR(pScrn);
215 volatile CARD8 *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
217 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
218 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, 0);
219 nv_crtc->paletteEnabled = TRUE;
223 NVDisablePalette(xf86CrtcPtr crtc)
225 ScrnInfoPtr pScrn = crtc->scrn;
226 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
227 NVPtr pNv = NVPTR(pScrn);
228 volatile CARD8 *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
230 NV_RD08(pCRTCReg, CRTC_IN_STAT_1);
231 NV_WR08(pCRTCReg, VGA_ATTR_INDEX, 0x20);
232 nv_crtc->paletteEnabled = FALSE;
235 static void NVWriteVgaReg(xf86CrtcPtr crtc, CARD32 reg, CARD8 value)
237 ScrnInfoPtr pScrn = crtc->scrn;
238 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
239 NVPtr pNv = NVPTR(pScrn);
240 volatile CARD8 *pCRTCReg = nv_crtc->head ? pNv->PCIO1 : pNv->PCIO0;
242 NV_WR08(pCRTCReg, reg, value);
245 /* perform a sequencer reset */
246 static void NVVgaSeqReset(xf86CrtcPtr crtc, Bool start)
249 NVWriteVgaSeq(crtc, 0x00, 0x1);
251 NVWriteVgaSeq(crtc, 0x00, 0x3);
254 static void NVVgaProtect(xf86CrtcPtr crtc, Bool on)
259 tmp = NVReadVgaSeq(crtc, 0x1);
260 NVVgaSeqReset(crtc, TRUE);
261 NVWriteVgaSeq(crtc, 0x01, tmp | 0x20);
263 NVEnablePalette(crtc);
266 * Reenable sequencer, then turn on screen.
268 tmp = NVReadVgaSeq(crtc, 0x1);
269 NVWriteVgaSeq(crtc, 0x01, tmp & ~0x20); /* reenable display */
270 NVVgaSeqReset(crtc, FALSE);
272 NVDisablePalette(crtc);
276 void NVCrtcLockUnlock(xf86CrtcPtr crtc, Bool Lock)
280 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LOCK, Lock ? 0x99 : 0x57);
281 cr11 = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_VSYNCE);
282 if (Lock) cr11 |= 0x80;
284 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_VSYNCE, cr11);
287 * Calculate the Video Clock parameters for the PLL.
289 static void CalcVClock (
296 unsigned lowM, highM, highP;
297 unsigned DeltaNew, DeltaOld;
301 /* M: PLL reference frequency postscaler divider */
302 /* P: PLL VCO output postscaler divider */
303 /* N: PLL VCO postscaler setting */
305 DeltaOld = 0xFFFFFFFF;
307 VClk = (unsigned)clockIn;
309 /* Taken from Haiku, after someone with an NV28 had an issue */
310 switch(pNv->NVArch) {
316 } else if (VClk > 200000) {
318 } else if (VClk > 150000) {
329 } else if (VClk > 250000) {
337 for (P = 0; P <= highP; P++) {
339 if ((Freq >= 128000) && (Freq <= 350000)) {
340 for (M = lowM; M <= highM; M++) {
341 N = ((VClk << P) * M) / pNv->CrystalFreqKHz;
343 Freq = ((pNv->CrystalFreqKHz * N) / M) >> P;
345 DeltaNew = Freq - VClk;
347 DeltaNew = VClk - Freq;
349 if (DeltaNew < DeltaOld) {
350 *pllOut = (P << 16) | (N << 8) | M;
360 static void CalcVClock2Stage (
368 unsigned DeltaNew, DeltaOld;
371 unsigned lowM, highM, highP;
373 DeltaOld = 0xFFFFFFFF;
375 *pllBOut = 0x80000401; /* fixed at x4 for now */
377 VClk = (unsigned)clockIn;
379 /* Taken from Haiku, after someone with an NV28 had an issue */
380 switch(pNv->NVArch) {
386 } else if (VClk > 200000) {
388 } else if (VClk > 150000) {
399 } else if (VClk > 250000) {
407 for (P = 0; P <= highP; P++) {
409 if ((Freq >= 400000) && (Freq <= 1000000)) {
410 for (M = lowM; M <= highM; M++) {
411 N = ((VClk << P) * M) / (pNv->CrystalFreqKHz << 2);
412 if ((N >= 5) && (N <= 255)) {
413 Freq = (((pNv->CrystalFreqKHz << 2) * N) / M) >> P;
415 DeltaNew = Freq - VClk;
417 DeltaNew = VClk - Freq;
419 if (DeltaNew < DeltaOld) {
420 *pllOut = (P << 16) | (N << 8) | M;
430 static void nv_crtc_save_state_pll(NVPtr pNv, RIVA_HW_STATE *state)
432 state->vpll = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL);
434 state->vpll2 = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL2);
436 if(pNv->twoStagePLL) {
437 state->vpllB = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL_B);
438 state->vpll2B = nvReadRAMDAC0(pNv, NV_RAMDAC_VPLL2_B);
440 state->pllsel = nvReadRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT);
444 static void nv_crtc_load_state_pll(NVPtr pNv, RIVA_HW_STATE *state)
446 nvWriteRAMDAC0(pNv, NV_RAMDAC_PLL_SELECT, state->pllsel);
448 ErrorF("writting vpll %08X\n", state->vpll);
449 ErrorF("writting vpll2 %08X\n", state->vpll2);
450 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL, state->vpll);
452 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL2, state->vpll2);
454 if(pNv->twoStagePLL) {
455 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL_B, state->vpllB);
456 nvWriteRAMDAC0(pNv, NV_RAMDAC_VPLL2_B, state->vpll2B);
461 * Calculate extended mode parameters (SVGA) and save in a
462 * mode state structure.
464 void nv_crtc_calc_state_ext(
467 int DisplayWidth, /* Does this change after setting the mode? */
474 ScrnInfoPtr pScrn = crtc->scrn;
475 int pixelDepth, VClk;
477 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
478 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
480 NVPtr pNv = NVPTR(pScrn);
481 RIVA_HW_STATE *state;
482 int num_crtc_enabled, i;
484 state = &pNv->ModeReg;
486 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
489 * Extended RIVA registers.
491 pixelDepth = (bpp + 1)/8;
493 CalcVClock2Stage(dotClock, &VClk, &state->pll, &state->pllB, pNv);
495 CalcVClock(dotClock, &VClk, &state->pll, pNv);
497 switch (pNv->Architecture) {
499 nv4UpdateArbitrationSettings(VClk,
501 &(state->arbitration0),
502 &(state->arbitration1),
504 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = 0x00;
505 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = 0xbC;
506 if (flags & V_DBLSCAN)
507 regp->CRTC[NV_VGA_CRTCX_CURCTL1] |= 2;
508 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = 0x00000000;
509 state->pllsel |= NV_RAMDAC_PLL_SELECT_VCLK_RATIO_DB2 | NV_RAMDAC_PLL_SELECT_PLL_SOURCE_ALL;
510 state->config = 0x00001114;
511 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = CrtcHDisplay < 1280 ? 0x04 : 0x00;
517 if (((pNv->Chipset & 0xfff0) == CHIPSET_C51) ||
518 ((pNv->Chipset & 0xfff0) == CHIPSET_C512)) {
519 state->arbitration0 = 128;
520 state->arbitration1 = 0x0480;
521 } else if (((pNv->Chipset & 0xffff) == CHIPSET_NFORCE) ||
522 ((pNv->Chipset & 0xffff) == CHIPSET_NFORCE2)) {
523 nForceUpdateArbitrationSettings(VClk,
525 &(state->arbitration0),
526 &(state->arbitration1),
528 } else if (pNv->Architecture < NV_ARCH_30) {
529 nv10UpdateArbitrationSettings(VClk,
531 &(state->arbitration0),
532 &(state->arbitration1),
535 nv30UpdateArbitrationSettings(pNv,
536 &(state->arbitration0),
537 &(state->arbitration1));
540 CursorStart = pNv->Cursor->offset;
542 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = 0x80 | (CursorStart >> 17);
543 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = (CursorStart >> 11) << 2;
544 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = CursorStart >> 24;
546 if (flags & V_DBLSCAN)
547 regp->CRTC[NV_VGA_CRTCX_CURCTL1] |= 2;
549 state->config = nvReadFB(pNv, NV_PFB_CFG0);
550 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = CrtcHDisplay < 1280 ? 0x04 : 0x00;
554 /* okay do we have 2 CRTCs running ? */
555 num_crtc_enabled = 0;
556 for (i = 0; i < xf86_config->num_crtc; i++) {
557 if (xf86_config->crtc[i]->enabled) {
562 ErrorF("There are %d CRTC's enabled\n", num_crtc_enabled);
564 if (nv_crtc->crtc == 1) {
565 state->vpll2 = state->pll;
566 state->vpll2B = state->pllB;
567 state->pllsel |= NV_RAMDAC_PLL_SELECT_VCLK2_RATIO_DB2;
568 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_CRTC1;
570 state->vpll = state->pll;
571 state->vpllB = state->pllB;
572 state->pllsel |= NV_RAMDAC_PLL_SELECT_PLL_SOURCE_ALL;
573 state->pllsel &= ~NV_RAMDAC_PLL_SELECT_VCLK_RATIO_DB2;
576 regp->CRTC[NV_VGA_CRTCX_FIFO0] = state->arbitration0;
577 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM] = state->arbitration1 & 0xff;
578 if (pNv->Architecture >= NV_ARCH_30) {
579 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30] = state->arbitration1 >> 8;
582 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = (((DisplayWidth/8) * pixelDepth) & 0x700) >> 3;
583 regp->CRTC[NV_VGA_CRTCX_PIXEL] = (pixelDepth > 2) ? 3 : pixelDepth;
588 nv_crtc_dpms(xf86CrtcPtr crtc, int mode)
590 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
591 ScrnInfoPtr pScrn = crtc->scrn;
592 NVPtr pNv = NVPTR(pScrn);
593 unsigned char seq1 = 0, crtc17 = 0;
594 unsigned char crtc1A;
597 ErrorF("nv_crtc_dpms is called for CRTC %d with mode %d\n", nv_crtc->crtc, mode);
599 NVCrtcSetOwner(crtc);
601 crtc1A = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1) & ~0xC0;
603 case DPMSModeStandby:
604 /* Screen: Off; HSync: Off, VSync: On -- Not Supported */
609 case DPMSModeSuspend:
610 /* Screen: Off; HSync: On, VSync: Off -- Not Supported */
616 /* Screen: Off; HSync: Off, VSync: Off */
623 /* Screen: On; HSync: On, VSync: On */
629 if (mode == DPMSModeOn) {
630 pNv->crtc_active[nv_crtc->head] = TRUE;
632 pNv->crtc_active[nv_crtc->head] = FALSE;
635 NVWriteVgaSeq(crtc, 0x00, 0x1);
636 seq1 = NVReadVgaSeq(crtc, 0x01) & ~0x20;
637 NVWriteVgaSeq(crtc, 0x1, seq1);
638 crtc17 |= NVReadVgaCrtc(crtc, NV_VGA_CRTCX_MODECTL) & ~0x80;
640 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_MODECTL, crtc17);
641 NVWriteVgaSeq(crtc, 0x0, 0x3);
643 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1, crtc1A);
647 nv_crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
648 DisplayModePtr adjusted_mode)
650 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
651 ErrorF("nv_crtc_mode_fixup is called for CRTC %d\n", nv_crtc->crtc);
656 nv_crtc_mode_set_vga(xf86CrtcPtr crtc, DisplayModePtr mode)
658 ScrnInfoPtr pScrn = crtc->scrn;
659 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
661 NVPtr pNv = NVPTR(pScrn);
662 int depth = pScrn->depth;
665 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
668 * compute correct Hsync & Vsync polarity
670 if ((mode->Flags & (V_PHSYNC | V_NHSYNC))
671 && (mode->Flags & (V_PVSYNC | V_NVSYNC))) {
673 regp->MiscOutReg = 0x23;
674 if (mode->Flags & V_NHSYNC) regp->MiscOutReg |= 0x40;
675 if (mode->Flags & V_NVSYNC) regp->MiscOutReg |= 0x80;
677 int VDisplay = mode->VDisplay;
678 if (mode->Flags & V_DBLSCAN)
681 VDisplay *= mode->VScan;
682 if (VDisplay < 400) {
683 regp->MiscOutReg = 0xA3; /* +hsync -vsync */
684 } else if (VDisplay < 480) {
685 regp->MiscOutReg = 0x63; /* -hsync +vsync */
686 } else if (VDisplay < 768) {
687 regp->MiscOutReg = 0xE3; /* -hsync -vsync */
689 regp->MiscOutReg = 0x23; /* +hsync +vsync */
693 regp->MiscOutReg |= (mode->ClockIndex & 0x03) << 2;
699 regp->Sequencer[0] = 0x02;
701 regp->Sequencer[0] = 0x00;
703 if (mode->Flags & V_CLKDIV2) {
704 regp->Sequencer[1] = 0x09;
706 regp->Sequencer[1] = 0x01;
709 regp->Sequencer[2] = 1 << BIT_PLANE;
711 regp->Sequencer[2] = 0x0F;
712 regp->Sequencer[3] = 0x00; /* Font select */
715 regp->Sequencer[4] = 0x06; /* Misc */
717 regp->Sequencer[4] = 0x0E; /* Misc */
723 regp->CRTC[0] = (mode->CrtcHTotal >> 3) - 5;
724 regp->CRTC[1] = (mode->CrtcHDisplay >> 3) - 1;
725 regp->CRTC[2] = (mode->CrtcHBlankStart >> 3) - 1;
726 regp->CRTC[3] = (((mode->CrtcHBlankEnd >> 3) - 1) & 0x1F) | 0x80;
727 i = (((mode->CrtcHSkew << 2) + 0x10) & ~0x1F);
731 regp->CRTC[4] = (mode->CrtcHSyncStart >> 3);
732 regp->CRTC[5] = ((((mode->CrtcHBlankEnd >> 3) - 1) & 0x20) << 2)
733 | (((mode->CrtcHSyncEnd >> 3)) & 0x1F);
734 regp->CRTC[6] = (mode->CrtcVTotal - 2) & 0xFF;
735 regp->CRTC[7] = (((mode->CrtcVTotal - 2) & 0x100) >> 8)
736 | (((mode->CrtcVDisplay - 1) & 0x100) >> 7)
737 | ((mode->CrtcVSyncStart & 0x100) >> 6)
738 | (((mode->CrtcVBlankStart - 1) & 0x100) >> 5)
740 | (((mode->CrtcVTotal - 2) & 0x200) >> 4)
741 | (((mode->CrtcVDisplay - 1) & 0x200) >> 3)
742 | ((mode->CrtcVSyncStart & 0x200) >> 2);
743 regp->CRTC[8] = 0x00;
744 regp->CRTC[9] = (((mode->CrtcVBlankStart - 1) & 0x200) >> 4) | 0x40;
745 if (mode->Flags & V_DBLSCAN) {
746 regp->CRTC[9] |= 0x80;
748 if (mode->VScan >= 32) {
749 regp->CRTC[9] |= 0x1F;
750 } else if (mode->VScan > 1) {
751 regp->CRTC[9] |= mode->VScan - 1;
753 regp->CRTC[10] = 0x00;
754 regp->CRTC[11] = 0x00;
755 regp->CRTC[12] = 0x00;
756 regp->CRTC[13] = 0x00;
757 regp->CRTC[14] = 0x00;
758 regp->CRTC[15] = 0x00;
759 regp->CRTC[16] = mode->CrtcVSyncStart & 0xFF;
760 regp->CRTC[17] = (mode->CrtcVSyncEnd & 0x0F) | 0x20;
761 regp->CRTC[18] = (mode->CrtcVDisplay - 1) & 0xFF;
762 regp->CRTC[19] = mode->CrtcHDisplay >> 4; /* just a guess */
763 regp->CRTC[20] = 0x00;
764 regp->CRTC[21] = (mode->CrtcVBlankStart - 1) & 0xFF;
765 regp->CRTC[22] = (mode->CrtcVBlankEnd - 1) & 0xFF;
767 regp->CRTC[23] = 0xE3;
769 regp->CRTC[23] = 0xC3;
771 regp->CRTC[24] = 0xFF;
774 * Theory resumes here....
778 * Graphics Display Controller
780 regp->Graphics[0] = 0x00;
781 regp->Graphics[1] = 0x00;
782 regp->Graphics[2] = 0x00;
783 regp->Graphics[3] = 0x00;
785 regp->Graphics[4] = BIT_PLANE;
786 regp->Graphics[5] = 0x00;
788 regp->Graphics[4] = 0x00;
790 regp->Graphics[5] = 0x02;
792 regp->Graphics[5] = 0x40;
795 regp->Graphics[6] = 0x05; /* only map 64k VGA memory !!!! */
796 regp->Graphics[7] = 0x0F;
797 regp->Graphics[8] = 0xFF;
800 /* Initialise the Mono map according to which bit-plane gets used */
802 Bool flipPixels = xf86GetFlipPixels();
804 for (i=0; i<16; i++) {
805 if (((i & (1 << BIT_PLANE)) != 0) != flipPixels) {
806 regp->Attribute[i] = WHITE_VALUE;
808 regp->Attribute[i] = BLACK_VALUE;
813 regp->Attribute[0] = 0x00; /* standard colormap translation */
814 regp->Attribute[1] = 0x01;
815 regp->Attribute[2] = 0x02;
816 regp->Attribute[3] = 0x03;
817 regp->Attribute[4] = 0x04;
818 regp->Attribute[5] = 0x05;
819 regp->Attribute[6] = 0x06;
820 regp->Attribute[7] = 0x07;
821 regp->Attribute[8] = 0x08;
822 regp->Attribute[9] = 0x09;
823 regp->Attribute[10] = 0x0A;
824 regp->Attribute[11] = 0x0B;
825 regp->Attribute[12] = 0x0C;
826 regp->Attribute[13] = 0x0D;
827 regp->Attribute[14] = 0x0E;
828 regp->Attribute[15] = 0x0F;
830 regp->Attribute[16] = 0x81; /* wrong for the ET4000 */
832 regp->Attribute[16] = 0x41; /* wrong for the ET4000 */
835 regp->Attribute[17] = 0xff;
837 /* Attribute[17] (overscan) initialised in vgaHWGetHWRec() */
839 regp->Attribute[18] = 0x0F;
840 regp->Attribute[19] = 0x00;
841 regp->Attribute[20] = 0x00;
845 * Sets up registers for the given mode/adjusted_mode pair.
847 * The clocks, CRTCs and outputs attached to this CRTC must be off.
849 * This shouldn't enable any clocks, CRTCs, or outputs, but they should
850 * be easily turned on/off after this.
853 nv_crtc_mode_set_regs(xf86CrtcPtr crtc, DisplayModePtr mode)
855 ScrnInfoPtr pScrn = crtc->scrn;
856 NVPtr pNv = NVPTR(pScrn);
857 NVRegPtr state = &pNv->ModeReg;
858 xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
859 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
860 NVFBLayout *pLayout = &pNv->CurrentLayout;
861 NVCrtcRegPtr regp, savep;
863 int horizDisplay = (mode->CrtcHDisplay/8);
864 int horizStart = (mode->CrtcHSyncStart/8);
865 int horizEnd = (mode->CrtcHSyncEnd/8);
866 int horizTotal = (mode->CrtcHTotal/8) ;
867 int horizBlankStart = (mode->CrtcHDisplay/8);
868 int horizBlankEnd = (mode->CrtcHTotal/8);
869 int vertDisplay = mode->CrtcVDisplay;
870 int vertStart = mode->CrtcVSyncStart;
871 int vertEnd = mode->CrtcVSyncEnd;
872 int vertTotal = mode->CrtcVTotal;
873 int vertBlankStart = mode->CrtcVDisplay;
874 int vertBlankEnd = mode->CrtcVTotal;
875 int linecomp = mode->CrtcVDisplay;
876 /* What about vsync and hsync? */
880 xf86OutputPtr output;
881 NVOutputPrivatePtr nv_output;
882 for (i = 0; i < xf86_config->num_output; i++) {
883 output = xf86_config->output[i];
884 nv_output = output->driver_private;
886 if (output->crtc == crtc) {
887 if ((nv_output->type == OUTPUT_PANEL) ||
888 (nv_output->type == OUTPUT_DIGITAL)) {
896 ErrorF("crtc: Pre-sync workaround\n");
897 /* Flatpanel stuff from haiku */
899 if (nv_output->fpWidth == mode->CrtcHDisplay) {
900 /* This is to keep the panel synced at native resolution */
901 if (pNv->NVArch == 0x11) {
911 if (horizStart == horizDisplay)
913 if (horizEnd == horizTotal)
915 if (vertStart == vertDisplay)
917 if (vertEnd == vertTotal)
921 /* Stuff from haiku, put here so it doesn't mess up the comparisons above */
929 ErrorF("horizDisplay: 0x%X \n", horizDisplay);
930 ErrorF("horizStart: 0x%X \n", horizStart);
931 ErrorF("horizEnd: 0x%X \n", horizEnd);
932 ErrorF("horizTotal: 0x%X \n", horizTotal);
933 ErrorF("horizBlankStart: 0x%X \n", horizBlankStart);
934 ErrorF("horizBlankEnd: 0x%X \n", horizBlankEnd);
935 ErrorF("vertDisplay: 0x%X \n", vertDisplay);
936 ErrorF("vertStart: 0x%X \n", vertStart);
937 ErrorF("vertEnd: 0x%X \n", vertEnd);
938 ErrorF("vertTotal: 0x%X \n", vertTotal);
939 ErrorF("vertBlankStart: 0x%X \n", vertBlankStart);
940 ErrorF("vertBlankEnd: 0x%X \n", vertBlankEnd);
942 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
943 savep = &pNv->SavedReg.crtc_reg[nv_crtc->head];
945 ErrorF("crtc: Post-sync workaround\n");
947 if(mode->Flags & V_INTERLACE)
950 regp->CRTC[NV_VGA_CRTCX_HTOTAL] = Set8Bits(horizTotal);
951 regp->CRTC[NV_VGA_CRTCX_HDISPE] = Set8Bits(horizDisplay);
952 regp->CRTC[NV_VGA_CRTCX_HBLANKS] = Set8Bits(horizBlankStart);
953 regp->CRTC[NV_VGA_CRTCX_HBLANKE] = SetBitField(horizBlankEnd,4:0,4:0)
955 regp->CRTC[NV_VGA_CRTCX_HSYNCS] = Set8Bits(horizStart);
956 regp->CRTC[NV_VGA_CRTCX_HSYNCE] = SetBitField(horizBlankEnd,5:5,7:7)
957 | SetBitField(horizEnd,4:0,4:0);
958 regp->CRTC[NV_VGA_CRTCX_VTOTAL] = SetBitField(vertTotal,7:0,7:0);
959 regp->CRTC[NV_VGA_CRTCX_OVERFLOW] = SetBitField(vertTotal,8:8,0:0)
960 | SetBitField(vertDisplay,8:8,1:1)
961 | SetBitField(vertStart,8:8,2:2)
962 | SetBitField(vertBlankStart,8:8,3:3)
963 | SetBitField(linecomp,8:8,4:4)
964 | SetBitField(vertTotal,9:9,5:5)
965 | SetBitField(vertDisplay,9:9,6:6)
966 | SetBitField(vertStart,9:9,7:7);
967 regp->CRTC[NV_VGA_CRTCX_MAXSCLIN] = SetBitField(vertBlankStart,9:9,5:5)
969 | ((mode->Flags & V_DBLSCAN) ? 0x80 : 0x00);
970 regp->CRTC[NV_VGA_CRTCX_VSYNCS] = Set8Bits(vertStart);
971 regp->CRTC[NV_VGA_CRTCX_VSYNCE] = SetBitField(vertEnd,3:0,3:0) | SetBit(5);
972 regp->CRTC[NV_VGA_CRTCX_VDISPE] = Set8Bits(vertDisplay);
973 regp->CRTC[NV_VGA_CRTCX_PITCHL] = ((pScrn->displayWidth/8)*(pLayout->bitsPerPixel/8));
974 regp->CRTC[NV_VGA_CRTCX_VBLANKS] = Set8Bits(vertBlankStart);
975 regp->CRTC[NV_VGA_CRTCX_VBLANKE] = Set8Bits(vertBlankEnd);
976 /* Not an extended register */
977 regp->CRTC[NV_VGA_CRTCX_LINECOMP] = Set8Bits(linecomp);
979 regp->Attribute[0x10] = 0x01;
982 regp->Attribute[0x11] = 0x00;
984 regp->CRTC[NV_VGA_CRTCX_LSR] = SetBitField(horizBlankEnd,6:6,4:4)
985 | SetBitField(vertBlankStart,10:10,3:3)
986 | SetBitField(vertStart,10:10,2:2)
987 | SetBitField(vertDisplay,10:10,1:1)
988 | SetBitField(vertTotal,10:10,0:0);
990 regp->CRTC[NV_VGA_CRTCX_HEB] = SetBitField(horizTotal,8:8,0:0)
991 | SetBitField(horizDisplay,8:8,1:1)
992 | SetBitField(horizBlankStart,8:8,2:2)
993 | SetBitField(horizStart,8:8,3:3);
995 regp->CRTC[NV_VGA_CRTCX_EXTRA] = SetBitField(vertTotal,11:11,0:0)
996 | SetBitField(vertDisplay,11:11,2:2)
997 | SetBitField(vertStart,11:11,4:4)
998 | SetBitField(vertBlankStart,11:11,6:6);
1000 if(mode->Flags & V_INTERLACE) {
1001 horizTotal = (horizTotal >> 1) & ~1;
1002 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = Set8Bits(horizTotal);
1003 regp->CRTC[NV_VGA_CRTCX_HEB] |= SetBitField(horizTotal,8:8,4:4);
1005 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = 0xff; /* interlace off */
1008 regp->CRTC[NV_VGA_CRTCX_BUFFER] = 0xfa;
1011 /* Maybe we need more to enable DFP screens, haiku has some info on this register */
1012 regp->CRTC[NV_VGA_CRTCX_LCD] = (1 << 3) | (1 << 0);
1014 regp->CRTC[NV_VGA_CRTCX_LCD] = 0;
1017 /* I'm trusting haiku driver on this one, they say it enables an external TDMS clock */
1019 regp->CRTC[NV_VGA_CRTCX_59] = 0x1;
1021 regp->CRTC[NV_VGA_CRTCX_59] = 0x0;
1025 * Initialize DAC palette.
1027 if(pLayout->bitsPerPixel != 8 ) {
1028 for (i = 0; i < 256; i++) {
1030 regp->DAC[(i*3)+1] = i;
1031 regp->DAC[(i*3)+2] = i;
1036 * Calculate the extended registers.
1039 if(pLayout->depth < 24) {
1045 if(pNv->Architecture >= NV_ARCH_10) {
1046 pNv->CURSOR = (CARD32 *)pNv->Cursor->map;
1049 ErrorF("crtc %d %d %d\n", nv_crtc->crtc, mode->CrtcHDisplay, pScrn->displayWidth);
1050 nv_crtc_calc_state_ext(crtc,
1052 pScrn->displayWidth,
1059 regp->CRTC[NV_VGA_CRTCX_PIXEL] |= (1 << 7);
1062 regp->CRTC[NV_VGA_CRTCX_FIFO1] = savep->CRTC[NV_VGA_CRTCX_FIFO1] & ~(1<<5);
1064 /* NV40's don't set FPP units, unless in special conditions (then they set both) */
1065 /* But what are those special conditions? */
1066 if (pNv->Architecture <= NV_ARCH_30) {
1068 if(nv_crtc->head == 1) {
1069 regp->head |= NV_CRTC_FSEL_FPP1;
1070 } else if (pNv->twoHeads) {
1071 regp->head |= NV_CRTC_FSEL_FPP2;
1076 /* In some situations I2C is also enabled on head 1, even when head 1 is not used */
1077 /* Seems to be in "crosswired" tmds situations as far as i can tell (only one known case) */
1078 if (nv_crtc->head == 0) {
1079 regp->head |= NV_CRTC_FSEL_I2C;
1080 if (pNv->overlayAdaptor) {
1081 regp->head |= NV_CRTC_FSEL_OVERLAY;
1085 regp->cursorConfig = 0x00000100;
1086 if(mode->Flags & V_DBLSCAN)
1087 regp->cursorConfig |= (1 << 4);
1088 if(pNv->alphaCursor) {
1089 if((pNv->Chipset & 0x0ff0) != CHIPSET_NV11) {
1090 regp->cursorConfig |= 0x04011000;
1092 regp->cursorConfig |= 0x14011000;
1095 regp->cursorConfig |= 0x02000000;
1098 regp->CRTC[NV_VGA_CRTCX_FP_HTIMING] = 0;
1099 regp->CRTC[NV_VGA_CRTCX_FP_VTIMING] = 0;
1101 /* 0x20 seems to be enabled and 0x14 disabled */
1102 regp->CRTC[NV_VGA_CRTCX_26] = 0x20;
1104 /* 0x00 is disabled, 0x22 crt and 0x88 dfp */
1107 regp->CRTC[NV_VGA_CRTCX_3B] = 0x88;
1109 regp->CRTC[NV_VGA_CRTCX_3B] = 0x22;
1112 /* These values seem to vary */
1113 regp->CRTC[NV_VGA_CRTCX_3C] = savep->CRTC[NV_VGA_CRTCX_3C];
1115 /* 0x80 seems to be used very often, if not always */
1116 regp->CRTC[NV_VGA_CRTCX_45] = 0x80;
1118 /* These values seem to vary */
1119 /* 0x01, 0x10, 0x11 for example */
1120 regp->CRTC[NV_VGA_CRTCX_56] = savep->CRTC[NV_VGA_CRTCX_56];
1122 /* bit0: Seems to be mostly used on crtc1 */
1123 /* bit1: 1=crtc1, 0=crtc, but i'm unsure about this */
1124 /* 0x7E (crtc0, only seen in one dump) and 0x7F (crtc1) seem to be some kind of disable setting */
1125 /* This is likely to be incomplete */
1126 /* This is a very strange register, changed very often by the blob */
1127 regp->CRTC[NV_VGA_CRTCX_58] = 0x0;
1129 /* The blob seems to take the current value from crtc 0, add 4 to that and reuse the old value for crtc 1*/
1130 if (nv_crtc->head == 1) {
1131 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_0_reg_52;
1133 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_0_reg_52 + 4;
1136 /* The exact purpose of this register is unknown, but we copy value from crtc0 */
1137 regp->unk81c = nvReadCRTC0(pNv, NV_CRTC_081C);
1139 regp->unk830 = mode->CrtcVDisplay - 3;
1140 regp->unk834 = mode->CrtcVDisplay - 1;
1144 * Sets up registers for the given mode/adjusted_mode pair.
1146 * The clocks, CRTCs and outputs attached to this CRTC must be off.
1148 * This shouldn't enable any clocks, CRTCs, or outputs, but they should
1149 * be easily turned on/off after this.
1152 nv_crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
1153 DisplayModePtr adjusted_mode,
1156 ScrnInfoPtr pScrn = crtc->scrn;
1157 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1158 NVPtr pNv = NVPTR(pScrn);
1160 ErrorF("nv_crtc_mode_set is called for CRTC %d\n", nv_crtc->crtc);
1162 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Mode on CRTC %d\n", nv_crtc->crtc);
1163 xf86PrintModeline(pScrn->scrnIndex, mode);
1164 NVCrtcSetOwner(crtc);
1166 nv_crtc_mode_set_vga(crtc, mode);
1167 nv_crtc_mode_set_regs(crtc, mode);
1170 NVVgaProtect(crtc, TRUE);
1171 nv_crtc_load_state_ext(crtc, &pNv->ModeReg);
1172 nv_crtc_load_state_vga(crtc, &pNv->ModeReg);
1173 nv_crtc_load_state_pll(pNv, &pNv->ModeReg);
1175 NVVgaProtect(crtc, FALSE);
1176 // NVCrtcLockUnlock(crtc, 1);
1178 NVCrtcSetBase(crtc, x, y);
1180 pNv->crtc_active[nv_crtc->head] = TRUE;
1181 #if X_BYTE_ORDER == X_BIG_ENDIAN
1182 /* turn on LFB swapping */
1186 tmp = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_SWAPPING);
1188 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_SWAPPING, tmp);
1194 void nv_crtc_save(xf86CrtcPtr crtc)
1196 ScrnInfoPtr pScrn = crtc->scrn;
1197 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1198 NVPtr pNv = NVPTR(pScrn);
1200 ErrorF("nv_crtc_save is called for CRTC %d\n", nv_crtc->crtc);
1202 NVCrtcSetOwner(crtc);
1203 nv_crtc_save_state_pll(pNv, &pNv->SavedReg);
1204 nv_crtc_save_state_vga(crtc, &pNv->SavedReg);
1205 nv_crtc_save_state_ext(crtc, &pNv->SavedReg);
1208 void nv_crtc_restore(xf86CrtcPtr crtc)
1210 ScrnInfoPtr pScrn = crtc->scrn;
1211 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1212 NVPtr pNv = NVPTR(pScrn);
1214 ErrorF("nv_crtc_restore is called for CRTC %d\n", nv_crtc->crtc);
1216 NVCrtcSetOwner(crtc);
1217 nv_crtc_load_state_ext(crtc, &pNv->SavedReg);
1218 nv_crtc_load_state_vga(crtc, &pNv->SavedReg);
1219 nv_crtc_load_state_pll(pNv, &pNv->SavedReg);
1220 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->vtOWNER);
1223 void nv_crtc_prepare(xf86CrtcPtr crtc)
1225 ScrnInfoPtr pScrn = crtc->scrn;
1226 NVPtr pNv = NVPTR(pScrn);
1227 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1229 ErrorF("nv_crtc_prepare is called for CRTC %d\n", nv_crtc->crtc);
1231 /* Sync the engine before adjust mode */
1232 if (pNv->EXADriverPtr) {
1233 exaMarkSync(pScrn->pScreen);
1234 exaWaitSync(pScrn->pScreen);
1238 void nv_crtc_commit(xf86CrtcPtr crtc)
1240 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1241 ErrorF("nv_crtc_commit for CRTC %d\n", nv_crtc->crtc);
1244 static Bool nv_crtc_lock(xf86CrtcPtr crtc)
1246 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1247 ErrorF("nv_crtc_lock is called for CRTC %d\n", nv_crtc->crtc);
1252 static void nv_crtc_unlock(xf86CrtcPtr crtc)
1254 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1255 ErrorF("nv_crtc_unlock is called for CRTC %d\n", nv_crtc->crtc);
1258 /* NV04-NV10 doesn't support alpha cursors */
1259 static const xf86CrtcFuncsRec nv_crtc_funcs = {
1260 .dpms = nv_crtc_dpms,
1261 .save = nv_crtc_save, /* XXX */
1262 .restore = nv_crtc_restore, /* XXX */
1263 .mode_fixup = nv_crtc_mode_fixup,
1264 .mode_set = nv_crtc_mode_set,
1265 .prepare = nv_crtc_prepare,
1266 .commit = nv_crtc_commit,
1267 .destroy = NULL, /* XXX */
1268 .lock = nv_crtc_lock,
1269 .unlock = nv_crtc_unlock,
1270 .set_cursor_colors = nv_crtc_set_cursor_colors,
1271 .set_cursor_position = nv_crtc_set_cursor_position,
1272 .show_cursor = nv_crtc_show_cursor,
1273 .hide_cursor = nv_crtc_hide_cursor,
1274 .load_cursor_image = nv_crtc_load_cursor_image,
1277 /* NV11 and up has support for alpha cursors. */
1278 /* Due to different maximum sizes we cannot allow it to use normal cursors */
1279 static const xf86CrtcFuncsRec nv11_crtc_funcs = {
1280 .dpms = nv_crtc_dpms,
1281 .save = nv_crtc_save, /* XXX */
1282 .restore = nv_crtc_restore, /* XXX */
1283 .mode_fixup = nv_crtc_mode_fixup,
1284 .mode_set = nv_crtc_mode_set,
1285 .prepare = nv_crtc_prepare,
1286 .commit = nv_crtc_commit,
1287 .destroy = NULL, /* XXX */
1288 .lock = nv_crtc_lock,
1289 .unlock = nv_crtc_unlock,
1290 .set_cursor_colors = nv_crtc_set_cursor_colors,
1291 .set_cursor_position = nv_crtc_set_cursor_position,
1292 .show_cursor = nv_crtc_show_cursor,
1293 .hide_cursor = nv_crtc_hide_cursor,
1294 .load_cursor_argb = nv_crtc_load_cursor_argb,
1299 nv_crtc_init(ScrnInfoPtr pScrn, int crtc_num)
1301 NVPtr pNv = NVPTR(pScrn);
1303 NVCrtcPrivatePtr nv_crtc;
1305 if (pNv->NVArch >= 0x11) {
1306 crtc = xf86CrtcCreate (pScrn, &nv11_crtc_funcs);
1308 crtc = xf86CrtcCreate (pScrn, &nv_crtc_funcs);
1313 nv_crtc = xnfcalloc (sizeof (NVCrtcPrivateRec), 1);
1314 nv_crtc->crtc = crtc_num;
1315 nv_crtc->head = crtc_num;
1317 crtc->driver_private = nv_crtc;
1319 NVCrtcLockUnlock(crtc, 0);
1322 static void nv_crtc_load_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
1324 ScrnInfoPtr pScrn = crtc->scrn;
1325 NVPtr pNv = NVPTR(pScrn);
1326 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1331 regp = &state->crtc_reg[nv_crtc->head];
1333 NVWriteMiscOut(crtc, regp->MiscOutReg);
1335 for (i = 1; i < 5; i++)
1336 NVWriteVgaSeq(crtc, i, regp->Sequencer[i]);
1338 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 of CRTC[17] */
1339 NVWriteVgaCrtc(crtc, 17, regp->CRTC[17] & ~0x80);
1341 for (i = 0; i < 25; i++)
1342 NVWriteVgaCrtc(crtc, i, regp->CRTC[i]);
1344 for (i = 0; i < 9; i++)
1345 NVWriteVgaGr(crtc, i, regp->Graphics[i]);
1347 NVEnablePalette(crtc);
1348 for (i = 0; i < 21; i++)
1349 NVWriteVgaAttr(crtc, i, regp->Attribute[i]);
1350 NVDisablePalette(crtc);
1354 static void nv_crtc_fix_nv40_hw_cursor(xf86CrtcPtr crtc)
1356 /* TODO - implement this properly */
1357 ScrnInfoPtr pScrn = crtc->scrn;
1358 NVPtr pNv = NVPTR(pScrn);
1360 if(pNv->Architecture == NV_ARCH_40) { /* HW bug */
1361 volatile CARD32 curpos = nvReadCurRAMDAC(pNv, NV_RAMDAC_CURSOR_POS);
1362 nvWriteCurRAMDAC(pNv, NV_RAMDAC_CURSOR_POS, curpos);
1366 static void nv_crtc_load_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
1368 ScrnInfoPtr pScrn = crtc->scrn;
1369 NVPtr pNv = NVPTR(pScrn);
1370 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1375 regp = &state->crtc_reg[nv_crtc->head];
1377 if(pNv->Architecture >= NV_ARCH_10) {
1379 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_FSEL, regp->head);
1381 nvWriteVIDEO(pNv, NV_PVIDEO_STOP, 1);
1382 nvWriteVIDEO(pNv, NV_PVIDEO_INTR_EN, 0);
1383 nvWriteVIDEO(pNv, NV_PVIDEO_OFFSET_BUFF(0), 0);
1384 nvWriteVIDEO(pNv, NV_PVIDEO_OFFSET_BUFF(1), 0);
1385 nvWriteVIDEO(pNv, NV_PVIDEO_LIMIT(0), pNv->VRAMPhysicalSize - 1);
1386 nvWriteVIDEO(pNv, NV_PVIDEO_LIMIT(1), pNv->VRAMPhysicalSize - 1);
1387 nvWriteMC(pNv, 0x1588, 0);
1389 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER, 0xff);
1390 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER, regp->CRTC[NV_VGA_CRTCX_BUFFER]);
1391 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_CURSOR_CONFIG, regp->cursorConfig);
1392 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_0830, regp->unk830);
1393 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_0834, regp->unk834);
1394 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_081C, regp->unk81c);
1396 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FP_HTIMING, regp->CRTC[NV_VGA_CRTCX_FP_HTIMING]);
1397 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FP_VTIMING, regp->CRTC[NV_VGA_CRTCX_FP_VTIMING]);
1399 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_26, regp->CRTC[NV_VGA_CRTCX_26]);
1400 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_3B, regp->CRTC[NV_VGA_CRTCX_3B]);
1401 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_3C, regp->CRTC[NV_VGA_CRTCX_3C]);
1402 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_45, regp->CRTC[NV_VGA_CRTCX_45]);
1403 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_52, regp->CRTC[NV_VGA_CRTCX_52]);
1404 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_56, regp->CRTC[NV_VGA_CRTCX_56]);
1405 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_58, regp->CRTC[NV_VGA_CRTCX_58]);
1406 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_59, regp->CRTC[NV_VGA_CRTCX_59]);
1407 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_EXTRA, regp->CRTC[NV_VGA_CRTCX_EXTRA]);
1410 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT0, regp->CRTC[NV_VGA_CRTCX_REPAINT0]);
1411 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1, regp->CRTC[NV_VGA_CRTCX_REPAINT1]);
1412 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LSR, regp->CRTC[NV_VGA_CRTCX_LSR]);
1413 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_PIXEL, regp->CRTC[NV_VGA_CRTCX_PIXEL]);
1414 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LCD, regp->CRTC[NV_VGA_CRTCX_LCD]);
1415 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_HEB, regp->CRTC[NV_VGA_CRTCX_HEB]);
1416 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO1, regp->CRTC[NV_VGA_CRTCX_FIFO1]);
1417 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO0, regp->CRTC[NV_VGA_CRTCX_FIFO0]);
1418 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM, regp->CRTC[NV_VGA_CRTCX_FIFO_LWM]);
1419 if(pNv->Architecture >= NV_ARCH_30) {
1420 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM_NV30, regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30]);
1423 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL0, regp->CRTC[NV_VGA_CRTCX_CURCTL0]);
1424 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL1, regp->CRTC[NV_VGA_CRTCX_CURCTL1]);
1425 nv_crtc_fix_nv40_hw_cursor(crtc);
1426 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL2, regp->CRTC[NV_VGA_CRTCX_CURCTL2]);
1427 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_INTERLACE, regp->CRTC[NV_VGA_CRTCX_INTERLACE]);
1429 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_INTR_EN_0, 0);
1430 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_INTR_0, NV_CRTC_INTR_VBLANK);
1432 pNv->CurrentState = state;
1435 static void nv_crtc_save_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
1437 ScrnInfoPtr pScrn = crtc->scrn;
1438 NVPtr pNv = NVPTR(pScrn);
1439 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1443 regp = &state->crtc_reg[nv_crtc->head];
1445 regp->MiscOutReg = NVReadMiscOut(crtc);
1447 for (i = 0; i < 25; i++)
1448 regp->CRTC[i] = NVReadVgaCrtc(crtc, i);
1450 NVEnablePalette(crtc);
1451 for (i = 0; i < 21; i++)
1452 regp->Attribute[i] = NVReadVgaAttr(crtc, i);
1453 NVDisablePalette(crtc);
1455 for (i = 0; i < 9; i++)
1456 regp->Graphics[i] = NVReadVgaGr(crtc, i);
1458 for (i = 1; i < 5; i++)
1459 regp->Sequencer[i] = NVReadVgaSeq(crtc, i);
1463 static void nv_crtc_save_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
1465 ScrnInfoPtr pScrn = crtc->scrn;
1466 NVPtr pNv = NVPTR(pScrn);
1467 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1471 regp = &state->crtc_reg[nv_crtc->head];
1473 regp->CRTC[NV_VGA_CRTCX_LCD] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_LCD);
1474 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT0);
1475 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1);
1476 regp->CRTC[NV_VGA_CRTCX_LSR] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_LSR);
1477 regp->CRTC[NV_VGA_CRTCX_PIXEL] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_PIXEL);
1478 regp->CRTC[NV_VGA_CRTCX_HEB] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_HEB);
1479 regp->CRTC[NV_VGA_CRTCX_FIFO1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO1);
1481 regp->CRTC[NV_VGA_CRTCX_FIFO0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO0);
1482 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM);
1483 if(pNv->Architecture >= NV_ARCH_30) {
1484 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM_NV30);
1486 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL0);
1487 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL1);
1488 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL2);
1489 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_INTERLACE);
1491 regp->unk830 = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_0830);
1492 regp->unk834 = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_0834);
1493 regp->unk81c = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_081C);
1495 if(pNv->Architecture >= NV_ARCH_10) {
1497 regp->head = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_FSEL);
1498 regp->crtcOwner = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_OWNER);
1500 regp->CRTC[NV_VGA_CRTCX_EXTRA] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_EXTRA);
1502 regp->cursorConfig = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_CURSOR_CONFIG);
1504 regp->CRTC[NV_VGA_CRTCX_26] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_26);
1505 regp->CRTC[NV_VGA_CRTCX_3B] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_3B);
1506 regp->CRTC[NV_VGA_CRTCX_3C] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_3C);
1507 regp->CRTC[NV_VGA_CRTCX_45] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_45);
1508 regp->CRTC[NV_VGA_CRTCX_52] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_52);
1509 regp->CRTC[NV_VGA_CRTCX_56] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_56);
1510 regp->CRTC[NV_VGA_CRTCX_58] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_58);
1511 regp->CRTC[NV_VGA_CRTCX_59] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_59);
1512 regp->CRTC[NV_VGA_CRTCX_BUFFER] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER);
1513 regp->CRTC[NV_VGA_CRTCX_FP_HTIMING] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FP_HTIMING);
1514 regp->CRTC[NV_VGA_CRTCX_FP_VTIMING] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FP_VTIMING);
1519 NVCrtcSetBase (xf86CrtcPtr crtc, int x, int y)
1521 ScrnInfoPtr pScrn = crtc->scrn;
1522 NVPtr pNv = NVPTR(pScrn);
1523 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1524 NVFBLayout *pLayout = &pNv->CurrentLayout;
1527 ErrorF("NVCrtcSetBase: x: %d y: %d\n", x, y);
1529 start += ((y * pScrn->displayWidth + x) * (pLayout->bitsPerPixel/8));
1530 start += pNv->FB->offset;
1532 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_START, start);
1538 static void NVCrtcWriteDacMask(xf86CrtcPtr crtc, CARD8 value)
1540 ScrnInfoPtr pScrn = crtc->scrn;
1541 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1542 NVPtr pNv = NVPTR(pScrn);
1543 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1545 NV_WR08(pDACReg, VGA_DAC_MASK, value);
1548 static CARD8 NVCrtcReadDacMask(xf86CrtcPtr crtc)
1550 ScrnInfoPtr pScrn = crtc->scrn;
1551 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1552 NVPtr pNv = NVPTR(pScrn);
1553 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1555 return NV_RD08(pDACReg, VGA_DAC_MASK);
1558 static void NVCrtcWriteDacReadAddr(xf86CrtcPtr crtc, CARD8 value)
1560 ScrnInfoPtr pScrn = crtc->scrn;
1561 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1562 NVPtr pNv = NVPTR(pScrn);
1563 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1565 NV_WR08(pDACReg, VGA_DAC_READ_ADDR, value);
1568 static void NVCrtcWriteDacWriteAddr(xf86CrtcPtr crtc, CARD8 value)
1570 ScrnInfoPtr pScrn = crtc->scrn;
1571 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1572 NVPtr pNv = NVPTR(pScrn);
1573 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1575 NV_WR08(pDACReg, VGA_DAC_WRITE_ADDR, value);
1578 static void NVCrtcWriteDacData(xf86CrtcPtr crtc, CARD8 value)
1580 ScrnInfoPtr pScrn = crtc->scrn;
1581 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1582 NVPtr pNv = NVPTR(pScrn);
1583 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1585 NV_WR08(pDACReg, VGA_DAC_DATA, value);
1588 static CARD8 NVCrtcReadDacData(xf86CrtcPtr crtc, CARD8 value)
1590 ScrnInfoPtr pScrn = crtc->scrn;
1591 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1592 NVPtr pNv = NVPTR(pScrn);
1593 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1595 return NV_RD08(pDACReg, VGA_DAC_DATA);
1598 void NVCrtcLoadPalette(xf86CrtcPtr crtc)
1601 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1603 ScrnInfoPtr pScrn = crtc->scrn;
1604 NVPtr pNv = NVPTR(pScrn);
1606 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
1608 NVCrtcSetOwner(crtc);
1609 NVCrtcWriteDacMask(crtc, 0xff);
1610 NVCrtcWriteDacWriteAddr(crtc, 0x00);
1612 for (i = 0; i<768; i++) {
1613 NVCrtcWriteDacData(crtc, regp->DAC[i]);
1615 NVDisablePalette(crtc);
1618 void NVCrtcBlankScreen(xf86CrtcPtr crtc, Bool on)
1620 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1623 NVCrtcSetOwner(crtc);
1625 scrn = NVReadVgaSeq(crtc, 0x01);
1632 NVVgaSeqReset(crtc, TRUE);
1633 NVWriteVgaSeq(crtc, 0x01, scrn);
1634 NVVgaSeqReset(crtc, FALSE);
1637 #endif /* ENABLE_RANDR12 */
1639 /*************************************************************************** \
1641 |* Copyright 1993-2003 NVIDIA, Corporation. All rights reserved. *|
1643 |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
1644 |* international laws. Users and possessors of this source code are *|
1645 |* hereby granted a nonexclusive, royalty-free copyright license to *|
1646 |* use this code in individual and commercial software. *|
1648 |* Any use of this source code must include, in the user documenta- *|
1649 |* tion and internal comments to the code, notices to the end user *|
1652 |* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
1654 |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
1655 |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
1656 |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
1657 |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
1658 |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
1659 |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
1660 |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
1661 |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
1662 |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
1663 |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
1664 |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
1666 |* U.S. Government End Users. This source code is a "commercial *|
1667 |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
1668 |* consisting of "commercial computer software" and "commercial *|
1669 |* computer software documentation," as such terms are used in *|
1670 |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
1671 |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
1672 |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
1673 |* all U.S. Government End Users acquire the source code with only *|
1674 |* those rights set forth herein. *|
1676 \***************************************************************************/