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 /* Stuff from haiku, put here so it doesn't look messy up there */
904 ErrorF("crtc: Pre-sync workaround\n");
905 /* Reverted to what nv did, because that works for all resolutions on flatpanels */
907 vertStart = vertTotal - 3;
908 vertEnd = vertTotal - 2;
909 vertBlankStart = vertStart;
910 horizStart = horizTotal - 5;
911 horizEnd = horizTotal - 2;
912 horizBlankEnd = horizTotal + 4;
913 if (pNv->overlayAdaptor) {
914 /* This reportedly works around Xv some overlay bandwidth problems*/
918 ErrorF("crtc: Post-sync workaround\n");
920 ErrorF("horizDisplay: 0x%X \n", horizDisplay);
921 ErrorF("horizStart: 0x%X \n", horizStart);
922 ErrorF("horizEnd: 0x%X \n", horizEnd);
923 ErrorF("horizTotal: 0x%X \n", horizTotal);
924 ErrorF("horizBlankStart: 0x%X \n", horizBlankStart);
925 ErrorF("horizBlankEnd: 0x%X \n", horizBlankEnd);
926 ErrorF("vertDisplay: 0x%X \n", vertDisplay);
927 ErrorF("vertStart: 0x%X \n", vertStart);
928 ErrorF("vertEnd: 0x%X \n", vertEnd);
929 ErrorF("vertTotal: 0x%X \n", vertTotal);
930 ErrorF("vertBlankStart: 0x%X \n", vertBlankStart);
931 ErrorF("vertBlankEnd: 0x%X \n", vertBlankEnd);
933 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
934 savep = &pNv->SavedReg.crtc_reg[nv_crtc->head];
936 if(mode->Flags & V_INTERLACE)
939 regp->CRTC[NV_VGA_CRTCX_HTOTAL] = Set8Bits(horizTotal);
940 regp->CRTC[NV_VGA_CRTCX_HDISPE] = Set8Bits(horizDisplay);
941 regp->CRTC[NV_VGA_CRTCX_HBLANKS] = Set8Bits(horizBlankStart);
942 regp->CRTC[NV_VGA_CRTCX_HBLANKE] = SetBitField(horizBlankEnd,4:0,4:0)
944 regp->CRTC[NV_VGA_CRTCX_HSYNCS] = Set8Bits(horizStart);
945 regp->CRTC[NV_VGA_CRTCX_HSYNCE] = SetBitField(horizBlankEnd,5:5,7:7)
946 | SetBitField(horizEnd,4:0,4:0);
947 regp->CRTC[NV_VGA_CRTCX_VTOTAL] = SetBitField(vertTotal,7:0,7:0);
948 regp->CRTC[NV_VGA_CRTCX_OVERFLOW] = SetBitField(vertTotal,8:8,0:0)
949 | SetBitField(vertDisplay,8:8,1:1)
950 | SetBitField(vertStart,8:8,2:2)
951 | SetBitField(vertBlankStart,8:8,3:3)
952 | SetBitField(linecomp,8:8,4:4)
953 | SetBitField(vertTotal,9:9,5:5)
954 | SetBitField(vertDisplay,9:9,6:6)
955 | SetBitField(vertStart,9:9,7:7);
956 regp->CRTC[NV_VGA_CRTCX_MAXSCLIN] = SetBitField(vertBlankStart,9:9,5:5)
958 | ((mode->Flags & V_DBLSCAN) ? 0x80 : 0x00);
959 regp->CRTC[NV_VGA_CRTCX_VSYNCS] = Set8Bits(vertStart);
960 regp->CRTC[NV_VGA_CRTCX_VSYNCE] = SetBitField(vertEnd,3:0,3:0) | SetBit(5);
961 regp->CRTC[NV_VGA_CRTCX_VDISPE] = Set8Bits(vertDisplay);
962 regp->CRTC[NV_VGA_CRTCX_PITCHL] = ((pScrn->displayWidth/8)*(pLayout->bitsPerPixel/8));
963 regp->CRTC[NV_VGA_CRTCX_VBLANKS] = Set8Bits(vertBlankStart);
964 regp->CRTC[NV_VGA_CRTCX_VBLANKE] = Set8Bits(vertBlankEnd);
965 /* Not an extended register */
966 regp->CRTC[NV_VGA_CRTCX_LINECOMP] = Set8Bits(linecomp);
968 regp->Attribute[0x10] = 0x01;
971 regp->Attribute[0x11] = 0x00;
973 regp->CRTC[NV_VGA_CRTCX_LSR] = SetBitField(horizBlankEnd,6:6,4:4)
974 | SetBitField(vertBlankStart,10:10,3:3)
975 | SetBitField(vertStart,10:10,2:2)
976 | SetBitField(vertDisplay,10:10,1:1)
977 | SetBitField(vertTotal,10:10,0:0);
979 regp->CRTC[NV_VGA_CRTCX_HEB] = SetBitField(horizTotal,8:8,0:0)
980 | SetBitField(horizDisplay,8:8,1:1)
981 | SetBitField(horizBlankStart,8:8,2:2)
982 | SetBitField(horizStart,8:8,3:3);
984 regp->CRTC[NV_VGA_CRTCX_EXTRA] = SetBitField(vertTotal,11:11,0:0)
985 | SetBitField(vertDisplay,11:11,2:2)
986 | SetBitField(vertStart,11:11,4:4)
987 | SetBitField(vertBlankStart,11:11,6:6);
989 if(mode->Flags & V_INTERLACE) {
990 horizTotal = (horizTotal >> 1) & ~1;
991 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = Set8Bits(horizTotal);
992 regp->CRTC[NV_VGA_CRTCX_HEB] |= SetBitField(horizTotal,8:8,4:4);
994 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = 0xff; /* interlace off */
997 regp->CRTC[NV_VGA_CRTCX_BUFFER] = 0xfa;
1000 /* Maybe we need more to enable DFP screens, haiku has some info on this register */
1001 regp->CRTC[NV_VGA_CRTCX_LCD] = (1 << 3) | (1 << 0);
1003 regp->CRTC[NV_VGA_CRTCX_LCD] = 0;
1006 /* I'm trusting haiku driver on this one, they say it enables an external TDMS clock */
1008 regp->CRTC[NV_VGA_CRTCX_59] = 0x1;
1010 regp->CRTC[NV_VGA_CRTCX_59] = 0x0;
1014 * Initialize DAC palette.
1016 if(pLayout->bitsPerPixel != 8 ) {
1017 for (i = 0; i < 256; i++) {
1019 regp->DAC[(i*3)+1] = i;
1020 regp->DAC[(i*3)+2] = i;
1025 * Calculate the extended registers.
1028 if(pLayout->depth < 24) {
1034 if(pNv->Architecture >= NV_ARCH_10) {
1035 pNv->CURSOR = (CARD32 *)pNv->Cursor->map;
1038 ErrorF("crtc %d %d %d\n", nv_crtc->crtc, mode->CrtcHDisplay, pScrn->displayWidth);
1039 nv_crtc_calc_state_ext(crtc,
1041 pScrn->displayWidth,
1048 regp->CRTC[NV_VGA_CRTCX_PIXEL] |= (1 << 7);
1051 regp->CRTC[NV_VGA_CRTCX_FIFO1] = savep->CRTC[NV_VGA_CRTCX_FIFO1] & ~(1<<5);
1053 /* NV40's don't set FPP units, unless in special conditions (then they set both) */
1054 /* But what are those special conditions? */
1055 if (pNv->Architecture <= NV_ARCH_30) {
1057 if(nv_crtc->head == 1) {
1058 regp->head |= NV_CRTC_FSEL_FPP1;
1059 } else if (pNv->twoHeads) {
1060 regp->head |= NV_CRTC_FSEL_FPP2;
1065 /* In some situations I2C is also enabled on head 1, even when head 1 is not used */
1066 /* Seems to be in "crosswired" tmds situations as far as i can tell (only one known case) */
1067 if (nv_crtc->head == 0) {
1068 regp->head |= NV_CRTC_FSEL_I2C;
1069 if (pNv->overlayAdaptor) {
1070 regp->head |= NV_CRTC_FSEL_OVERLAY;
1074 regp->cursorConfig = 0x00000100;
1075 if(mode->Flags & V_DBLSCAN)
1076 regp->cursorConfig |= (1 << 4);
1077 if(pNv->alphaCursor) {
1078 if((pNv->Chipset & 0x0ff0) != CHIPSET_NV11) {
1079 regp->cursorConfig |= 0x04011000;
1081 regp->cursorConfig |= 0x14011000;
1084 regp->cursorConfig |= 0x02000000;
1087 regp->CRTC[NV_VGA_CRTCX_FP_HTIMING] = 0;
1088 regp->CRTC[NV_VGA_CRTCX_FP_VTIMING] = 0;
1090 /* 0x20 seems to be enabled and 0x14 disabled */
1091 regp->CRTC[NV_VGA_CRTCX_26] = 0x20;
1093 /* 0x00 is disabled, 0x22 crt and 0x88 dfp */
1096 regp->CRTC[NV_VGA_CRTCX_3B] = 0x88;
1098 regp->CRTC[NV_VGA_CRTCX_3B] = 0x22;
1101 /* These values seem to vary */
1102 regp->CRTC[NV_VGA_CRTCX_3C] = savep->CRTC[NV_VGA_CRTCX_3C];
1104 /* 0x80 seems to be used very often, if not always */
1105 regp->CRTC[NV_VGA_CRTCX_45] = 0x80;
1107 /* These values seem to vary */
1108 /* 0x01, 0x10, 0x11 for example */
1109 regp->CRTC[NV_VGA_CRTCX_56] = savep->CRTC[NV_VGA_CRTCX_56];
1111 /* bit0: Seems to be mostly used on crtc1 */
1112 /* bit1: 1=crtc1, 0=crtc, but i'm unsure about this */
1113 /* 0x7E (crtc0, only seen in one dump) and 0x7F (crtc1) seem to be some kind of disable setting */
1114 /* This is likely to be incomplete */
1115 /* This is a very strange register, changed very often by the blob */
1116 regp->CRTC[NV_VGA_CRTCX_58] = 0x0;
1118 /* The blob seems to take the current value from crtc 0, add 4 to that and reuse the old value for crtc 1*/
1119 if (nv_crtc->head == 1) {
1120 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_0_reg_52;
1122 regp->CRTC[NV_VGA_CRTCX_52] = pNv->misc_info.crtc_0_reg_52 + 4;
1125 /* The exact purpose of this register is unknown, but we copy value from crtc0 */
1126 regp->unk81c = nvReadCRTC0(pNv, NV_CRTC_081C);
1128 regp->unk830 = mode->CrtcVDisplay - 3;
1129 regp->unk834 = mode->CrtcVDisplay - 1;
1133 * Sets up registers for the given mode/adjusted_mode pair.
1135 * The clocks, CRTCs and outputs attached to this CRTC must be off.
1137 * This shouldn't enable any clocks, CRTCs, or outputs, but they should
1138 * be easily turned on/off after this.
1141 nv_crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
1142 DisplayModePtr adjusted_mode,
1145 ScrnInfoPtr pScrn = crtc->scrn;
1146 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1147 NVPtr pNv = NVPTR(pScrn);
1149 ErrorF("nv_crtc_mode_set is called for CRTC %d\n", nv_crtc->crtc);
1151 xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Mode on CRTC %d\n", nv_crtc->crtc);
1152 xf86PrintModeline(pScrn->scrnIndex, mode);
1153 NVCrtcSetOwner(crtc);
1155 nv_crtc_mode_set_vga(crtc, mode);
1156 nv_crtc_mode_set_regs(crtc, mode);
1159 NVVgaProtect(crtc, TRUE);
1160 nv_crtc_load_state_ext(crtc, &pNv->ModeReg);
1161 nv_crtc_load_state_vga(crtc, &pNv->ModeReg);
1162 nv_crtc_load_state_pll(pNv, &pNv->ModeReg);
1164 NVVgaProtect(crtc, FALSE);
1165 // NVCrtcLockUnlock(crtc, 1);
1167 NVCrtcSetBase(crtc, x, y);
1169 pNv->crtc_active[nv_crtc->head] = TRUE;
1170 #if X_BYTE_ORDER == X_BIG_ENDIAN
1171 /* turn on LFB swapping */
1175 tmp = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_SWAPPING);
1177 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_SWAPPING, tmp);
1183 void nv_crtc_save(xf86CrtcPtr crtc)
1185 ScrnInfoPtr pScrn = crtc->scrn;
1186 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1187 NVPtr pNv = NVPTR(pScrn);
1189 ErrorF("nv_crtc_save is called for CRTC %d\n", nv_crtc->crtc);
1191 NVCrtcSetOwner(crtc);
1192 nv_crtc_save_state_pll(pNv, &pNv->SavedReg);
1193 nv_crtc_save_state_vga(crtc, &pNv->SavedReg);
1194 nv_crtc_save_state_ext(crtc, &pNv->SavedReg);
1197 void nv_crtc_restore(xf86CrtcPtr crtc)
1199 ScrnInfoPtr pScrn = crtc->scrn;
1200 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1201 NVPtr pNv = NVPTR(pScrn);
1203 ErrorF("nv_crtc_restore is called for CRTC %d\n", nv_crtc->crtc);
1205 NVCrtcSetOwner(crtc);
1206 nv_crtc_load_state_ext(crtc, &pNv->SavedReg);
1207 nv_crtc_load_state_vga(crtc, &pNv->SavedReg);
1208 nv_crtc_load_state_pll(pNv, &pNv->SavedReg);
1209 nvWriteVGA(pNv, NV_VGA_CRTCX_OWNER, pNv->vtOWNER);
1212 void nv_crtc_prepare(xf86CrtcPtr crtc)
1214 ScrnInfoPtr pScrn = crtc->scrn;
1215 NVPtr pNv = NVPTR(pScrn);
1216 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1218 ErrorF("nv_crtc_prepare is called for CRTC %d\n", nv_crtc->crtc);
1220 /* Sync the engine before adjust mode */
1221 if (pNv->EXADriverPtr) {
1222 exaMarkSync(pScrn->pScreen);
1223 exaWaitSync(pScrn->pScreen);
1227 void nv_crtc_commit(xf86CrtcPtr crtc)
1229 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1230 ErrorF("nv_crtc_commit for CRTC %d\n", nv_crtc->crtc);
1233 static Bool nv_crtc_lock(xf86CrtcPtr crtc)
1235 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1236 ErrorF("nv_crtc_lock is called for CRTC %d\n", nv_crtc->crtc);
1241 static void nv_crtc_unlock(xf86CrtcPtr crtc)
1243 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1244 ErrorF("nv_crtc_unlock is called for CRTC %d\n", nv_crtc->crtc);
1247 /* NV04-NV10 doesn't support alpha cursors */
1248 static const xf86CrtcFuncsRec nv_crtc_funcs = {
1249 .dpms = nv_crtc_dpms,
1250 .save = nv_crtc_save, /* XXX */
1251 .restore = nv_crtc_restore, /* XXX */
1252 .mode_fixup = nv_crtc_mode_fixup,
1253 .mode_set = nv_crtc_mode_set,
1254 .prepare = nv_crtc_prepare,
1255 .commit = nv_crtc_commit,
1256 .destroy = NULL, /* XXX */
1257 .lock = nv_crtc_lock,
1258 .unlock = nv_crtc_unlock,
1259 .set_cursor_colors = nv_crtc_set_cursor_colors,
1260 .set_cursor_position = nv_crtc_set_cursor_position,
1261 .show_cursor = nv_crtc_show_cursor,
1262 .hide_cursor = nv_crtc_hide_cursor,
1263 .load_cursor_image = nv_crtc_load_cursor_image,
1266 /* NV11 and up has support for alpha cursors. */
1267 /* Due to different maximum sizes we cannot allow it to use normal cursors */
1268 static const xf86CrtcFuncsRec nv11_crtc_funcs = {
1269 .dpms = nv_crtc_dpms,
1270 .save = nv_crtc_save, /* XXX */
1271 .restore = nv_crtc_restore, /* XXX */
1272 .mode_fixup = nv_crtc_mode_fixup,
1273 .mode_set = nv_crtc_mode_set,
1274 .prepare = nv_crtc_prepare,
1275 .commit = nv_crtc_commit,
1276 .destroy = NULL, /* XXX */
1277 .lock = nv_crtc_lock,
1278 .unlock = nv_crtc_unlock,
1279 .set_cursor_colors = nv_crtc_set_cursor_colors,
1280 .set_cursor_position = nv_crtc_set_cursor_position,
1281 .show_cursor = nv_crtc_show_cursor,
1282 .hide_cursor = nv_crtc_hide_cursor,
1283 .load_cursor_argb = nv_crtc_load_cursor_argb,
1288 nv_crtc_init(ScrnInfoPtr pScrn, int crtc_num)
1290 NVPtr pNv = NVPTR(pScrn);
1292 NVCrtcPrivatePtr nv_crtc;
1294 if (pNv->NVArch >= 0x11) {
1295 crtc = xf86CrtcCreate (pScrn, &nv11_crtc_funcs);
1297 crtc = xf86CrtcCreate (pScrn, &nv_crtc_funcs);
1302 nv_crtc = xnfcalloc (sizeof (NVCrtcPrivateRec), 1);
1303 nv_crtc->crtc = crtc_num;
1304 nv_crtc->head = crtc_num;
1306 crtc->driver_private = nv_crtc;
1308 NVCrtcLockUnlock(crtc, 0);
1311 static void nv_crtc_load_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
1313 ScrnInfoPtr pScrn = crtc->scrn;
1314 NVPtr pNv = NVPTR(pScrn);
1315 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1320 regp = &state->crtc_reg[nv_crtc->head];
1322 NVWriteMiscOut(crtc, regp->MiscOutReg);
1324 for (i = 1; i < 5; i++)
1325 NVWriteVgaSeq(crtc, i, regp->Sequencer[i]);
1327 /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 of CRTC[17] */
1328 NVWriteVgaCrtc(crtc, 17, regp->CRTC[17] & ~0x80);
1330 for (i = 0; i < 25; i++)
1331 NVWriteVgaCrtc(crtc, i, regp->CRTC[i]);
1333 for (i = 0; i < 9; i++)
1334 NVWriteVgaGr(crtc, i, regp->Graphics[i]);
1336 NVEnablePalette(crtc);
1337 for (i = 0; i < 21; i++)
1338 NVWriteVgaAttr(crtc, i, regp->Attribute[i]);
1339 NVDisablePalette(crtc);
1343 static void nv_crtc_fix_nv40_hw_cursor(xf86CrtcPtr crtc)
1345 /* TODO - implement this properly */
1346 ScrnInfoPtr pScrn = crtc->scrn;
1347 NVPtr pNv = NVPTR(pScrn);
1349 if(pNv->Architecture == NV_ARCH_40) { /* HW bug */
1350 volatile CARD32 curpos = nvReadCurRAMDAC(pNv, NV_RAMDAC_CURSOR_POS);
1351 nvWriteCurRAMDAC(pNv, NV_RAMDAC_CURSOR_POS, curpos);
1355 static void nv_crtc_load_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
1357 ScrnInfoPtr pScrn = crtc->scrn;
1358 NVPtr pNv = NVPTR(pScrn);
1359 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1364 regp = &state->crtc_reg[nv_crtc->head];
1366 if(pNv->Architecture >= NV_ARCH_10) {
1368 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_FSEL, regp->head);
1370 nvWriteVIDEO(pNv, NV_PVIDEO_STOP, 1);
1371 nvWriteVIDEO(pNv, NV_PVIDEO_INTR_EN, 0);
1372 nvWriteVIDEO(pNv, NV_PVIDEO_OFFSET_BUFF(0), 0);
1373 nvWriteVIDEO(pNv, NV_PVIDEO_OFFSET_BUFF(1), 0);
1374 nvWriteVIDEO(pNv, NV_PVIDEO_LIMIT(0), pNv->VRAMPhysicalSize - 1);
1375 nvWriteVIDEO(pNv, NV_PVIDEO_LIMIT(1), pNv->VRAMPhysicalSize - 1);
1376 nvWriteMC(pNv, 0x1588, 0);
1378 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER, 0xff);
1379 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER, regp->CRTC[NV_VGA_CRTCX_BUFFER]);
1380 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_CURSOR_CONFIG, regp->cursorConfig);
1381 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_0830, regp->unk830);
1382 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_0834, regp->unk834);
1383 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_081C, regp->unk81c);
1385 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FP_HTIMING, regp->CRTC[NV_VGA_CRTCX_FP_HTIMING]);
1386 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FP_VTIMING, regp->CRTC[NV_VGA_CRTCX_FP_VTIMING]);
1388 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_26, regp->CRTC[NV_VGA_CRTCX_26]);
1389 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_3B, regp->CRTC[NV_VGA_CRTCX_3B]);
1390 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_3C, regp->CRTC[NV_VGA_CRTCX_3C]);
1391 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_45, regp->CRTC[NV_VGA_CRTCX_45]);
1392 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_52, regp->CRTC[NV_VGA_CRTCX_52]);
1393 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_56, regp->CRTC[NV_VGA_CRTCX_56]);
1394 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_58, regp->CRTC[NV_VGA_CRTCX_58]);
1395 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_59, regp->CRTC[NV_VGA_CRTCX_59]);
1396 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_EXTRA, regp->CRTC[NV_VGA_CRTCX_EXTRA]);
1399 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT0, regp->CRTC[NV_VGA_CRTCX_REPAINT0]);
1400 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1, regp->CRTC[NV_VGA_CRTCX_REPAINT1]);
1401 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LSR, regp->CRTC[NV_VGA_CRTCX_LSR]);
1402 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_PIXEL, regp->CRTC[NV_VGA_CRTCX_PIXEL]);
1403 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_LCD, regp->CRTC[NV_VGA_CRTCX_LCD]);
1404 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_HEB, regp->CRTC[NV_VGA_CRTCX_HEB]);
1405 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO1, regp->CRTC[NV_VGA_CRTCX_FIFO1]);
1406 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO0, regp->CRTC[NV_VGA_CRTCX_FIFO0]);
1407 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM, regp->CRTC[NV_VGA_CRTCX_FIFO_LWM]);
1408 if(pNv->Architecture >= NV_ARCH_30) {
1409 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM_NV30, regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30]);
1412 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL0, regp->CRTC[NV_VGA_CRTCX_CURCTL0]);
1413 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL1, regp->CRTC[NV_VGA_CRTCX_CURCTL1]);
1414 nv_crtc_fix_nv40_hw_cursor(crtc);
1415 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL2, regp->CRTC[NV_VGA_CRTCX_CURCTL2]);
1416 NVWriteVgaCrtc(crtc, NV_VGA_CRTCX_INTERLACE, regp->CRTC[NV_VGA_CRTCX_INTERLACE]);
1418 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_INTR_EN_0, 0);
1419 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_INTR_0, NV_CRTC_INTR_VBLANK);
1421 pNv->CurrentState = state;
1424 static void nv_crtc_save_state_vga(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
1426 ScrnInfoPtr pScrn = crtc->scrn;
1427 NVPtr pNv = NVPTR(pScrn);
1428 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1432 regp = &state->crtc_reg[nv_crtc->head];
1434 regp->MiscOutReg = NVReadMiscOut(crtc);
1436 for (i = 0; i < 25; i++)
1437 regp->CRTC[i] = NVReadVgaCrtc(crtc, i);
1439 NVEnablePalette(crtc);
1440 for (i = 0; i < 21; i++)
1441 regp->Attribute[i] = NVReadVgaAttr(crtc, i);
1442 NVDisablePalette(crtc);
1444 for (i = 0; i < 9; i++)
1445 regp->Graphics[i] = NVReadVgaGr(crtc, i);
1447 for (i = 1; i < 5; i++)
1448 regp->Sequencer[i] = NVReadVgaSeq(crtc, i);
1452 static void nv_crtc_save_state_ext(xf86CrtcPtr crtc, RIVA_HW_STATE *state)
1454 ScrnInfoPtr pScrn = crtc->scrn;
1455 NVPtr pNv = NVPTR(pScrn);
1456 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1460 regp = &state->crtc_reg[nv_crtc->head];
1462 regp->CRTC[NV_VGA_CRTCX_LCD] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_LCD);
1463 regp->CRTC[NV_VGA_CRTCX_REPAINT0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT0);
1464 regp->CRTC[NV_VGA_CRTCX_REPAINT1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_REPAINT1);
1465 regp->CRTC[NV_VGA_CRTCX_LSR] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_LSR);
1466 regp->CRTC[NV_VGA_CRTCX_PIXEL] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_PIXEL);
1467 regp->CRTC[NV_VGA_CRTCX_HEB] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_HEB);
1468 regp->CRTC[NV_VGA_CRTCX_FIFO1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO1);
1470 regp->CRTC[NV_VGA_CRTCX_FIFO0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO0);
1471 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM);
1472 if(pNv->Architecture >= NV_ARCH_30) {
1473 regp->CRTC[NV_VGA_CRTCX_FIFO_LWM_NV30] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FIFO_LWM_NV30);
1475 regp->CRTC[NV_VGA_CRTCX_CURCTL0] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL0);
1476 regp->CRTC[NV_VGA_CRTCX_CURCTL1] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL1);
1477 regp->CRTC[NV_VGA_CRTCX_CURCTL2] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_CURCTL2);
1478 regp->CRTC[NV_VGA_CRTCX_INTERLACE] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_INTERLACE);
1480 regp->unk830 = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_0830);
1481 regp->unk834 = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_0834);
1482 regp->unk81c = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_081C);
1484 if(pNv->Architecture >= NV_ARCH_10) {
1486 regp->head = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_FSEL);
1487 regp->crtcOwner = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_OWNER);
1489 regp->CRTC[NV_VGA_CRTCX_EXTRA] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_EXTRA);
1491 regp->cursorConfig = nvReadCRTC(pNv, nv_crtc->head, NV_CRTC_CURSOR_CONFIG);
1493 regp->CRTC[NV_VGA_CRTCX_26] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_26);
1494 regp->CRTC[NV_VGA_CRTCX_3B] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_3B);
1495 regp->CRTC[NV_VGA_CRTCX_3C] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_3C);
1496 regp->CRTC[NV_VGA_CRTCX_45] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_45);
1497 regp->CRTC[NV_VGA_CRTCX_52] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_52);
1498 regp->CRTC[NV_VGA_CRTCX_56] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_56);
1499 regp->CRTC[NV_VGA_CRTCX_58] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_58);
1500 regp->CRTC[NV_VGA_CRTCX_59] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_59);
1501 regp->CRTC[NV_VGA_CRTCX_BUFFER] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_BUFFER);
1502 regp->CRTC[NV_VGA_CRTCX_FP_HTIMING] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FP_HTIMING);
1503 regp->CRTC[NV_VGA_CRTCX_FP_VTIMING] = NVReadVgaCrtc(crtc, NV_VGA_CRTCX_FP_VTIMING);
1508 NVCrtcSetBase (xf86CrtcPtr crtc, int x, int y)
1510 ScrnInfoPtr pScrn = crtc->scrn;
1511 NVPtr pNv = NVPTR(pScrn);
1512 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1513 NVFBLayout *pLayout = &pNv->CurrentLayout;
1516 ErrorF("NVCrtcSetBase: x: %d y: %d\n", x, y);
1518 start += ((y * pScrn->displayWidth + x) * (pLayout->bitsPerPixel/8));
1519 start += pNv->FB->offset;
1521 nvWriteCRTC(pNv, nv_crtc->head, NV_CRTC_START, start);
1527 static void NVCrtcWriteDacMask(xf86CrtcPtr crtc, CARD8 value)
1529 ScrnInfoPtr pScrn = crtc->scrn;
1530 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1531 NVPtr pNv = NVPTR(pScrn);
1532 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1534 NV_WR08(pDACReg, VGA_DAC_MASK, value);
1537 static CARD8 NVCrtcReadDacMask(xf86CrtcPtr crtc)
1539 ScrnInfoPtr pScrn = crtc->scrn;
1540 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1541 NVPtr pNv = NVPTR(pScrn);
1542 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1544 return NV_RD08(pDACReg, VGA_DAC_MASK);
1547 static void NVCrtcWriteDacReadAddr(xf86CrtcPtr crtc, CARD8 value)
1549 ScrnInfoPtr pScrn = crtc->scrn;
1550 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1551 NVPtr pNv = NVPTR(pScrn);
1552 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1554 NV_WR08(pDACReg, VGA_DAC_READ_ADDR, value);
1557 static void NVCrtcWriteDacWriteAddr(xf86CrtcPtr crtc, CARD8 value)
1559 ScrnInfoPtr pScrn = crtc->scrn;
1560 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1561 NVPtr pNv = NVPTR(pScrn);
1562 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1564 NV_WR08(pDACReg, VGA_DAC_WRITE_ADDR, value);
1567 static void NVCrtcWriteDacData(xf86CrtcPtr crtc, CARD8 value)
1569 ScrnInfoPtr pScrn = crtc->scrn;
1570 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1571 NVPtr pNv = NVPTR(pScrn);
1572 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1574 NV_WR08(pDACReg, VGA_DAC_DATA, value);
1577 static CARD8 NVCrtcReadDacData(xf86CrtcPtr crtc, CARD8 value)
1579 ScrnInfoPtr pScrn = crtc->scrn;
1580 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1581 NVPtr pNv = NVPTR(pScrn);
1582 volatile CARD8 *pDACReg = nv_crtc->head ? pNv->PDIO1 : pNv->PDIO0;
1584 return NV_RD08(pDACReg, VGA_DAC_DATA);
1587 void NVCrtcLoadPalette(xf86CrtcPtr crtc)
1590 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1592 ScrnInfoPtr pScrn = crtc->scrn;
1593 NVPtr pNv = NVPTR(pScrn);
1595 regp = &pNv->ModeReg.crtc_reg[nv_crtc->head];
1597 NVCrtcSetOwner(crtc);
1598 NVCrtcWriteDacMask(crtc, 0xff);
1599 NVCrtcWriteDacWriteAddr(crtc, 0x00);
1601 for (i = 0; i<768; i++) {
1602 NVCrtcWriteDacData(crtc, regp->DAC[i]);
1604 NVDisablePalette(crtc);
1607 void NVCrtcBlankScreen(xf86CrtcPtr crtc, Bool on)
1609 NVCrtcPrivatePtr nv_crtc = crtc->driver_private;
1612 NVCrtcSetOwner(crtc);
1614 scrn = NVReadVgaSeq(crtc, 0x01);
1621 NVVgaSeqReset(crtc, TRUE);
1622 NVWriteVgaSeq(crtc, 0x01, scrn);
1623 NVVgaSeqReset(crtc, FALSE);
1626 #endif /* ENABLE_RANDR12 */
1628 /*************************************************************************** \
1630 |* Copyright 1993-2003 NVIDIA, Corporation. All rights reserved. *|
1632 |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
1633 |* international laws. Users and possessors of this source code are *|
1634 |* hereby granted a nonexclusive, royalty-free copyright license to *|
1635 |* use this code in individual and commercial software. *|
1637 |* Any use of this source code must include, in the user documenta- *|
1638 |* tion and internal comments to the code, notices to the end user *|
1641 |* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
1643 |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
1644 |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
1645 |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
1646 |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
1647 |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
1648 |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
1649 |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
1650 |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
1651 |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
1652 |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
1653 |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
1655 |* U.S. Government End Users. This source code is a "commercial *|
1656 |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
1657 |* consisting of "commercial computer software" and "commercial *|
1658 |* computer software documentation," as such terms are used in *|
1659 |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
1660 |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
1661 |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
1662 |* all U.S. Government End Users acquire the source code with only *|
1663 |* those rights set forth herein. *|
1665 \***************************************************************************/