1ff50d0d1SRudolf Cornelissen /* second CTRC functionality for GeForce cards */ 2ff50d0d1SRudolf Cornelissen /* Author: 317f2ecd6SRudolf Cornelissen Rudolf Cornelissen 11/2002-6/2004 408705d96Sshatty */ 508705d96Sshatty 608705d96Sshatty #define MODULE_BIT 0x00020000 708705d96Sshatty 808705d96Sshatty #include "nv_std.h" 908705d96Sshatty 10ff50d0d1SRudolf Cornelissen /*Adjust passed parameters to a valid mode line*/ 11ff50d0d1SRudolf Cornelissen status_t nv_crtc2_validate_timing( 12ff50d0d1SRudolf Cornelissen uint16 *hd_e,uint16 *hs_s,uint16 *hs_e,uint16 *ht, 13ff50d0d1SRudolf Cornelissen uint16 *vd_e,uint16 *vs_s,uint16 *vs_e,uint16 *vt 14ff50d0d1SRudolf Cornelissen ) 1508705d96Sshatty { 16ff50d0d1SRudolf Cornelissen /* horizontal */ 17ff50d0d1SRudolf Cornelissen /* make all parameters multiples of 8 */ 18ff50d0d1SRudolf Cornelissen *hd_e &= 0xfff8; 19ff50d0d1SRudolf Cornelissen *hs_s &= 0xfff8; 20ff50d0d1SRudolf Cornelissen *hs_e &= 0xfff8; 21ff50d0d1SRudolf Cornelissen *ht &= 0xfff8; 22ff50d0d1SRudolf Cornelissen 23ff50d0d1SRudolf Cornelissen /* confine to required number of bits, taking logic into account */ 24ff50d0d1SRudolf Cornelissen if (*hd_e > ((0x01ff - 2) << 3)) *hd_e = ((0x01ff - 2) << 3); 25ff50d0d1SRudolf Cornelissen if (*hs_s > ((0x01ff - 1) << 3)) *hs_s = ((0x01ff - 1) << 3); 26ff50d0d1SRudolf Cornelissen if (*hs_e > ( 0x01ff << 3)) *hs_e = ( 0x01ff << 3); 27ff50d0d1SRudolf Cornelissen if (*ht > ((0x01ff + 5) << 3)) *ht = ((0x01ff + 5) << 3); 28ff50d0d1SRudolf Cornelissen 29ff50d0d1SRudolf Cornelissen /* NOTE: keep horizontal timing at multiples of 8! */ 30ff50d0d1SRudolf Cornelissen /* confine to a reasonable width */ 31ff50d0d1SRudolf Cornelissen if (*hd_e < 640) *hd_e = 640; 32ff50d0d1SRudolf Cornelissen if (*hd_e > 2048) *hd_e = 2048; 33ff50d0d1SRudolf Cornelissen 34ff50d0d1SRudolf Cornelissen /* if hor. total does not leave room for a sensible sync pulse, increase it! */ 35ff50d0d1SRudolf Cornelissen if (*ht < (*hd_e + 80)) *ht = (*hd_e + 80); 36ff50d0d1SRudolf Cornelissen 37ff50d0d1SRudolf Cornelissen /* make sure sync pulse is not during display */ 38ff50d0d1SRudolf Cornelissen if (*hs_e > (*ht - 8)) *hs_e = (*ht - 8); 39ff50d0d1SRudolf Cornelissen if (*hs_s < (*hd_e + 8)) *hs_s = (*hd_e + 8); 40ff50d0d1SRudolf Cornelissen 41ff50d0d1SRudolf Cornelissen /* correct sync pulse if it is too long: 42ff50d0d1SRudolf Cornelissen * there are only 5 bits available to save this in the card registers! */ 43ff50d0d1SRudolf Cornelissen if (*hs_e > (*hs_s + 0xf8)) *hs_e = (*hs_s + 0xf8); 44ff50d0d1SRudolf Cornelissen 45ff50d0d1SRudolf Cornelissen /*vertical*/ 46ff50d0d1SRudolf Cornelissen /* confine to required number of bits, taking logic into account */ 47ff50d0d1SRudolf Cornelissen //fixme if needed: on GeForce cards there are 12 instead of 11 bits... 48ff50d0d1SRudolf Cornelissen if (*vd_e > (0x7ff - 2)) *vd_e = (0x7ff - 2); 49ff50d0d1SRudolf Cornelissen if (*vs_s > (0x7ff - 1)) *vs_s = (0x7ff - 1); 50ff50d0d1SRudolf Cornelissen if (*vs_e > 0x7ff ) *vs_e = 0x7ff ; 51ff50d0d1SRudolf Cornelissen if (*vt > (0x7ff + 2)) *vt = (0x7ff + 2); 52ff50d0d1SRudolf Cornelissen 53ff50d0d1SRudolf Cornelissen /* confine to a reasonable height */ 54ff50d0d1SRudolf Cornelissen if (*vd_e < 480) *vd_e = 480; 55ff50d0d1SRudolf Cornelissen if (*vd_e > 1536) *vd_e = 1536; 56ff50d0d1SRudolf Cornelissen 57ff50d0d1SRudolf Cornelissen /*if vertical total does not leave room for a sync pulse, increase it!*/ 58ff50d0d1SRudolf Cornelissen if (*vt < (*vd_e + 3)) *vt = (*vd_e + 3); 59ff50d0d1SRudolf Cornelissen 60ff50d0d1SRudolf Cornelissen /* make sure sync pulse is not during display */ 61ff50d0d1SRudolf Cornelissen if (*vs_e > (*vt - 1)) *vs_e = (*vt - 1); 62ff50d0d1SRudolf Cornelissen if (*vs_s < (*vd_e + 1)) *vs_s = (*vd_e + 1); 63ff50d0d1SRudolf Cornelissen 64ff50d0d1SRudolf Cornelissen /* correct sync pulse if it is too long: 65ff50d0d1SRudolf Cornelissen * there are only 4 bits available to save this in the card registers! */ 66ff50d0d1SRudolf Cornelissen if (*vs_e > (*vs_s + 0x0f)) *vs_e = (*vs_s + 0x0f); 67ff50d0d1SRudolf Cornelissen 68ff50d0d1SRudolf Cornelissen return B_OK; 69ff50d0d1SRudolf Cornelissen } 70ff50d0d1SRudolf Cornelissen 71ff50d0d1SRudolf Cornelissen /*set a mode line - inputs are in pixels*/ 72ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_timing(display_mode target) 73ff50d0d1SRudolf Cornelissen { 74ff50d0d1SRudolf Cornelissen uint8 temp; 75ff50d0d1SRudolf Cornelissen 76ff50d0d1SRudolf Cornelissen uint32 htotal; /*total horizontal total VCLKs*/ 77ff50d0d1SRudolf Cornelissen uint32 hdisp_e; /*end of horizontal display (begins at 0)*/ 78ff50d0d1SRudolf Cornelissen uint32 hsync_s; /*begin of horizontal sync pulse*/ 79ff50d0d1SRudolf Cornelissen uint32 hsync_e; /*end of horizontal sync pulse*/ 80ff50d0d1SRudolf Cornelissen uint32 hblnk_s; /*begin horizontal blanking*/ 81ff50d0d1SRudolf Cornelissen uint32 hblnk_e; /*end horizontal blanking*/ 82ff50d0d1SRudolf Cornelissen 83ff50d0d1SRudolf Cornelissen uint32 vtotal; /*total vertical total scanlines*/ 84ff50d0d1SRudolf Cornelissen uint32 vdisp_e; /*end of vertical display*/ 85ff50d0d1SRudolf Cornelissen uint32 vsync_s; /*begin of vertical sync pulse*/ 86ff50d0d1SRudolf Cornelissen uint32 vsync_e; /*end of vertical sync pulse*/ 87ff50d0d1SRudolf Cornelissen uint32 vblnk_s; /*begin vertical blanking*/ 88ff50d0d1SRudolf Cornelissen uint32 vblnk_e; /*end vertical blanking*/ 89ff50d0d1SRudolf Cornelissen 90ff50d0d1SRudolf Cornelissen uint32 linecomp; /*split screen and vdisp_e interrupt*/ 9108705d96Sshatty 9208705d96Sshatty LOG(4,("CRTC2: setting timing\n")); 9308705d96Sshatty 94c9210b6fSRudolf Cornelissen /* setup tuned internal modeline for flatpanel if connected and active */ 95*2cb6fc9cSRudolf Cornelissen /* notes: 96*2cb6fc9cSRudolf Cornelissen * - the CRTC modeline must end earlier than the panel modeline to keep correct 97*2cb6fc9cSRudolf Cornelissen * sync going; 98*2cb6fc9cSRudolf Cornelissen * - if the CRTC modeline ends too soon, pixelnoise will occur in 8 (or so) pixel 99*2cb6fc9cSRudolf Cornelissen * wide horizontal stripes. This can be observed earliest on fullscreen overlay, 100*2cb6fc9cSRudolf Cornelissen * and if it gets worse, also normal desktop output will suffer. The stripes 101*2cb6fc9cSRudolf Cornelissen * are mainly visible at the left of the screen, over the entire screen height. */ 102c567e072SRudolf Cornelissen if (si->ps.tmds2_active) 103c567e072SRudolf Cornelissen { 104c567e072SRudolf Cornelissen LOG(2,("CRTC2: DFP active: tuning modeline\n")); 105c567e072SRudolf Cornelissen 106c567e072SRudolf Cornelissen /* horizontal timing */ 10716fc5a30SRudolf Cornelissen target.timing.h_sync_start = 108268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.h_sync_start / ((float)si->ps.p2_timing.h_display)) * 10916fc5a30SRudolf Cornelissen target.timing.h_display)) & 0xfff8; 11016fc5a30SRudolf Cornelissen 11116fc5a30SRudolf Cornelissen target.timing.h_sync_end = 112268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.h_sync_end / ((float)si->ps.p2_timing.h_display)) * 11316fc5a30SRudolf Cornelissen target.timing.h_display)) & 0xfff8; 11416fc5a30SRudolf Cornelissen 11516fc5a30SRudolf Cornelissen target.timing.h_total = 116268624c4SRudolf Cornelissen (((uint16)((si->ps.p2_timing.h_total / ((float)si->ps.p2_timing.h_display)) * 117bef5b86aSRudolf Cornelissen target.timing.h_display)) & 0xfff8) - 8; 11816fc5a30SRudolf Cornelissen 119*2cb6fc9cSRudolf Cornelissen /* NV11 timing has tighter constraints than later cards */ 12004e6b7ceSRudolf Cornelissen if ((si->ps.card_type == NV11) && 12104e6b7ceSRudolf Cornelissen (target.timing.h_display == si->ps.p2_timing.h_display)) 12204e6b7ceSRudolf Cornelissen { 123*2cb6fc9cSRudolf Cornelissen target.timing.h_total -= 56; 12404e6b7ceSRudolf Cornelissen } 12504e6b7ceSRudolf Cornelissen 12616fc5a30SRudolf Cornelissen if (target.timing.h_sync_start == target.timing.h_display) 12716fc5a30SRudolf Cornelissen target.timing.h_sync_start += 8; 12816fc5a30SRudolf Cornelissen if (target.timing.h_sync_end == target.timing.h_total) 12916fc5a30SRudolf Cornelissen target.timing.h_sync_end -= 8; 130c567e072SRudolf Cornelissen 131c567e072SRudolf Cornelissen /* vertical timing */ 13216fc5a30SRudolf Cornelissen target.timing.v_sync_start = 133268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_sync_start / ((float)si->ps.p2_timing.v_display)) * 13416fc5a30SRudolf Cornelissen target.timing.v_display)); 13516fc5a30SRudolf Cornelissen 13616fc5a30SRudolf Cornelissen target.timing.v_sync_end = 137268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_sync_end / ((float)si->ps.p2_timing.v_display)) * 13816fc5a30SRudolf Cornelissen target.timing.v_display)); 13916fc5a30SRudolf Cornelissen 14016fc5a30SRudolf Cornelissen target.timing.v_total = 141268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_total / ((float)si->ps.p2_timing.v_display)) * 142b97caf33SRudolf Cornelissen target.timing.v_display)) - 1; 14316fc5a30SRudolf Cornelissen 14416fc5a30SRudolf Cornelissen if (target.timing.v_sync_start == target.timing.v_display) 14516fc5a30SRudolf Cornelissen target.timing.v_sync_start += 1; 14616fc5a30SRudolf Cornelissen if (target.timing.v_sync_end == target.timing.v_total) 14716fc5a30SRudolf Cornelissen target.timing.v_sync_end -= 1; 148e6708074SRudolf Cornelissen 149e6708074SRudolf Cornelissen /* disable GPU scaling testmode so automatic scaling will be done */ 150e6708074SRudolf Cornelissen DAC2W(FP_DEBUG1, 0); 151c567e072SRudolf Cornelissen } 152c567e072SRudolf Cornelissen 153ff50d0d1SRudolf Cornelissen /* Modify parameters as required by standard VGA */ 154ff50d0d1SRudolf Cornelissen htotal = ((target.timing.h_total >> 3) - 5); 155ff50d0d1SRudolf Cornelissen hdisp_e = ((target.timing.h_display >> 3) - 1); 156ff50d0d1SRudolf Cornelissen hblnk_s = hdisp_e; 157ff50d0d1SRudolf Cornelissen hblnk_e = (htotal + 4);//0; 158ff50d0d1SRudolf Cornelissen hsync_s = (target.timing.h_sync_start >> 3); 159ff50d0d1SRudolf Cornelissen hsync_e = (target.timing.h_sync_end >> 3); 160ff50d0d1SRudolf Cornelissen 161ff50d0d1SRudolf Cornelissen vtotal = target.timing.v_total - 2; 162ff50d0d1SRudolf Cornelissen vdisp_e = target.timing.v_display - 1; 163ff50d0d1SRudolf Cornelissen vblnk_s = vdisp_e; 164ff50d0d1SRudolf Cornelissen vblnk_e = (vtotal + 1); 165ff50d0d1SRudolf Cornelissen vsync_s = target.timing.v_sync_start;//-1; 166ff50d0d1SRudolf Cornelissen vsync_e = target.timing.v_sync_end;//-1; 167ff50d0d1SRudolf Cornelissen 168ff50d0d1SRudolf Cornelissen /* prevent memory adress counter from being reset (linecomp may not occur) */ 169ff50d0d1SRudolf Cornelissen linecomp = target.timing.v_display; 170ff50d0d1SRudolf Cornelissen 17164c14e7eSRudolf Cornelissen /* enable access to secondary head */ 17264c14e7eSRudolf Cornelissen set_crtc_owner(1); 173255e5021SRudolf Cornelissen 174a16d55ddSRudolf Cornelissen /* Note for laptop and DVI flatpanels: 175a16d55ddSRudolf Cornelissen * CRTC timing has a seperate set of registers from flatpanel timing. 176a16d55ddSRudolf Cornelissen * The flatpanel timing registers have scaling registers that are used to match 177a16d55ddSRudolf Cornelissen * these two modelines. */ 17808705d96Sshatty { 179a16d55ddSRudolf Cornelissen LOG(4,("CRTC2: Setting full timing...\n")); 18008705d96Sshatty 181ff50d0d1SRudolf Cornelissen /* log the mode that will be set */ 182ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2:\n\tHTOT:%x\n\tHDISPEND:%x\n\tHBLNKS:%x\n\tHBLNKE:%x\n\tHSYNCS:%x\n\tHSYNCE:%x\n\t",htotal,hdisp_e,hblnk_s,hblnk_e,hsync_s,hsync_e)); 183ff50d0d1SRudolf Cornelissen LOG(2,("VTOT:%x\n\tVDISPEND:%x\n\tVBLNKS:%x\n\tVBLNKE:%x\n\tVSYNCS:%x\n\tVSYNCE:%x\n",vtotal,vdisp_e,vblnk_s,vblnk_e,vsync_s,vsync_e)); 18408705d96Sshatty 185ff50d0d1SRudolf Cornelissen /* actually program the card! */ 186ff50d0d1SRudolf Cornelissen /* unlock CRTC registers at index 0-7 */ 187ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCE, (CRTC2R(VSYNCE) & 0x7f)); 188ff50d0d1SRudolf Cornelissen /* horizontal standard VGA regs */ 189ff50d0d1SRudolf Cornelissen CRTC2W(HTOTAL, (htotal & 0xff)); 190ff50d0d1SRudolf Cornelissen CRTC2W(HDISPE, (hdisp_e & 0xff)); 191ff50d0d1SRudolf Cornelissen CRTC2W(HBLANKS, (hblnk_s & 0xff)); 192ff50d0d1SRudolf Cornelissen /* also unlock vertical retrace registers in advance */ 193ff50d0d1SRudolf Cornelissen CRTC2W(HBLANKE, ((hblnk_e & 0x1f) | 0x80)); 194ff50d0d1SRudolf Cornelissen CRTC2W(HSYNCS, (hsync_s & 0xff)); 195ff50d0d1SRudolf Cornelissen CRTC2W(HSYNCE, ((hsync_e & 0x1f) | ((hblnk_e & 0x20) << 2))); 19608705d96Sshatty 197ff50d0d1SRudolf Cornelissen /* vertical standard VGA regs */ 198ff50d0d1SRudolf Cornelissen CRTC2W(VTOTAL, (vtotal & 0xff)); 199ff50d0d1SRudolf Cornelissen CRTC2W(OVERFLOW, 200ff50d0d1SRudolf Cornelissen ( 201ff50d0d1SRudolf Cornelissen ((vtotal & 0x100) >> (8 - 0)) | ((vtotal & 0x200) >> (9 - 5)) | 202ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x100) >> (8 - 1)) | ((vdisp_e & 0x200) >> (9 - 6)) | 203ff50d0d1SRudolf Cornelissen ((vsync_s & 0x100) >> (8 - 2)) | ((vsync_s & 0x200) >> (9 - 7)) | 204ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x100) >> (8 - 3)) | ((linecomp & 0x100) >> (8 - 4)) 205ff50d0d1SRudolf Cornelissen )); 206ff50d0d1SRudolf Cornelissen CRTC2W(PRROWSCN, 0x00); /* not used */ 207ff50d0d1SRudolf Cornelissen CRTC2W(MAXSCLIN, (((vblnk_s & 0x200) >> (9 - 5)) | ((linecomp & 0x200) >> (9 - 6)))); 208ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCS, (vsync_s & 0xff)); 209ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCE, ((CRTC2R(VSYNCE) & 0xf0) | (vsync_e & 0x0f))); 210ff50d0d1SRudolf Cornelissen CRTC2W(VDISPE, (vdisp_e & 0xff)); 211ff50d0d1SRudolf Cornelissen CRTC2W(VBLANKS, (vblnk_s & 0xff)); 212ff50d0d1SRudolf Cornelissen CRTC2W(VBLANKE, (vblnk_e & 0xff)); 213ff50d0d1SRudolf Cornelissen CRTC2W(LINECOMP, (linecomp & 0xff)); 21408705d96Sshatty 215ff50d0d1SRudolf Cornelissen /* horizontal extended regs */ 216ff50d0d1SRudolf Cornelissen //fixme: we reset bit4. is this correct?? 217ff50d0d1SRudolf Cornelissen CRTC2W(HEB, (CRTC2R(HEB) & 0xe0) | 218ff50d0d1SRudolf Cornelissen ( 219ff50d0d1SRudolf Cornelissen ((htotal & 0x100) >> (8 - 0)) | 220ff50d0d1SRudolf Cornelissen ((hdisp_e & 0x100) >> (8 - 1)) | 221ff50d0d1SRudolf Cornelissen ((hblnk_s & 0x100) >> (8 - 2)) | 222ff50d0d1SRudolf Cornelissen ((hsync_s & 0x100) >> (8 - 3)) 223ff50d0d1SRudolf Cornelissen )); 22408705d96Sshatty 225ff50d0d1SRudolf Cornelissen /* (mostly) vertical extended regs */ 226ff50d0d1SRudolf Cornelissen CRTC2W(LSR, 227ff50d0d1SRudolf Cornelissen ( 228ff50d0d1SRudolf Cornelissen ((vtotal & 0x400) >> (10 - 0)) | 229ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x400) >> (10 - 1)) | 230ff50d0d1SRudolf Cornelissen ((vsync_s & 0x400) >> (10 - 2)) | 231ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x400) >> (10 - 3)) | 232ff50d0d1SRudolf Cornelissen ((hblnk_e & 0x040) >> (6 - 4)) 233ff50d0d1SRudolf Cornelissen //fixme: we still miss one linecomp bit!?! is this it?? 234ff50d0d1SRudolf Cornelissen //| ((linecomp & 0x400) >> 3) 235ff50d0d1SRudolf Cornelissen )); 23608705d96Sshatty 237ff50d0d1SRudolf Cornelissen /* more vertical extended regs */ 238ff50d0d1SRudolf Cornelissen CRTC2W(EXTRA, 239ff50d0d1SRudolf Cornelissen ( 240ff50d0d1SRudolf Cornelissen ((vtotal & 0x800) >> (11 - 0)) | 241ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x800) >> (11 - 2)) | 242ff50d0d1SRudolf Cornelissen ((vsync_s & 0x800) >> (11 - 4)) | 243ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x800) >> (11 - 6)) 244ff50d0d1SRudolf Cornelissen //fixme: do we miss another linecomp bit!?! 245ff50d0d1SRudolf Cornelissen )); 24608705d96Sshatty 247ff50d0d1SRudolf Cornelissen /* setup 'large screen' mode */ 248ff50d0d1SRudolf Cornelissen if (target.timing.h_display >= 1280) 249ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0xfb)); 25008705d96Sshatty else 251ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x04)); 25208705d96Sshatty 253ff50d0d1SRudolf Cornelissen /* setup HSYNC & VSYNC polarity */ 254ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: sync polarity: ")); 255255e5021SRudolf Cornelissen temp = NV_REG8(NV8_MISCR); 256ff50d0d1SRudolf Cornelissen if (target.timing.flags & B_POSITIVE_HSYNC) 257ff50d0d1SRudolf Cornelissen { 258ff50d0d1SRudolf Cornelissen LOG(2,("H:pos ")); 259ff50d0d1SRudolf Cornelissen temp &= ~0x40; 26008705d96Sshatty } 261ff50d0d1SRudolf Cornelissen else 262ff50d0d1SRudolf Cornelissen { 263ff50d0d1SRudolf Cornelissen LOG(2,("H:neg ")); 264ff50d0d1SRudolf Cornelissen temp |= 0x40; 265ff50d0d1SRudolf Cornelissen } 266ff50d0d1SRudolf Cornelissen if (target.timing.flags & B_POSITIVE_VSYNC) 267ff50d0d1SRudolf Cornelissen { 268ff50d0d1SRudolf Cornelissen LOG(2,("V:pos ")); 269ff50d0d1SRudolf Cornelissen temp &= ~0x80; 270ff50d0d1SRudolf Cornelissen } 271ff50d0d1SRudolf Cornelissen else 272ff50d0d1SRudolf Cornelissen { 273ff50d0d1SRudolf Cornelissen LOG(2,("V:neg ")); 274ff50d0d1SRudolf Cornelissen temp |= 0x80; 275ff50d0d1SRudolf Cornelissen } 276255e5021SRudolf Cornelissen NV_REG8(NV8_MISCW) = temp; 277ff50d0d1SRudolf Cornelissen 278255e5021SRudolf Cornelissen LOG(2,(", MISC reg readback: $%02x\n", NV_REG8(NV8_MISCR))); 279ff50d0d1SRudolf Cornelissen } 280ff50d0d1SRudolf Cornelissen 281ff50d0d1SRudolf Cornelissen /* always disable interlaced operation */ 282255e5021SRudolf Cornelissen /* (interlace is supported on upto and including NV10, NV15, and NV30 and up) */ 283ff50d0d1SRudolf Cornelissen CRTC2W(INTERLACE, 0xff); 28408705d96Sshatty 285bc9c6041SRudolf Cornelissen /* disable CRTC slaved mode unless a panel is in use */ 286bc9c6041SRudolf Cornelissen // fixme: this kills TVout when it was in use... 287bc9c6041SRudolf Cornelissen if (!si->ps.tmds2_active) CRTC2W(PIXEL, (CRTC2R(PIXEL) & 0x7f)); 288bc9c6041SRudolf Cornelissen 2891e37a9acSRudolf Cornelissen /* setup flatpanel if connected and active */ 290a16d55ddSRudolf Cornelissen if (si->ps.tmds2_active) 291a16d55ddSRudolf Cornelissen { 292a16d55ddSRudolf Cornelissen uint32 iscale_x, iscale_y; 293a16d55ddSRudolf Cornelissen 294a973fe9eSRudolf Cornelissen /* calculate inverse scaling factors used by hardware in 20.12 format */ 2950fccffc2SRudolf Cornelissen iscale_x = (((1 << 12) * target.timing.h_display) / si->ps.p2_timing.h_display); 2960fccffc2SRudolf Cornelissen iscale_y = (((1 << 12) * target.timing.v_display) / si->ps.p2_timing.v_display); 2971e37a9acSRudolf Cornelissen 2981e37a9acSRudolf Cornelissen /* unblock flatpanel timing programming (or something like that..) */ 2991e37a9acSRudolf Cornelissen CRTC2W(FP_HTIMING, 0); 3001e37a9acSRudolf Cornelissen CRTC2W(FP_VTIMING, 0); 301e6708074SRudolf Cornelissen LOG(2,("CRTC2: FP_HTIMING reg readback: $%02x\n", CRTC2R(FP_HTIMING))); 302e6708074SRudolf Cornelissen LOG(2,("CRTC2: FP_VTIMING reg readback: $%02x\n", CRTC2R(FP_VTIMING))); 3031e37a9acSRudolf Cornelissen 304a973fe9eSRudolf Cornelissen /* enable full width visibility on flatpanel */ 305a973fe9eSRudolf Cornelissen DAC2W(FP_HVALID_S, 0); 3060fccffc2SRudolf Cornelissen DAC2W(FP_HVALID_E, (si->ps.p2_timing.h_display - 1)); 307a973fe9eSRudolf Cornelissen /* enable full height visibility on flatpanel */ 308a973fe9eSRudolf Cornelissen DAC2W(FP_VVALID_S, 0); 3090fccffc2SRudolf Cornelissen DAC2W(FP_VVALID_E, (si->ps.p2_timing.v_display - 1)); 310a973fe9eSRudolf Cornelissen 3114709c2c8SRudolf Cornelissen /* nVidia cards support upscaling except on ??? */ 3124709c2c8SRudolf Cornelissen /* NV11 cards can upscale after all! */ 313e6708074SRudolf Cornelissen if (0)//si->ps.card_type == NV11) 3141e37a9acSRudolf Cornelissen { 3151e37a9acSRudolf Cornelissen /* disable last fetched line limiting */ 3161e37a9acSRudolf Cornelissen DAC2W(FP_DEBUG2, 0x00000000); 317c567e072SRudolf Cornelissen /* inform panel to scale if needed */ 318c567e072SRudolf Cornelissen if ((iscale_x != (1 << 12)) || (iscale_y != (1 << 12))) 319c567e072SRudolf Cornelissen { 320c567e072SRudolf Cornelissen LOG(2,("CRTC2: DFP needs to do scaling\n")); 3211e37a9acSRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) | 0x00000100)); 3221e37a9acSRudolf Cornelissen } 3231e37a9acSRudolf Cornelissen else 3241e37a9acSRudolf Cornelissen { 325c567e072SRudolf Cornelissen LOG(2,("CRTC2: no scaling for DFP needed\n")); 326c567e072SRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) & 0xfffffeff)); 327c567e072SRudolf Cornelissen } 328c567e072SRudolf Cornelissen } 329c567e072SRudolf Cornelissen else 330c567e072SRudolf Cornelissen { 331a973fe9eSRudolf Cornelissen float dm_aspect; 332a973fe9eSRudolf Cornelissen 333c567e072SRudolf Cornelissen LOG(2,("CRTC2: GPU scales for DFP if needed\n")); 3341e37a9acSRudolf Cornelissen 335a973fe9eSRudolf Cornelissen /* calculate display mode aspect */ 336a973fe9eSRudolf Cornelissen dm_aspect = (target.timing.h_display / ((float)target.timing.v_display)); 337a973fe9eSRudolf Cornelissen 338a16d55ddSRudolf Cornelissen /* limit last fetched line if vertical scaling is done */ 3391e37a9acSRudolf Cornelissen if (iscale_y != (1 << 12)) 340a16d55ddSRudolf Cornelissen DAC2W(FP_DEBUG2, ((1 << 28) | ((target.timing.v_display - 1) << 16))); 341a16d55ddSRudolf Cornelissen else 342a16d55ddSRudolf Cornelissen DAC2W(FP_DEBUG2, 0x00000000); 3431e37a9acSRudolf Cornelissen 3441e37a9acSRudolf Cornelissen /* inform panel not to scale */ 3451e37a9acSRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) & 0xfffffeff)); 346c65998faSRudolf Cornelissen 347c65998faSRudolf Cornelissen /* GPU scaling is automatically setup by hardware, so only modify this 348c65998faSRudolf Cornelissen * scalingfactor for non 4:3 (1.33) aspect panels; 349c65998faSRudolf Cornelissen * let's consider 1280x1024 1:33 aspect (it's 1.25 aspect actually!) */ 350c65998faSRudolf Cornelissen 351a973fe9eSRudolf Cornelissen /* correct for widescreen panels relative to mode... 352a973fe9eSRudolf Cornelissen * (so if panel is more widescreen than mode being set) */ 353a973fe9eSRudolf Cornelissen /* BTW: known widescreen panels: 354c65998faSRudolf Cornelissen * 1280 x 800 (1.60), 355c65998faSRudolf Cornelissen * 1440 x 900 (1.60), 356b97caf33SRudolf Cornelissen * 1680 x 1050 (1.60), 357b97caf33SRudolf Cornelissen * 1920 x 1200 (1.60). */ 358c65998faSRudolf Cornelissen /* known 4:3 aspect non-standard resolution panels: 359c65998faSRudolf Cornelissen * 1400 x 1050 (1.33). */ 360a973fe9eSRudolf Cornelissen /* NOTE: 361a973fe9eSRudolf Cornelissen * allow 0.10 difference so 1280x1024 panels will be used fullscreen! */ 362a973fe9eSRudolf Cornelissen if ((iscale_x != (1 << 12)) && (si->ps.panel2_aspect > (dm_aspect + 0.10))) 363c65998faSRudolf Cornelissen { 364a973fe9eSRudolf Cornelissen uint16 diff; 365a973fe9eSRudolf Cornelissen 366a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: (relative) widescreen panel: tuning horizontal scaling\n")); 367a973fe9eSRudolf Cornelissen 368a973fe9eSRudolf Cornelissen /* X-scaling should be the same as Y-scaling */ 369a973fe9eSRudolf Cornelissen iscale_x = iscale_y; 370c65998faSRudolf Cornelissen /* enable testmode (b12) and program new X-scaling factor */ 371c65998faSRudolf Cornelissen DAC2W(FP_DEBUG1, (((iscale_x >> 1) & 0x00000fff) | (1 << 12))); 372a973fe9eSRudolf Cornelissen /* center/cut-off left and right side of screen */ 3730fccffc2SRudolf Cornelissen diff = ((si->ps.p2_timing.h_display - 374a973fe9eSRudolf Cornelissen (target.timing.h_display * ((1 << 12) / ((float)iscale_x)))) 375a973fe9eSRudolf Cornelissen / 2); 376a973fe9eSRudolf Cornelissen DAC2W(FP_HVALID_S, diff); 3770fccffc2SRudolf Cornelissen DAC2W(FP_HVALID_E, ((si->ps.p2_timing.h_display - diff) - 1)); 378c65998faSRudolf Cornelissen } 379c65998faSRudolf Cornelissen /* correct for portrait panels... */ 380a973fe9eSRudolf Cornelissen /* NOTE: 381a973fe9eSRudolf Cornelissen * allow 0.10 difference so 1280x1024 panels will be used fullscreen! */ 382a973fe9eSRudolf Cornelissen if ((iscale_y != (1 << 12)) && (si->ps.panel2_aspect < (dm_aspect - 0.10))) 383c65998faSRudolf Cornelissen { 384a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: (relative) portrait panel: should tune vertical scaling\n")); 385a973fe9eSRudolf Cornelissen /* fixme: implement if this kind of portrait panels exist on nVidia... */ 386c65998faSRudolf Cornelissen } 3871e37a9acSRudolf Cornelissen } 3881e37a9acSRudolf Cornelissen 3891e37a9acSRudolf Cornelissen /* do some logging.. */ 390a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_HVALID_S reg readback: $%08x\n", DAC2R(FP_HVALID_S))); 391a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_HVALID_E reg readback: $%08x\n", DAC2R(FP_HVALID_E))); 392a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_VVALID_S reg readback: $%08x\n", DAC2R(FP_VVALID_S))); 393a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_VVALID_E reg readback: $%08x\n", DAC2R(FP_VVALID_E))); 3941e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG0 reg readback: $%08x\n", DAC2R(FP_DEBUG0))); 3951e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG1 reg readback: $%08x\n", DAC2R(FP_DEBUG1))); 3961e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG2 reg readback: $%08x\n", DAC2R(FP_DEBUG2))); 3971e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG3 reg readback: $%08x\n", DAC2R(FP_DEBUG3))); 3981e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_TG_CTRL reg readback: $%08x\n", DAC2R(FP_TG_CTRL))); 399a16d55ddSRudolf Cornelissen } 400a16d55ddSRudolf Cornelissen 40108705d96Sshatty return B_OK; 40208705d96Sshatty } 40308705d96Sshatty 404ff50d0d1SRudolf Cornelissen status_t nv_crtc2_depth(int mode) 40508705d96Sshatty { 406ff50d0d1SRudolf Cornelissen uint8 viddelay = 0; 407ff50d0d1SRudolf Cornelissen uint32 genctrl = 0; 408ff50d0d1SRudolf Cornelissen 409ff50d0d1SRudolf Cornelissen /* set VCLK scaling */ 41008705d96Sshatty switch(mode) 41108705d96Sshatty { 412ff50d0d1SRudolf Cornelissen case BPP8: 413ff50d0d1SRudolf Cornelissen viddelay = 0x01; 414ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 reset: 'direct mode' */ 415ff50d0d1SRudolf Cornelissen genctrl = 0x00101100; 41608705d96Sshatty break; 417ff50d0d1SRudolf Cornelissen case BPP15: 418ff50d0d1SRudolf Cornelissen viddelay = 0x02; 419ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 420ff50d0d1SRudolf Cornelissen genctrl = 0x00100130; 421ff50d0d1SRudolf Cornelissen break; 422ff50d0d1SRudolf Cornelissen case BPP16: 423ff50d0d1SRudolf Cornelissen viddelay = 0x02; 424ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 425ff50d0d1SRudolf Cornelissen genctrl = 0x00101130; 426ff50d0d1SRudolf Cornelissen break; 427ff50d0d1SRudolf Cornelissen case BPP24: 428ff50d0d1SRudolf Cornelissen viddelay = 0x03; 429ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 430ff50d0d1SRudolf Cornelissen genctrl = 0x00100130; 431ff50d0d1SRudolf Cornelissen break; 432ff50d0d1SRudolf Cornelissen case BPP32: 433ff50d0d1SRudolf Cornelissen viddelay = 0x03; 434ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 435ff50d0d1SRudolf Cornelissen genctrl = 0x00101130; 43608705d96Sshatty break; 43708705d96Sshatty } 43864c14e7eSRudolf Cornelissen /* enable access to secondary head */ 43964c14e7eSRudolf Cornelissen set_crtc_owner(1); 440255e5021SRudolf Cornelissen 441ff50d0d1SRudolf Cornelissen CRTC2W(PIXEL, ((CRTC2R(PIXEL) & 0xfc) | viddelay)); 442ff50d0d1SRudolf Cornelissen DAC2W(GENCTRL, genctrl); 44308705d96Sshatty 44408705d96Sshatty return B_OK; 44508705d96Sshatty } 44608705d96Sshatty 447ff50d0d1SRudolf Cornelissen status_t nv_crtc2_dpms(bool display, bool h, bool v) 44808705d96Sshatty { 449d97178c9SRudolf Cornelissen uint8 temp; 450ff50d0d1SRudolf Cornelissen 451ff50d0d1SRudolf Cornelissen LOG(4,("CRTC2: setting DPMS: ")); 452ff50d0d1SRudolf Cornelissen 45364c14e7eSRudolf Cornelissen /* enable access to secondary head */ 45464c14e7eSRudolf Cornelissen set_crtc_owner(1); 455255e5021SRudolf Cornelissen 456ff50d0d1SRudolf Cornelissen /* start synchronous reset: required before turning screen off! */ 457d97178c9SRudolf Cornelissen SEQW(RESET, 0x01); 458ff50d0d1SRudolf Cornelissen 459ff50d0d1SRudolf Cornelissen /* turn screen off */ 460d97178c9SRudolf Cornelissen temp = SEQR(CLKMODE); 461ff50d0d1SRudolf Cornelissen if (display) 46208705d96Sshatty { 463d97178c9SRudolf Cornelissen SEQW(CLKMODE, (temp & ~0x20)); 464ff50d0d1SRudolf Cornelissen 465ff50d0d1SRudolf Cornelissen /* end synchronous reset if display should be enabled */ 466d97178c9SRudolf Cornelissen SEQW(RESET, 0x03); 467ff50d0d1SRudolf Cornelissen 46822ffe8b5SRudolf Cornelissen //'safe mode' test! feedback needed with this 'setting'! 46922ffe8b5SRudolf Cornelissen if (0)//si->ps.tmds2_active) 470b4f28c26SRudolf Cornelissen { 471b4f28c26SRudolf Cornelissen /* powerup both LVDS (laptop panellink) and TMDS (DVI panellink) 472b4f28c26SRudolf Cornelissen * internal transmitters... */ 4738addb7c3SRudolf Cornelissen /* note: 4748addb7c3SRudolf Cornelissen * the powerbits in this register are hardwired to the DVI connectors, 4758addb7c3SRudolf Cornelissen * instead of to the DACs! (confirmed NV34) */ 4768addb7c3SRudolf Cornelissen //fixme... 477b4f28c26SRudolf Cornelissen DAC2W(FP_DEBUG0, (DAC2R(FP_DEBUG0) & 0xcfffffff)); 478b4f28c26SRudolf Cornelissen /* ... and powerup external TMDS transmitter if it exists */ 479ed391abaSRudolf Cornelissen /* (confirmed OK on NV28 and NV34) */ 480ed391abaSRudolf Cornelissen CRTC2W(0x59, (CRTC2R(0x59) | 0x01)); 481b4f28c26SRudolf Cornelissen } 4824709c2c8SRudolf Cornelissen 483ff50d0d1SRudolf Cornelissen LOG(4,("display on, ")); 48408705d96Sshatty } 48508705d96Sshatty else 48608705d96Sshatty { 487d97178c9SRudolf Cornelissen SEQW(CLKMODE, (temp | 0x20)); 488ff50d0d1SRudolf Cornelissen 48922ffe8b5SRudolf Cornelissen //'safe mode' test! feedback needed with this 'setting'! 49022ffe8b5SRudolf Cornelissen if (0)//si->ps.tmds2_active) 491b4f28c26SRudolf Cornelissen { 492b4f28c26SRudolf Cornelissen /* powerdown both LVDS (laptop panellink) and TMDS (DVI panellink) 493b4f28c26SRudolf Cornelissen * internal transmitters... */ 4948addb7c3SRudolf Cornelissen /* note: 4958addb7c3SRudolf Cornelissen * the powerbits in this register are hardwired to the DVI connectors, 4968addb7c3SRudolf Cornelissen * instead of to the DACs! (confirmed NV34) */ 4978addb7c3SRudolf Cornelissen //fixme... 498b4f28c26SRudolf Cornelissen DAC2W(FP_DEBUG0, (DAC2R(FP_DEBUG0) | 0x30000000)); 499b4f28c26SRudolf Cornelissen /* ... and powerdown external TMDS transmitter if it exists */ 500ed391abaSRudolf Cornelissen /* (confirmed OK on NV28 and NV34) */ 501ed391abaSRudolf Cornelissen CRTC2W(0x59, (CRTC2R(0x59) & 0xfe)); 502b4f28c26SRudolf Cornelissen } 5034709c2c8SRudolf Cornelissen 504ff50d0d1SRudolf Cornelissen LOG(4,("display off, ")); 50508705d96Sshatty } 50608705d96Sshatty 507ff50d0d1SRudolf Cornelissen if (h) 50808705d96Sshatty { 509ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0x7f)); 510ff50d0d1SRudolf Cornelissen LOG(4,("hsync enabled, ")); 511ff50d0d1SRudolf Cornelissen } 512ff50d0d1SRudolf Cornelissen else 513ff50d0d1SRudolf Cornelissen { 514ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x80)); 515ff50d0d1SRudolf Cornelissen LOG(4,("hsync disabled, ")); 516ff50d0d1SRudolf Cornelissen } 517ff50d0d1SRudolf Cornelissen if (v) 518ff50d0d1SRudolf Cornelissen { 519ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0xbf)); 520ff50d0d1SRudolf Cornelissen LOG(4,("vsync enabled\n")); 521ff50d0d1SRudolf Cornelissen } 522ff50d0d1SRudolf Cornelissen else 523ff50d0d1SRudolf Cornelissen { 524ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x40)); 525ff50d0d1SRudolf Cornelissen LOG(4,("vsync disabled\n")); 526ff50d0d1SRudolf Cornelissen } 52708705d96Sshatty 52808705d96Sshatty return B_OK; 52908705d96Sshatty } 53008705d96Sshatty 531ff50d0d1SRudolf Cornelissen status_t nv_crtc2_dpms_fetch(bool *display, bool *h, bool *v) 532ff50d0d1SRudolf Cornelissen { 53364c14e7eSRudolf Cornelissen /* enable access to secondary head */ 53464c14e7eSRudolf Cornelissen set_crtc_owner(1); 535255e5021SRudolf Cornelissen 536d97178c9SRudolf Cornelissen *display = !(SEQR(CLKMODE) & 0x20); 537ff50d0d1SRudolf Cornelissen *h = !(CRTC2R(REPAINT1) & 0x80); 538ff50d0d1SRudolf Cornelissen *v = !(CRTC2R(REPAINT1) & 0x40); 539ff50d0d1SRudolf Cornelissen 540ff50d0d1SRudolf Cornelissen LOG(4,("CTRC2: fetched DPMS state: ")); 54117f2ecd6SRudolf Cornelissen if (*display) LOG(4,("display on, ")); 542ff50d0d1SRudolf Cornelissen else LOG(4,("display off, ")); 54317f2ecd6SRudolf Cornelissen if (*h) LOG(4,("hsync enabled, ")); 544ff50d0d1SRudolf Cornelissen else LOG(4,("hsync disabled, ")); 54517f2ecd6SRudolf Cornelissen if (*v) LOG(4,("vsync enabled\n")); 546ff50d0d1SRudolf Cornelissen else LOG(4,("vsync disabled\n")); 547ff50d0d1SRudolf Cornelissen 548ff50d0d1SRudolf Cornelissen return B_OK; 549ff50d0d1SRudolf Cornelissen } 550ff50d0d1SRudolf Cornelissen 551ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_display_pitch() 55208705d96Sshatty { 55308705d96Sshatty uint32 offset; 55408705d96Sshatty 55508705d96Sshatty LOG(4,("CRTC2: setting card pitch (offset between lines)\n")); 55608705d96Sshatty 55708705d96Sshatty /* figure out offset value hardware needs */ 558ff50d0d1SRudolf Cornelissen offset = si->fbc.bytes_per_row / 8; 55908705d96Sshatty 560ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: offset register set to: $%04x\n", offset)); 56108705d96Sshatty 56264c14e7eSRudolf Cornelissen /* enable access to secondary head */ 56364c14e7eSRudolf Cornelissen set_crtc_owner(1); 564255e5021SRudolf Cornelissen 565b4bdc2b6SRudolf Cornelissen /* program the card */ 566ff50d0d1SRudolf Cornelissen CRTC2W(PITCHL, (offset & 0x00ff)); 567ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT0, ((CRTC2R(REPAINT0) & 0x1f) | ((offset & 0x0700) >> 3))); 568ff50d0d1SRudolf Cornelissen 56908705d96Sshatty return B_OK; 57008705d96Sshatty } 57108705d96Sshatty 572ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_display_start(uint32 startadd,uint8 bpp) 57308705d96Sshatty { 574e0dd08e8SRudolf Cornelissen uint32 timeout = 0; 57508705d96Sshatty 576ff50d0d1SRudolf Cornelissen LOG(4,("CRTC2: setting card RAM to be displayed bpp %d\n", bpp)); 57708705d96Sshatty 578ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: startadd: $%08x\n", startadd)); 579ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: frameRAM: $%08x\n", si->framebuffer)); 580ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: framebuffer: $%08x\n", si->fbc.frame_buffer)); 581ff50d0d1SRudolf Cornelissen 582e0dd08e8SRudolf Cornelissen /* we might have no retraces during setmode! */ 583e0dd08e8SRudolf Cornelissen /* wait 25mS max. for retrace to occur (refresh > 40Hz) */ 584e0dd08e8SRudolf Cornelissen while (((NV_REG32(NV32_RASTER2) & 0x000007ff) < si->dm.timing.v_display) && 585e0dd08e8SRudolf Cornelissen (timeout < (25000/10))) 586e0dd08e8SRudolf Cornelissen { 587e0dd08e8SRudolf Cornelissen /* don't snooze much longer or retrace might get missed! */ 588e0dd08e8SRudolf Cornelissen snooze(10); 589e0dd08e8SRudolf Cornelissen timeout++; 590e0dd08e8SRudolf Cornelissen } 591ff50d0d1SRudolf Cornelissen 59264c14e7eSRudolf Cornelissen /* enable access to secondary head */ 59364c14e7eSRudolf Cornelissen set_crtc_owner(1); 594255e5021SRudolf Cornelissen 595ff50d0d1SRudolf Cornelissen /* upto 4Gb RAM adressing: must be used on NV10 and later! */ 596ff50d0d1SRudolf Cornelissen /* NOTE: 597ff50d0d1SRudolf Cornelissen * While this register also exists on pre-NV10 cards, it will 598ff50d0d1SRudolf Cornelissen * wrap-around at 16Mb boundaries!! */ 599ff50d0d1SRudolf Cornelissen 600ff50d0d1SRudolf Cornelissen /* 30bit adress in 32bit words */ 601ff50d0d1SRudolf Cornelissen NV_REG32(NV32_NV10FB2STADD32) = (startadd & 0xfffffffc); 602ff50d0d1SRudolf Cornelissen 603bc9d4aceSRudolf Cornelissen /* set byte adress: (b0 - 1) */ 604e0dd08e8SRudolf Cornelissen ATB2W(HORPIXPAN, ((startadd & 0x00000003) << 1)); 605ff50d0d1SRudolf Cornelissen 606ff50d0d1SRudolf Cornelissen return B_OK; 607ff50d0d1SRudolf Cornelissen } 608ff50d0d1SRudolf Cornelissen 609ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_init() 610ff50d0d1SRudolf Cornelissen { 611ff50d0d1SRudolf Cornelissen int i; 612ff50d0d1SRudolf Cornelissen uint32 * fb; 613ff50d0d1SRudolf Cornelissen /* cursor bitmap will be stored at the start of the framebuffer */ 614ff50d0d1SRudolf Cornelissen const uint32 curadd = 0; 615ff50d0d1SRudolf Cornelissen 61664c14e7eSRudolf Cornelissen /* enable access to secondary head */ 61764c14e7eSRudolf Cornelissen set_crtc_owner(1); 618255e5021SRudolf Cornelissen 619ff50d0d1SRudolf Cornelissen /* set cursor bitmap adress ... */ 620255e5021SRudolf Cornelissen if (si->ps.laptop) 621ff50d0d1SRudolf Cornelissen { 622ff50d0d1SRudolf Cornelissen /* must be used this way on pre-NV10 and on all 'Go' cards! */ 623ff50d0d1SRudolf Cornelissen 624ff50d0d1SRudolf Cornelissen /* cursorbitmap must start on 2Kbyte boundary: */ 625ff50d0d1SRudolf Cornelissen /* set adress bit11-16, and set 'no doublescan' (registerbit 1 = 0) */ 626ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, ((curadd & 0x0001f800) >> 9)); 627ff50d0d1SRudolf Cornelissen /* set adress bit17-23, and set graphics mode cursor(?) (registerbit 7 = 1) */ 628ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL1, (((curadd & 0x00fe0000) >> 17) | 0x80)); 629ff50d0d1SRudolf Cornelissen /* set adress bit24-31 */ 630ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL2, ((curadd & 0xff000000) >> 24)); 63108705d96Sshatty } 63208705d96Sshatty else 63308705d96Sshatty { 634ff50d0d1SRudolf Cornelissen /* upto 4Gb RAM adressing: 635ff50d0d1SRudolf Cornelissen * can be used on NV10 and later (except for 'Go' cards)! */ 636ff50d0d1SRudolf Cornelissen /* NOTE: 637ff50d0d1SRudolf Cornelissen * This register does not exist on pre-NV10 and 'Go' cards. */ 638ff50d0d1SRudolf Cornelissen 639ff50d0d1SRudolf Cornelissen /* cursorbitmap must still start on 2Kbyte boundary: */ 640ff50d0d1SRudolf Cornelissen NV_REG32(NV32_NV10CUR2ADD32) = (curadd & 0xfffff800); 64108705d96Sshatty } 64208705d96Sshatty 643ff50d0d1SRudolf Cornelissen /* set cursor colour: not needed because of direct nature of cursor bitmap. */ 644ff50d0d1SRudolf Cornelissen 645ff50d0d1SRudolf Cornelissen /*clear cursor*/ 646ff50d0d1SRudolf Cornelissen fb = (uint32 *) si->framebuffer + curadd; 647ff50d0d1SRudolf Cornelissen for (i=0;i<(2048/4);i++) 648ff50d0d1SRudolf Cornelissen { 649ff50d0d1SRudolf Cornelissen fb[i]=0; 650ff50d0d1SRudolf Cornelissen } 651ff50d0d1SRudolf Cornelissen 652ff50d0d1SRudolf Cornelissen /* select 32x32 pixel, 16bit color cursorbitmap, no doublescan */ 653ff50d0d1SRudolf Cornelissen NV_REG32(NV32_2CURCONF) = 0x02000100; 654ff50d0d1SRudolf Cornelissen 655ff50d0d1SRudolf Cornelissen /* activate hardware cursor */ 656255e5021SRudolf Cornelissen nv_crtc2_cursor_show(); 657ff50d0d1SRudolf Cornelissen 658ff50d0d1SRudolf Cornelissen return B_OK; 659ff50d0d1SRudolf Cornelissen } 660ff50d0d1SRudolf Cornelissen 661ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_show() 662ff50d0d1SRudolf Cornelissen { 663255e5021SRudolf Cornelissen LOG(4,("CRTC2: enabling cursor\n")); 664255e5021SRudolf Cornelissen 66564c14e7eSRudolf Cornelissen /* enable access to secondary head */ 66664c14e7eSRudolf Cornelissen set_crtc_owner(1); 667255e5021SRudolf Cornelissen 668ff50d0d1SRudolf Cornelissen /* b0 = 1 enables cursor */ 669ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, (CRTC2R(CURCTL0) | 0x01)); 670ff50d0d1SRudolf Cornelissen 671ff50d0d1SRudolf Cornelissen return B_OK; 672ff50d0d1SRudolf Cornelissen } 673ff50d0d1SRudolf Cornelissen 674ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_hide() 675ff50d0d1SRudolf Cornelissen { 676255e5021SRudolf Cornelissen LOG(4,("CRTC2: disabling cursor\n")); 677255e5021SRudolf Cornelissen 67864c14e7eSRudolf Cornelissen /* enable access to secondary head */ 67964c14e7eSRudolf Cornelissen set_crtc_owner(1); 680255e5021SRudolf Cornelissen 681ff50d0d1SRudolf Cornelissen /* b0 = 0 disables cursor */ 682ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, (CRTC2R(CURCTL0) & 0xfe)); 683ff50d0d1SRudolf Cornelissen 684ff50d0d1SRudolf Cornelissen return B_OK; 685ff50d0d1SRudolf Cornelissen } 686ff50d0d1SRudolf Cornelissen 687ff50d0d1SRudolf Cornelissen /*set up cursor shape*/ 688ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_define(uint8* andMask,uint8* xorMask) 689ff50d0d1SRudolf Cornelissen { 690ff50d0d1SRudolf Cornelissen int x, y; 691ff50d0d1SRudolf Cornelissen uint8 b; 692ff50d0d1SRudolf Cornelissen uint16 *cursor; 693ff50d0d1SRudolf Cornelissen uint16 pixel; 694ff50d0d1SRudolf Cornelissen 695ff50d0d1SRudolf Cornelissen /* get a pointer to the cursor */ 696ff50d0d1SRudolf Cornelissen cursor = (uint16*) si->framebuffer; 697ff50d0d1SRudolf Cornelissen 698ff50d0d1SRudolf Cornelissen /* draw the cursor */ 699ff50d0d1SRudolf Cornelissen /* (Nvidia cards have a RGB15 direct color cursor bitmap, bit #16 is transparancy) */ 700ff50d0d1SRudolf Cornelissen for (y = 0; y < 16; y++) 701ff50d0d1SRudolf Cornelissen { 702ff50d0d1SRudolf Cornelissen b = 0x80; 703ff50d0d1SRudolf Cornelissen for (x = 0; x < 8; x++) 704ff50d0d1SRudolf Cornelissen { 705ff50d0d1SRudolf Cornelissen /* preset transparant */ 706ff50d0d1SRudolf Cornelissen pixel = 0x0000; 707ff50d0d1SRudolf Cornelissen /* set white if requested */ 708ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (!(*xorMask & b))) pixel = 0xffff; 709ff50d0d1SRudolf Cornelissen /* set black if requested */ 710ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (*xorMask & b)) pixel = 0x8000; 711ff50d0d1SRudolf Cornelissen /* set invert if requested */ 712ff50d0d1SRudolf Cornelissen if ( (*andMask & b) && (*xorMask & b)) pixel = 0x7fff; 713ff50d0d1SRudolf Cornelissen /* place the pixel in the bitmap */ 714ff50d0d1SRudolf Cornelissen cursor[x + (y * 32)] = pixel; 715ff50d0d1SRudolf Cornelissen b >>= 1; 716ff50d0d1SRudolf Cornelissen } 717ff50d0d1SRudolf Cornelissen xorMask++; 718ff50d0d1SRudolf Cornelissen andMask++; 719ff50d0d1SRudolf Cornelissen b = 0x80; 720ff50d0d1SRudolf Cornelissen for (; x < 16; x++) 721ff50d0d1SRudolf Cornelissen { 722ff50d0d1SRudolf Cornelissen /* preset transparant */ 723ff50d0d1SRudolf Cornelissen pixel = 0x0000; 724ff50d0d1SRudolf Cornelissen /* set white if requested */ 725ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (!(*xorMask & b))) pixel = 0xffff; 726ff50d0d1SRudolf Cornelissen /* set black if requested */ 727ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (*xorMask & b)) pixel = 0x8000; 728ff50d0d1SRudolf Cornelissen /* set invert if requested */ 729ff50d0d1SRudolf Cornelissen if ( (*andMask & b) && (*xorMask & b)) pixel = 0x7fff; 730ff50d0d1SRudolf Cornelissen /* place the pixel in the bitmap */ 731ff50d0d1SRudolf Cornelissen cursor[x + (y * 32)] = pixel; 732ff50d0d1SRudolf Cornelissen b >>= 1; 733ff50d0d1SRudolf Cornelissen } 734ff50d0d1SRudolf Cornelissen xorMask++; 735ff50d0d1SRudolf Cornelissen andMask++; 736ff50d0d1SRudolf Cornelissen } 737ff50d0d1SRudolf Cornelissen 738ff50d0d1SRudolf Cornelissen return B_OK; 739ff50d0d1SRudolf Cornelissen } 740ff50d0d1SRudolf Cornelissen 741ff50d0d1SRudolf Cornelissen /* position the cursor */ 742ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_position(uint16 x, uint16 y) 743ff50d0d1SRudolf Cornelissen { 744ff50d0d1SRudolf Cornelissen uint16 yhigh; 745ff50d0d1SRudolf Cornelissen 746ff50d0d1SRudolf Cornelissen /* make sure we are beyond the first line of the cursorbitmap being drawn during 747ff50d0d1SRudolf Cornelissen * updating the position to prevent distortions: no double buffering feature */ 748ff50d0d1SRudolf Cornelissen /* Note: 749ff50d0d1SRudolf Cornelissen * we need to return as quick as possible or some apps will exhibit lagging.. */ 750ff50d0d1SRudolf Cornelissen 751ff50d0d1SRudolf Cornelissen /* read the old cursor Y position */ 752ff50d0d1SRudolf Cornelissen yhigh = ((DAC2R(CURPOS) & 0x0fff0000) >> 16); 753ff50d0d1SRudolf Cornelissen /* make sure we will wait until we are below both the old and new Y position: 754ff50d0d1SRudolf Cornelissen * visible cursorbitmap drawing needs to be done at least... */ 755ff50d0d1SRudolf Cornelissen if (y > yhigh) yhigh = y; 756ff50d0d1SRudolf Cornelissen 757ff50d0d1SRudolf Cornelissen if (yhigh < (si->dm.timing.v_display - 16)) 758ff50d0d1SRudolf Cornelissen { 759ff50d0d1SRudolf Cornelissen /* we have vertical lines below old and new cursorposition to spare. So we 760ff50d0d1SRudolf Cornelissen * update the cursor postion 'mid-screen', but below that area. */ 761ff50d0d1SRudolf Cornelissen while (((uint16)(NV_REG32(NV32_RASTER2) & 0x000007ff)) < (yhigh + 16)) 762ff50d0d1SRudolf Cornelissen { 763ff50d0d1SRudolf Cornelissen snooze(10); 764ff50d0d1SRudolf Cornelissen } 765ff50d0d1SRudolf Cornelissen } 766ff50d0d1SRudolf Cornelissen else 767ff50d0d1SRudolf Cornelissen { 768ff50d0d1SRudolf Cornelissen /* no room to spare, just wait for retrace (is relatively slow) */ 769ff50d0d1SRudolf Cornelissen while ((NV_REG32(NV32_RASTER2) & 0x000007ff) < si->dm.timing.v_display) 770ff50d0d1SRudolf Cornelissen { 771ff50d0d1SRudolf Cornelissen /* don't snooze much longer or retrace might get missed! */ 772ff50d0d1SRudolf Cornelissen snooze(10); 773ff50d0d1SRudolf Cornelissen } 774ff50d0d1SRudolf Cornelissen } 775ff50d0d1SRudolf Cornelissen 776ff50d0d1SRudolf Cornelissen /* update cursorposition */ 777ff50d0d1SRudolf Cornelissen DAC2W(CURPOS, ((x & 0x0fff) | ((y & 0x0fff) << 16))); 778ff50d0d1SRudolf Cornelissen 77908705d96Sshatty return B_OK; 78008705d96Sshatty } 781