1ff50d0d1SRudolf Cornelissen /* second CTRC functionality for GeForce cards */ 2ff50d0d1SRudolf Cornelissen /* Author: 3a658603aSRudolf Cornelissen Rudolf Cornelissen 11/2002-11/2005 408705d96Sshatty */ 508705d96Sshatty 608705d96Sshatty #define MODULE_BIT 0x00020000 708705d96Sshatty 808705d96Sshatty #include "nv_std.h" 908705d96Sshatty 10a393eaf8SRudolf Cornelissen /* doing general fail-safe default setup here */ 11a393eaf8SRudolf Cornelissen //fixme: this is a _very_ basic setup, and it's preliminary... 12a393eaf8SRudolf Cornelissen status_t nv_crtc2_update_fifo() 13a393eaf8SRudolf Cornelissen { 14a393eaf8SRudolf Cornelissen uint8 bytes_per_pixel = 1; 15a393eaf8SRudolf Cornelissen uint32 drain; 16a393eaf8SRudolf Cornelissen 17a393eaf8SRudolf Cornelissen /* we are only using this on >>coldstarted<< cards which really need this */ 18a393eaf8SRudolf Cornelissen //fixme: re-enable or remove after general user confirmation of behaviour... 19a393eaf8SRudolf Cornelissen if (/*(si->settings.usebios) ||*/ (si->ps.card_type != NV11)) return B_OK; 20a393eaf8SRudolf Cornelissen 21d320dfafSRudolf Cornelissen /* enable access to secondary head */ 22a393eaf8SRudolf Cornelissen set_crtc_owner(1); 23a393eaf8SRudolf Cornelissen 24a393eaf8SRudolf Cornelissen /* set CRTC FIFO low watermark according to memory drain */ 25a393eaf8SRudolf Cornelissen switch(si->dm.space) 26a393eaf8SRudolf Cornelissen { 27a393eaf8SRudolf Cornelissen case B_CMAP8: 28a393eaf8SRudolf Cornelissen bytes_per_pixel = 1; 29a393eaf8SRudolf Cornelissen break; 30a393eaf8SRudolf Cornelissen case B_RGB15_LITTLE: 31a393eaf8SRudolf Cornelissen case B_RGB16_LITTLE: 32a393eaf8SRudolf Cornelissen bytes_per_pixel = 2; 33a393eaf8SRudolf Cornelissen break; 34a393eaf8SRudolf Cornelissen case B_RGB24_LITTLE: 35a393eaf8SRudolf Cornelissen bytes_per_pixel = 3; 36a393eaf8SRudolf Cornelissen break; 37a393eaf8SRudolf Cornelissen case B_RGB32_LITTLE: 38a393eaf8SRudolf Cornelissen bytes_per_pixel = 4; 39a393eaf8SRudolf Cornelissen break; 40a393eaf8SRudolf Cornelissen } 41a393eaf8SRudolf Cornelissen /* fixme: 42a393eaf8SRudolf Cornelissen * - I should probably include the refreshrate as well; 43a393eaf8SRudolf Cornelissen * - and the memory clocking speed, core clocking speed, RAM buswidth.. */ 44a393eaf8SRudolf Cornelissen drain = si->dm.timing.h_display * si->dm.timing.v_display * bytes_per_pixel; 45a393eaf8SRudolf Cornelissen 46a393eaf8SRudolf Cornelissen /* Doesn't work for other than 32bit space (yet?) */ 47a393eaf8SRudolf Cornelissen if (si->dm.space != B_RGB32_LITTLE) 48a393eaf8SRudolf Cornelissen { 49a393eaf8SRudolf Cornelissen /* BIOS defaults */ 50a393eaf8SRudolf Cornelissen CRTC2W(FIFO, 0x03); 51a393eaf8SRudolf Cornelissen CRTC2W(FIFO_LWM, 0x20); 52a393eaf8SRudolf Cornelissen LOG(4,("CRTC2: FIFO low-watermark set to $20, burst size 256 (BIOS defaults)\n")); 53a393eaf8SRudolf Cornelissen return B_OK; 54a393eaf8SRudolf Cornelissen } 55a393eaf8SRudolf Cornelissen 56a393eaf8SRudolf Cornelissen if (drain > (((uint32)1280) * 1024 * 4)) 57a393eaf8SRudolf Cornelissen { 58a393eaf8SRudolf Cornelissen /* set CRTC FIFO burst size for 'smaller' bursts */ 59a393eaf8SRudolf Cornelissen CRTC2W(FIFO, 0x01); 60a393eaf8SRudolf Cornelissen /* Instruct CRTC to fetch new data 'earlier' */ 61a393eaf8SRudolf Cornelissen CRTC2W(FIFO_LWM, 0x40); 62a393eaf8SRudolf Cornelissen LOG(4,("CRTC2: FIFO low-watermark set to $40, burst size 64\n")); 63a393eaf8SRudolf Cornelissen } 64a393eaf8SRudolf Cornelissen else 65a393eaf8SRudolf Cornelissen { 66a393eaf8SRudolf Cornelissen if (drain > (((uint32)1024) * 768 * 4)) 67a393eaf8SRudolf Cornelissen { 68a393eaf8SRudolf Cornelissen /* BIOS default */ 69a393eaf8SRudolf Cornelissen CRTC2W(FIFO, 0x02); 70a393eaf8SRudolf Cornelissen /* Instruct CRTC to fetch new data 'earlier' */ 71a393eaf8SRudolf Cornelissen CRTC2W(FIFO_LWM, 0x40); 72a393eaf8SRudolf Cornelissen LOG(4,("CRTC2: FIFO low-watermark set to $40, burst size 128\n")); 73a393eaf8SRudolf Cornelissen } 74a393eaf8SRudolf Cornelissen else 75a393eaf8SRudolf Cornelissen { 76a393eaf8SRudolf Cornelissen /* BIOS defaults */ 77a393eaf8SRudolf Cornelissen CRTC2W(FIFO, 0x03); 78a393eaf8SRudolf Cornelissen CRTC2W(FIFO_LWM, 0x20); 79a393eaf8SRudolf Cornelissen LOG(4,("CRTC2: FIFO low-watermark set to $20, burst size 256 (BIOS defaults)\n")); 80a393eaf8SRudolf Cornelissen } 81a393eaf8SRudolf Cornelissen } 82a393eaf8SRudolf Cornelissen 83a393eaf8SRudolf Cornelissen return B_OK; 84a393eaf8SRudolf Cornelissen } 85a393eaf8SRudolf Cornelissen 86ff50d0d1SRudolf Cornelissen /* Adjust passed parameters to a valid mode line */ 87ff50d0d1SRudolf Cornelissen status_t nv_crtc2_validate_timing( 88ff50d0d1SRudolf Cornelissen uint16 *hd_e,uint16 *hs_s,uint16 *hs_e,uint16 *ht, 89ff50d0d1SRudolf Cornelissen uint16 *vd_e,uint16 *vs_s,uint16 *vs_e,uint16 *vt 90ff50d0d1SRudolf Cornelissen ) 9108705d96Sshatty { 92ff50d0d1SRudolf Cornelissen /* horizontal */ 93ff50d0d1SRudolf Cornelissen /* make all parameters multiples of 8 */ 94ff50d0d1SRudolf Cornelissen *hd_e &= 0xfff8; 95ff50d0d1SRudolf Cornelissen *hs_s &= 0xfff8; 96ff50d0d1SRudolf Cornelissen *hs_e &= 0xfff8; 97ff50d0d1SRudolf Cornelissen *ht &= 0xfff8; 98ff50d0d1SRudolf Cornelissen 99ff50d0d1SRudolf Cornelissen /* confine to required number of bits, taking logic into account */ 100ff50d0d1SRudolf Cornelissen if (*hd_e > ((0x01ff - 2) << 3)) *hd_e = ((0x01ff - 2) << 3); 101ff50d0d1SRudolf Cornelissen if (*hs_s > ((0x01ff - 1) << 3)) *hs_s = ((0x01ff - 1) << 3); 102ff50d0d1SRudolf Cornelissen if (*hs_e > ( 0x01ff << 3)) *hs_e = ( 0x01ff << 3); 103ff50d0d1SRudolf Cornelissen if (*ht > ((0x01ff + 5) << 3)) *ht = ((0x01ff + 5) << 3); 104ff50d0d1SRudolf Cornelissen 105ff50d0d1SRudolf Cornelissen /* NOTE: keep horizontal timing at multiples of 8! */ 106ff50d0d1SRudolf Cornelissen /* confine to a reasonable width */ 107ff50d0d1SRudolf Cornelissen if (*hd_e < 640) *hd_e = 640; 108ff50d0d1SRudolf Cornelissen if (*hd_e > 2048) *hd_e = 2048; 109ff50d0d1SRudolf Cornelissen 110ff50d0d1SRudolf Cornelissen /* if hor. total does not leave room for a sensible sync pulse, increase it! */ 111ff50d0d1SRudolf Cornelissen if (*ht < (*hd_e + 80)) *ht = (*hd_e + 80); 112ff50d0d1SRudolf Cornelissen 1130ecea71bSRudolf Cornelissen /* if hor. total does not adhere to max. blanking pulse width, decrease it! */ 1140ecea71bSRudolf Cornelissen if (*ht > (*hd_e + 0x3f8)) *ht = (*hd_e + 0x3f8); 1150ecea71bSRudolf Cornelissen 116ff50d0d1SRudolf Cornelissen /* make sure sync pulse is not during display */ 117ff50d0d1SRudolf Cornelissen if (*hs_e > (*ht - 8)) *hs_e = (*ht - 8); 118ff50d0d1SRudolf Cornelissen if (*hs_s < (*hd_e + 8)) *hs_s = (*hd_e + 8); 119ff50d0d1SRudolf Cornelissen 120ff50d0d1SRudolf Cornelissen /* correct sync pulse if it is too long: 121ff50d0d1SRudolf Cornelissen * there are only 5 bits available to save this in the card registers! */ 122ff50d0d1SRudolf Cornelissen if (*hs_e > (*hs_s + 0xf8)) *hs_e = (*hs_s + 0xf8); 123ff50d0d1SRudolf Cornelissen 124ff50d0d1SRudolf Cornelissen /*vertical*/ 125ff50d0d1SRudolf Cornelissen /* confine to required number of bits, taking logic into account */ 126ff50d0d1SRudolf Cornelissen //fixme if needed: on GeForce cards there are 12 instead of 11 bits... 127ff50d0d1SRudolf Cornelissen if (*vd_e > (0x7ff - 2)) *vd_e = (0x7ff - 2); 128ff50d0d1SRudolf Cornelissen if (*vs_s > (0x7ff - 1)) *vs_s = (0x7ff - 1); 129ff50d0d1SRudolf Cornelissen if (*vs_e > 0x7ff ) *vs_e = 0x7ff ; 130ff50d0d1SRudolf Cornelissen if (*vt > (0x7ff + 2)) *vt = (0x7ff + 2); 131ff50d0d1SRudolf Cornelissen 132ff50d0d1SRudolf Cornelissen /* confine to a reasonable height */ 133ff50d0d1SRudolf Cornelissen if (*vd_e < 480) *vd_e = 480; 134ff50d0d1SRudolf Cornelissen if (*vd_e > 1536) *vd_e = 1536; 135ff50d0d1SRudolf Cornelissen 136ff50d0d1SRudolf Cornelissen /*if vertical total does not leave room for a sync pulse, increase it!*/ 137ff50d0d1SRudolf Cornelissen if (*vt < (*vd_e + 3)) *vt = (*vd_e + 3); 138ff50d0d1SRudolf Cornelissen 1390ecea71bSRudolf Cornelissen /* if vert. total does not adhere to max. blanking pulse width, decrease it! */ 1400ecea71bSRudolf Cornelissen if (*vt > (*vd_e + 0xff)) *vt = (*vd_e + 0xff); 1410ecea71bSRudolf Cornelissen 142ff50d0d1SRudolf Cornelissen /* make sure sync pulse is not during display */ 143ff50d0d1SRudolf Cornelissen if (*vs_e > (*vt - 1)) *vs_e = (*vt - 1); 144ff50d0d1SRudolf Cornelissen if (*vs_s < (*vd_e + 1)) *vs_s = (*vd_e + 1); 145ff50d0d1SRudolf Cornelissen 146ff50d0d1SRudolf Cornelissen /* correct sync pulse if it is too long: 147ff50d0d1SRudolf Cornelissen * there are only 4 bits available to save this in the card registers! */ 148ff50d0d1SRudolf Cornelissen if (*vs_e > (*vs_s + 0x0f)) *vs_e = (*vs_s + 0x0f); 149ff50d0d1SRudolf Cornelissen 150ff50d0d1SRudolf Cornelissen return B_OK; 151ff50d0d1SRudolf Cornelissen } 152ff50d0d1SRudolf Cornelissen 153ff50d0d1SRudolf Cornelissen /*set a mode line - inputs are in pixels*/ 154ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_timing(display_mode target) 155ff50d0d1SRudolf Cornelissen { 156ff50d0d1SRudolf Cornelissen uint8 temp; 157ff50d0d1SRudolf Cornelissen 158ff50d0d1SRudolf Cornelissen uint32 htotal; /*total horizontal total VCLKs*/ 159ff50d0d1SRudolf Cornelissen uint32 hdisp_e; /*end of horizontal display (begins at 0)*/ 160ff50d0d1SRudolf Cornelissen uint32 hsync_s; /*begin of horizontal sync pulse*/ 161ff50d0d1SRudolf Cornelissen uint32 hsync_e; /*end of horizontal sync pulse*/ 162ff50d0d1SRudolf Cornelissen uint32 hblnk_s; /*begin horizontal blanking*/ 163ff50d0d1SRudolf Cornelissen uint32 hblnk_e; /*end horizontal blanking*/ 164ff50d0d1SRudolf Cornelissen 165ff50d0d1SRudolf Cornelissen uint32 vtotal; /*total vertical total scanlines*/ 166ff50d0d1SRudolf Cornelissen uint32 vdisp_e; /*end of vertical display*/ 167ff50d0d1SRudolf Cornelissen uint32 vsync_s; /*begin of vertical sync pulse*/ 168ff50d0d1SRudolf Cornelissen uint32 vsync_e; /*end of vertical sync pulse*/ 169ff50d0d1SRudolf Cornelissen uint32 vblnk_s; /*begin vertical blanking*/ 170ff50d0d1SRudolf Cornelissen uint32 vblnk_e; /*end vertical blanking*/ 171ff50d0d1SRudolf Cornelissen 172ff50d0d1SRudolf Cornelissen uint32 linecomp; /*split screen and vdisp_e interrupt*/ 17308705d96Sshatty 17408705d96Sshatty LOG(4,("CRTC2: setting timing\n")); 17508705d96Sshatty 176c9210b6fSRudolf Cornelissen /* setup tuned internal modeline for flatpanel if connected and active */ 1772cb6fc9cSRudolf Cornelissen /* notes: 1782cb6fc9cSRudolf Cornelissen * - the CRTC modeline must end earlier than the panel modeline to keep correct 1792cb6fc9cSRudolf Cornelissen * sync going; 1802cb6fc9cSRudolf Cornelissen * - if the CRTC modeline ends too soon, pixelnoise will occur in 8 (or so) pixel 1812cb6fc9cSRudolf Cornelissen * wide horizontal stripes. This can be observed earliest on fullscreen overlay, 1822cb6fc9cSRudolf Cornelissen * and if it gets worse, also normal desktop output will suffer. The stripes 1832cb6fc9cSRudolf Cornelissen * are mainly visible at the left of the screen, over the entire screen height. */ 184c567e072SRudolf Cornelissen if (si->ps.tmds2_active) 185c567e072SRudolf Cornelissen { 186c567e072SRudolf Cornelissen LOG(2,("CRTC2: DFP active: tuning modeline\n")); 187c567e072SRudolf Cornelissen 188c567e072SRudolf Cornelissen /* horizontal timing */ 18916fc5a30SRudolf Cornelissen target.timing.h_sync_start = 190268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.h_sync_start / ((float)si->ps.p2_timing.h_display)) * 19116fc5a30SRudolf Cornelissen target.timing.h_display)) & 0xfff8; 19216fc5a30SRudolf Cornelissen 19316fc5a30SRudolf Cornelissen target.timing.h_sync_end = 194268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.h_sync_end / ((float)si->ps.p2_timing.h_display)) * 19516fc5a30SRudolf Cornelissen target.timing.h_display)) & 0xfff8; 19616fc5a30SRudolf Cornelissen 19716fc5a30SRudolf Cornelissen target.timing.h_total = 198268624c4SRudolf Cornelissen (((uint16)((si->ps.p2_timing.h_total / ((float)si->ps.p2_timing.h_display)) * 199bef5b86aSRudolf Cornelissen target.timing.h_display)) & 0xfff8) - 8; 20016fc5a30SRudolf Cornelissen 201139d62e9SRudolf Cornelissen /* in native mode the CRTC needs some extra time to keep synced correctly; 202139d62e9SRudolf Cornelissen * OTOH the overlay unit distorts if we reserve too much time! */ 2037ae8e6dcSRudolf Cornelissen if (target.timing.h_display == si->ps.p2_timing.h_display) 20404e6b7ceSRudolf Cornelissen { 205139d62e9SRudolf Cornelissen /* NV11 timing has different constraints than later cards */ 206139d62e9SRudolf Cornelissen if (si->ps.card_type == NV11) 2072cb6fc9cSRudolf Cornelissen target.timing.h_total -= 56; 208139d62e9SRudolf Cornelissen else 209139d62e9SRudolf Cornelissen /* confirmed NV34 with 1680x1050 panel */ 210139d62e9SRudolf Cornelissen target.timing.h_total -= 32; 21104e6b7ceSRudolf Cornelissen } 21204e6b7ceSRudolf Cornelissen 21316fc5a30SRudolf Cornelissen if (target.timing.h_sync_start == target.timing.h_display) 21416fc5a30SRudolf Cornelissen target.timing.h_sync_start += 8; 21516fc5a30SRudolf Cornelissen if (target.timing.h_sync_end == target.timing.h_total) 21616fc5a30SRudolf Cornelissen target.timing.h_sync_end -= 8; 217c567e072SRudolf Cornelissen 218c567e072SRudolf Cornelissen /* vertical timing */ 21916fc5a30SRudolf Cornelissen target.timing.v_sync_start = 220268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_sync_start / ((float)si->ps.p2_timing.v_display)) * 22116fc5a30SRudolf Cornelissen target.timing.v_display)); 22216fc5a30SRudolf Cornelissen 22316fc5a30SRudolf Cornelissen target.timing.v_sync_end = 224268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_sync_end / ((float)si->ps.p2_timing.v_display)) * 22516fc5a30SRudolf Cornelissen target.timing.v_display)); 22616fc5a30SRudolf Cornelissen 22716fc5a30SRudolf Cornelissen target.timing.v_total = 228268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_total / ((float)si->ps.p2_timing.v_display)) * 229b97caf33SRudolf Cornelissen target.timing.v_display)) - 1; 23016fc5a30SRudolf Cornelissen 23116fc5a30SRudolf Cornelissen if (target.timing.v_sync_start == target.timing.v_display) 23216fc5a30SRudolf Cornelissen target.timing.v_sync_start += 1; 23316fc5a30SRudolf Cornelissen if (target.timing.v_sync_end == target.timing.v_total) 23416fc5a30SRudolf Cornelissen target.timing.v_sync_end -= 1; 235e6708074SRudolf Cornelissen 236e6708074SRudolf Cornelissen /* disable GPU scaling testmode so automatic scaling will be done */ 237e6708074SRudolf Cornelissen DAC2W(FP_DEBUG1, 0); 238c567e072SRudolf Cornelissen } 239c567e072SRudolf Cornelissen 240ff50d0d1SRudolf Cornelissen /* Modify parameters as required by standard VGA */ 241ff50d0d1SRudolf Cornelissen htotal = ((target.timing.h_total >> 3) - 5); 242ff50d0d1SRudolf Cornelissen hdisp_e = ((target.timing.h_display >> 3) - 1); 243ff50d0d1SRudolf Cornelissen hblnk_s = hdisp_e; 244da3804eeSRudolf Cornelissen hblnk_e = (htotal + 4); 245ff50d0d1SRudolf Cornelissen hsync_s = (target.timing.h_sync_start >> 3); 246ff50d0d1SRudolf Cornelissen hsync_e = (target.timing.h_sync_end >> 3); 247ff50d0d1SRudolf Cornelissen 248ff50d0d1SRudolf Cornelissen vtotal = target.timing.v_total - 2; 249ff50d0d1SRudolf Cornelissen vdisp_e = target.timing.v_display - 1; 250ff50d0d1SRudolf Cornelissen vblnk_s = vdisp_e; 251ff50d0d1SRudolf Cornelissen vblnk_e = (vtotal + 1); 252da3804eeSRudolf Cornelissen vsync_s = target.timing.v_sync_start; 253da3804eeSRudolf Cornelissen vsync_e = target.timing.v_sync_end; 254ff50d0d1SRudolf Cornelissen 255ff50d0d1SRudolf Cornelissen /* prevent memory adress counter from being reset (linecomp may not occur) */ 256ff50d0d1SRudolf Cornelissen linecomp = target.timing.v_display; 257ff50d0d1SRudolf Cornelissen 25864c14e7eSRudolf Cornelissen /* enable access to secondary head */ 25964c14e7eSRudolf Cornelissen set_crtc_owner(1); 260255e5021SRudolf Cornelissen 261a16d55ddSRudolf Cornelissen /* Note for laptop and DVI flatpanels: 262a16d55ddSRudolf Cornelissen * CRTC timing has a seperate set of registers from flatpanel timing. 263a16d55ddSRudolf Cornelissen * The flatpanel timing registers have scaling registers that are used to match 264a16d55ddSRudolf Cornelissen * these two modelines. */ 26508705d96Sshatty { 266a16d55ddSRudolf Cornelissen LOG(4,("CRTC2: Setting full timing...\n")); 26708705d96Sshatty 268ff50d0d1SRudolf Cornelissen /* log the mode that will be set */ 269ff50d0d1SRudolf 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)); 270ff50d0d1SRudolf 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)); 27108705d96Sshatty 272ff50d0d1SRudolf Cornelissen /* actually program the card! */ 273ff50d0d1SRudolf Cornelissen /* unlock CRTC registers at index 0-7 */ 274ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCE, (CRTC2R(VSYNCE) & 0x7f)); 275ff50d0d1SRudolf Cornelissen /* horizontal standard VGA regs */ 276ff50d0d1SRudolf Cornelissen CRTC2W(HTOTAL, (htotal & 0xff)); 277ff50d0d1SRudolf Cornelissen CRTC2W(HDISPE, (hdisp_e & 0xff)); 278ff50d0d1SRudolf Cornelissen CRTC2W(HBLANKS, (hblnk_s & 0xff)); 279ff50d0d1SRudolf Cornelissen /* also unlock vertical retrace registers in advance */ 280ff50d0d1SRudolf Cornelissen CRTC2W(HBLANKE, ((hblnk_e & 0x1f) | 0x80)); 281ff50d0d1SRudolf Cornelissen CRTC2W(HSYNCS, (hsync_s & 0xff)); 282ff50d0d1SRudolf Cornelissen CRTC2W(HSYNCE, ((hsync_e & 0x1f) | ((hblnk_e & 0x20) << 2))); 28308705d96Sshatty 284ff50d0d1SRudolf Cornelissen /* vertical standard VGA regs */ 285ff50d0d1SRudolf Cornelissen CRTC2W(VTOTAL, (vtotal & 0xff)); 286ff50d0d1SRudolf Cornelissen CRTC2W(OVERFLOW, 287ff50d0d1SRudolf Cornelissen ( 288ff50d0d1SRudolf Cornelissen ((vtotal & 0x100) >> (8 - 0)) | ((vtotal & 0x200) >> (9 - 5)) | 289ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x100) >> (8 - 1)) | ((vdisp_e & 0x200) >> (9 - 6)) | 290ff50d0d1SRudolf Cornelissen ((vsync_s & 0x100) >> (8 - 2)) | ((vsync_s & 0x200) >> (9 - 7)) | 291ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x100) >> (8 - 3)) | ((linecomp & 0x100) >> (8 - 4)) 292ff50d0d1SRudolf Cornelissen )); 293ff50d0d1SRudolf Cornelissen CRTC2W(PRROWSCN, 0x00); /* not used */ 294ff50d0d1SRudolf Cornelissen CRTC2W(MAXSCLIN, (((vblnk_s & 0x200) >> (9 - 5)) | ((linecomp & 0x200) >> (9 - 6)))); 295ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCS, (vsync_s & 0xff)); 296ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCE, ((CRTC2R(VSYNCE) & 0xf0) | (vsync_e & 0x0f))); 297ff50d0d1SRudolf Cornelissen CRTC2W(VDISPE, (vdisp_e & 0xff)); 298ff50d0d1SRudolf Cornelissen CRTC2W(VBLANKS, (vblnk_s & 0xff)); 299ff50d0d1SRudolf Cornelissen CRTC2W(VBLANKE, (vblnk_e & 0xff)); 300ff50d0d1SRudolf Cornelissen CRTC2W(LINECOMP, (linecomp & 0xff)); 30108705d96Sshatty 302ff50d0d1SRudolf Cornelissen /* horizontal extended regs */ 303ff50d0d1SRudolf Cornelissen //fixme: we reset bit4. is this correct?? 304ff50d0d1SRudolf Cornelissen CRTC2W(HEB, (CRTC2R(HEB) & 0xe0) | 305ff50d0d1SRudolf Cornelissen ( 306ff50d0d1SRudolf Cornelissen ((htotal & 0x100) >> (8 - 0)) | 307ff50d0d1SRudolf Cornelissen ((hdisp_e & 0x100) >> (8 - 1)) | 308ff50d0d1SRudolf Cornelissen ((hblnk_s & 0x100) >> (8 - 2)) | 309ff50d0d1SRudolf Cornelissen ((hsync_s & 0x100) >> (8 - 3)) 310ff50d0d1SRudolf Cornelissen )); 31108705d96Sshatty 312ff50d0d1SRudolf Cornelissen /* (mostly) vertical extended regs */ 313ff50d0d1SRudolf Cornelissen CRTC2W(LSR, 314ff50d0d1SRudolf Cornelissen ( 315ff50d0d1SRudolf Cornelissen ((vtotal & 0x400) >> (10 - 0)) | 316ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x400) >> (10 - 1)) | 317ff50d0d1SRudolf Cornelissen ((vsync_s & 0x400) >> (10 - 2)) | 318ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x400) >> (10 - 3)) | 319ff50d0d1SRudolf Cornelissen ((hblnk_e & 0x040) >> (6 - 4)) 320ff50d0d1SRudolf Cornelissen //fixme: we still miss one linecomp bit!?! is this it?? 321ff50d0d1SRudolf Cornelissen //| ((linecomp & 0x400) >> 3) 322ff50d0d1SRudolf Cornelissen )); 32308705d96Sshatty 324ff50d0d1SRudolf Cornelissen /* more vertical extended regs */ 325ff50d0d1SRudolf Cornelissen CRTC2W(EXTRA, 326ff50d0d1SRudolf Cornelissen ( 327ff50d0d1SRudolf Cornelissen ((vtotal & 0x800) >> (11 - 0)) | 328ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x800) >> (11 - 2)) | 329ff50d0d1SRudolf Cornelissen ((vsync_s & 0x800) >> (11 - 4)) | 330ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x800) >> (11 - 6)) 331ff50d0d1SRudolf Cornelissen //fixme: do we miss another linecomp bit!?! 332ff50d0d1SRudolf Cornelissen )); 33308705d96Sshatty 334ff50d0d1SRudolf Cornelissen /* setup 'large screen' mode */ 335ff50d0d1SRudolf Cornelissen if (target.timing.h_display >= 1280) 336ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0xfb)); 33708705d96Sshatty else 338ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x04)); 33908705d96Sshatty 340ff50d0d1SRudolf Cornelissen /* setup HSYNC & VSYNC polarity */ 341ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: sync polarity: ")); 342255e5021SRudolf Cornelissen temp = NV_REG8(NV8_MISCR); 343ff50d0d1SRudolf Cornelissen if (target.timing.flags & B_POSITIVE_HSYNC) 344ff50d0d1SRudolf Cornelissen { 345ff50d0d1SRudolf Cornelissen LOG(2,("H:pos ")); 346ff50d0d1SRudolf Cornelissen temp &= ~0x40; 34708705d96Sshatty } 348ff50d0d1SRudolf Cornelissen else 349ff50d0d1SRudolf Cornelissen { 350ff50d0d1SRudolf Cornelissen LOG(2,("H:neg ")); 351ff50d0d1SRudolf Cornelissen temp |= 0x40; 352ff50d0d1SRudolf Cornelissen } 353ff50d0d1SRudolf Cornelissen if (target.timing.flags & B_POSITIVE_VSYNC) 354ff50d0d1SRudolf Cornelissen { 355ff50d0d1SRudolf Cornelissen LOG(2,("V:pos ")); 356ff50d0d1SRudolf Cornelissen temp &= ~0x80; 357ff50d0d1SRudolf Cornelissen } 358ff50d0d1SRudolf Cornelissen else 359ff50d0d1SRudolf Cornelissen { 360ff50d0d1SRudolf Cornelissen LOG(2,("V:neg ")); 361ff50d0d1SRudolf Cornelissen temp |= 0x80; 362ff50d0d1SRudolf Cornelissen } 363255e5021SRudolf Cornelissen NV_REG8(NV8_MISCW) = temp; 364ff50d0d1SRudolf Cornelissen 365255e5021SRudolf Cornelissen LOG(2,(", MISC reg readback: $%02x\n", NV_REG8(NV8_MISCR))); 366ff50d0d1SRudolf Cornelissen } 367ff50d0d1SRudolf Cornelissen 368ff50d0d1SRudolf Cornelissen /* always disable interlaced operation */ 369255e5021SRudolf Cornelissen /* (interlace is supported on upto and including NV10, NV15, and NV30 and up) */ 370ff50d0d1SRudolf Cornelissen CRTC2W(INTERLACE, 0xff); 37108705d96Sshatty 372bc9c6041SRudolf Cornelissen /* disable CRTC slaved mode unless a panel is in use */ 373bc9c6041SRudolf Cornelissen // fixme: this kills TVout when it was in use... 374bc9c6041SRudolf Cornelissen if (!si->ps.tmds2_active) CRTC2W(PIXEL, (CRTC2R(PIXEL) & 0x7f)); 375bc9c6041SRudolf Cornelissen 3761e37a9acSRudolf Cornelissen /* setup flatpanel if connected and active */ 377a16d55ddSRudolf Cornelissen if (si->ps.tmds2_active) 378a16d55ddSRudolf Cornelissen { 379a16d55ddSRudolf Cornelissen uint32 iscale_x, iscale_y; 380a16d55ddSRudolf Cornelissen 381a973fe9eSRudolf Cornelissen /* calculate inverse scaling factors used by hardware in 20.12 format */ 3820fccffc2SRudolf Cornelissen iscale_x = (((1 << 12) * target.timing.h_display) / si->ps.p2_timing.h_display); 3830fccffc2SRudolf Cornelissen iscale_y = (((1 << 12) * target.timing.v_display) / si->ps.p2_timing.v_display); 3841e37a9acSRudolf Cornelissen 3851e37a9acSRudolf Cornelissen /* unblock flatpanel timing programming (or something like that..) */ 3861e37a9acSRudolf Cornelissen CRTC2W(FP_HTIMING, 0); 3871e37a9acSRudolf Cornelissen CRTC2W(FP_VTIMING, 0); 388e6708074SRudolf Cornelissen LOG(2,("CRTC2: FP_HTIMING reg readback: $%02x\n", CRTC2R(FP_HTIMING))); 389e6708074SRudolf Cornelissen LOG(2,("CRTC2: FP_VTIMING reg readback: $%02x\n", CRTC2R(FP_VTIMING))); 3901e37a9acSRudolf Cornelissen 391a973fe9eSRudolf Cornelissen /* enable full width visibility on flatpanel */ 392a973fe9eSRudolf Cornelissen DAC2W(FP_HVALID_S, 0); 3930fccffc2SRudolf Cornelissen DAC2W(FP_HVALID_E, (si->ps.p2_timing.h_display - 1)); 394a973fe9eSRudolf Cornelissen /* enable full height visibility on flatpanel */ 395a973fe9eSRudolf Cornelissen DAC2W(FP_VVALID_S, 0); 3960fccffc2SRudolf Cornelissen DAC2W(FP_VVALID_E, (si->ps.p2_timing.v_display - 1)); 397a973fe9eSRudolf Cornelissen 3984709c2c8SRudolf Cornelissen /* nVidia cards support upscaling except on ??? */ 3994709c2c8SRudolf Cornelissen /* NV11 cards can upscale after all! */ 400e6708074SRudolf Cornelissen if (0)//si->ps.card_type == NV11) 4011e37a9acSRudolf Cornelissen { 4021e37a9acSRudolf Cornelissen /* disable last fetched line limiting */ 4031e37a9acSRudolf Cornelissen DAC2W(FP_DEBUG2, 0x00000000); 404c567e072SRudolf Cornelissen /* inform panel to scale if needed */ 405c567e072SRudolf Cornelissen if ((iscale_x != (1 << 12)) || (iscale_y != (1 << 12))) 406c567e072SRudolf Cornelissen { 407c567e072SRudolf Cornelissen LOG(2,("CRTC2: DFP needs to do scaling\n")); 4081e37a9acSRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) | 0x00000100)); 4091e37a9acSRudolf Cornelissen } 4101e37a9acSRudolf Cornelissen else 4111e37a9acSRudolf Cornelissen { 412c567e072SRudolf Cornelissen LOG(2,("CRTC2: no scaling for DFP needed\n")); 413c567e072SRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) & 0xfffffeff)); 414c567e072SRudolf Cornelissen } 415c567e072SRudolf Cornelissen } 416c567e072SRudolf Cornelissen else 417c567e072SRudolf Cornelissen { 418a973fe9eSRudolf Cornelissen float dm_aspect; 419a973fe9eSRudolf Cornelissen 420c567e072SRudolf Cornelissen LOG(2,("CRTC2: GPU scales for DFP if needed\n")); 4211e37a9acSRudolf Cornelissen 422a973fe9eSRudolf Cornelissen /* calculate display mode aspect */ 423a973fe9eSRudolf Cornelissen dm_aspect = (target.timing.h_display / ((float)target.timing.v_display)); 424a973fe9eSRudolf Cornelissen 425a16d55ddSRudolf Cornelissen /* limit last fetched line if vertical scaling is done */ 4261e37a9acSRudolf Cornelissen if (iscale_y != (1 << 12)) 427a16d55ddSRudolf Cornelissen DAC2W(FP_DEBUG2, ((1 << 28) | ((target.timing.v_display - 1) << 16))); 428a16d55ddSRudolf Cornelissen else 429a16d55ddSRudolf Cornelissen DAC2W(FP_DEBUG2, 0x00000000); 4301e37a9acSRudolf Cornelissen 4311e37a9acSRudolf Cornelissen /* inform panel not to scale */ 4321e37a9acSRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) & 0xfffffeff)); 433c65998faSRudolf Cornelissen 434c65998faSRudolf Cornelissen /* GPU scaling is automatically setup by hardware, so only modify this 435c65998faSRudolf Cornelissen * scalingfactor for non 4:3 (1.33) aspect panels; 436c65998faSRudolf Cornelissen * let's consider 1280x1024 1:33 aspect (it's 1.25 aspect actually!) */ 437c65998faSRudolf Cornelissen 438a973fe9eSRudolf Cornelissen /* correct for widescreen panels relative to mode... 439a973fe9eSRudolf Cornelissen * (so if panel is more widescreen than mode being set) */ 440a973fe9eSRudolf Cornelissen /* BTW: known widescreen panels: 441c65998faSRudolf Cornelissen * 1280 x 800 (1.60), 442c65998faSRudolf Cornelissen * 1440 x 900 (1.60), 443b97caf33SRudolf Cornelissen * 1680 x 1050 (1.60), 444b97caf33SRudolf Cornelissen * 1920 x 1200 (1.60). */ 445c65998faSRudolf Cornelissen /* known 4:3 aspect non-standard resolution panels: 446c65998faSRudolf Cornelissen * 1400 x 1050 (1.33). */ 447a973fe9eSRudolf Cornelissen /* NOTE: 448a973fe9eSRudolf Cornelissen * allow 0.10 difference so 1280x1024 panels will be used fullscreen! */ 449a973fe9eSRudolf Cornelissen if ((iscale_x != (1 << 12)) && (si->ps.panel2_aspect > (dm_aspect + 0.10))) 450c65998faSRudolf Cornelissen { 451a973fe9eSRudolf Cornelissen uint16 diff; 452a973fe9eSRudolf Cornelissen 453a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: (relative) widescreen panel: tuning horizontal scaling\n")); 454a973fe9eSRudolf Cornelissen 455a973fe9eSRudolf Cornelissen /* X-scaling should be the same as Y-scaling */ 456a973fe9eSRudolf Cornelissen iscale_x = iscale_y; 457c65998faSRudolf Cornelissen /* enable testmode (b12) and program new X-scaling factor */ 458c65998faSRudolf Cornelissen DAC2W(FP_DEBUG1, (((iscale_x >> 1) & 0x00000fff) | (1 << 12))); 459a973fe9eSRudolf Cornelissen /* center/cut-off left and right side of screen */ 4600fccffc2SRudolf Cornelissen diff = ((si->ps.p2_timing.h_display - 46179098812SRudolf Cornelissen ((target.timing.h_display * (1 << 12)) / iscale_x)) 462a973fe9eSRudolf Cornelissen / 2); 463a973fe9eSRudolf Cornelissen DAC2W(FP_HVALID_S, diff); 4640fccffc2SRudolf Cornelissen DAC2W(FP_HVALID_E, ((si->ps.p2_timing.h_display - diff) - 1)); 465c65998faSRudolf Cornelissen } 466c65998faSRudolf Cornelissen /* correct for portrait panels... */ 467a973fe9eSRudolf Cornelissen /* NOTE: 468a973fe9eSRudolf Cornelissen * allow 0.10 difference so 1280x1024 panels will be used fullscreen! */ 469a973fe9eSRudolf Cornelissen if ((iscale_y != (1 << 12)) && (si->ps.panel2_aspect < (dm_aspect - 0.10))) 470c65998faSRudolf Cornelissen { 471a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: (relative) portrait panel: should tune vertical scaling\n")); 472a973fe9eSRudolf Cornelissen /* fixme: implement if this kind of portrait panels exist on nVidia... */ 473c65998faSRudolf Cornelissen } 4741e37a9acSRudolf Cornelissen } 4751e37a9acSRudolf Cornelissen 4761e37a9acSRudolf Cornelissen /* do some logging.. */ 477a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_HVALID_S reg readback: $%08x\n", DAC2R(FP_HVALID_S))); 478a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_HVALID_E reg readback: $%08x\n", DAC2R(FP_HVALID_E))); 479a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_VVALID_S reg readback: $%08x\n", DAC2R(FP_VVALID_S))); 480a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_VVALID_E reg readback: $%08x\n", DAC2R(FP_VVALID_E))); 4811e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG0 reg readback: $%08x\n", DAC2R(FP_DEBUG0))); 4821e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG1 reg readback: $%08x\n", DAC2R(FP_DEBUG1))); 4831e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG2 reg readback: $%08x\n", DAC2R(FP_DEBUG2))); 4841e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG3 reg readback: $%08x\n", DAC2R(FP_DEBUG3))); 4851e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_TG_CTRL reg readback: $%08x\n", DAC2R(FP_TG_CTRL))); 486a16d55ddSRudolf Cornelissen } 487a16d55ddSRudolf Cornelissen 48808705d96Sshatty return B_OK; 48908705d96Sshatty } 49008705d96Sshatty 491ff50d0d1SRudolf Cornelissen status_t nv_crtc2_depth(int mode) 49208705d96Sshatty { 493ff50d0d1SRudolf Cornelissen uint8 viddelay = 0; 494ff50d0d1SRudolf Cornelissen uint32 genctrl = 0; 495ff50d0d1SRudolf Cornelissen 496ff50d0d1SRudolf Cornelissen /* set VCLK scaling */ 49708705d96Sshatty switch(mode) 49808705d96Sshatty { 499ff50d0d1SRudolf Cornelissen case BPP8: 500ff50d0d1SRudolf Cornelissen viddelay = 0x01; 501ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 reset: 'direct mode' */ 502ff50d0d1SRudolf Cornelissen genctrl = 0x00101100; 50308705d96Sshatty break; 504ff50d0d1SRudolf Cornelissen case BPP15: 505ff50d0d1SRudolf Cornelissen viddelay = 0x02; 506ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 507ff50d0d1SRudolf Cornelissen genctrl = 0x00100130; 508ff50d0d1SRudolf Cornelissen break; 509ff50d0d1SRudolf Cornelissen case BPP16: 510ff50d0d1SRudolf Cornelissen viddelay = 0x02; 511ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 512ff50d0d1SRudolf Cornelissen genctrl = 0x00101130; 513ff50d0d1SRudolf Cornelissen break; 514ff50d0d1SRudolf Cornelissen case BPP24: 515ff50d0d1SRudolf Cornelissen viddelay = 0x03; 516ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 517ff50d0d1SRudolf Cornelissen genctrl = 0x00100130; 518ff50d0d1SRudolf Cornelissen break; 519ff50d0d1SRudolf Cornelissen case BPP32: 520ff50d0d1SRudolf Cornelissen viddelay = 0x03; 521ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 522ff50d0d1SRudolf Cornelissen genctrl = 0x00101130; 52308705d96Sshatty break; 52408705d96Sshatty } 52564c14e7eSRudolf Cornelissen /* enable access to secondary head */ 52664c14e7eSRudolf Cornelissen set_crtc_owner(1); 527255e5021SRudolf Cornelissen 528ff50d0d1SRudolf Cornelissen CRTC2W(PIXEL, ((CRTC2R(PIXEL) & 0xfc) | viddelay)); 529ff50d0d1SRudolf Cornelissen DAC2W(GENCTRL, genctrl); 53008705d96Sshatty 53108705d96Sshatty return B_OK; 53208705d96Sshatty } 53308705d96Sshatty 534*4022652cSRudolf Cornelissen status_t nv_crtc2_dpms(bool display, bool h, bool v, bool do_panel) 53508705d96Sshatty { 536d97178c9SRudolf Cornelissen uint8 temp; 537*4022652cSRudolf Cornelissen char msg[100]; 538ff50d0d1SRudolf Cornelissen 539*4022652cSRudolf Cornelissen sprintf(msg, "CRTC2: setting DPMS: "); 540ff50d0d1SRudolf Cornelissen 54164c14e7eSRudolf Cornelissen /* enable access to secondary head */ 54264c14e7eSRudolf Cornelissen set_crtc_owner(1); 543255e5021SRudolf Cornelissen 544ff50d0d1SRudolf Cornelissen /* start synchronous reset: required before turning screen off! */ 545d97178c9SRudolf Cornelissen SEQW(RESET, 0x01); 546ff50d0d1SRudolf Cornelissen 547d97178c9SRudolf Cornelissen temp = SEQR(CLKMODE); 548ff50d0d1SRudolf Cornelissen if (display) 54908705d96Sshatty { 550ecaef637SRudolf Cornelissen /* turn screen on */ 551d97178c9SRudolf Cornelissen SEQW(CLKMODE, (temp & ~0x20)); 552ff50d0d1SRudolf Cornelissen 553ecaef637SRudolf Cornelissen /* end synchronous reset because display should be enabled */ 554d97178c9SRudolf Cornelissen SEQW(RESET, 0x03); 555ff50d0d1SRudolf Cornelissen 556*4022652cSRudolf Cornelissen if (do_panel && si->ps.tmds2_active && !si->ps.laptop) 557b4f28c26SRudolf Cornelissen { 558ecaef637SRudolf Cornelissen /* restore original panelsync and panel-enable */ 559ecaef637SRudolf Cornelissen uint32 panelsync = 0x00000000; 560ecaef637SRudolf Cornelissen if(si->ps.p2_timing.flags & B_POSITIVE_VSYNC) panelsync |= 0x00000001; 561ecaef637SRudolf Cornelissen if(si->ps.p2_timing.flags & B_POSITIVE_HSYNC) panelsync |= 0x00000010; 562ecaef637SRudolf Cornelissen /* display enable polarity (not an official flag) */ 563ecaef637SRudolf Cornelissen if(si->ps.p2_timing.flags & B_BLANK_PEDESTAL) panelsync |= 0x10000000; 564ecaef637SRudolf Cornelissen DAC2W(FP_TG_CTRL, ((DAC2R(FP_TG_CTRL) & 0xcfffffcc) | panelsync)); 565ecaef637SRudolf Cornelissen 566ecaef637SRudolf Cornelissen //fixme?: looks like we don't need this after all: 567b4f28c26SRudolf Cornelissen /* powerup both LVDS (laptop panellink) and TMDS (DVI panellink) 568b4f28c26SRudolf Cornelissen * internal transmitters... */ 5698addb7c3SRudolf Cornelissen /* note: 5708addb7c3SRudolf Cornelissen * the powerbits in this register are hardwired to the DVI connectors, 5718addb7c3SRudolf Cornelissen * instead of to the DACs! (confirmed NV34) */ 5728addb7c3SRudolf Cornelissen //fixme... 573ecaef637SRudolf Cornelissen //DAC2W(FP_DEBUG0, (DAC2R(FP_DEBUG0) & 0xcfffffff)); 574b4f28c26SRudolf Cornelissen /* ... and powerup external TMDS transmitter if it exists */ 575ed391abaSRudolf Cornelissen /* (confirmed OK on NV28 and NV34) */ 576ecaef637SRudolf Cornelissen //CRTC2W(0x59, (CRTC2R(0x59) | 0x01)); 577*4022652cSRudolf Cornelissen 578*4022652cSRudolf Cornelissen sprintf(msg, "%s(panel-)", msg); 579b4f28c26SRudolf Cornelissen } 5804709c2c8SRudolf Cornelissen 581*4022652cSRudolf Cornelissen sprintf(msg, "%sdisplay on, ", msg); 58208705d96Sshatty } 58308705d96Sshatty else 58408705d96Sshatty { 585ecaef637SRudolf Cornelissen /* turn screen off */ 586d97178c9SRudolf Cornelissen SEQW(CLKMODE, (temp | 0x20)); 587ff50d0d1SRudolf Cornelissen 588*4022652cSRudolf Cornelissen if (do_panel && si->ps.tmds2_active && !si->ps.laptop) 589b4f28c26SRudolf Cornelissen { 590ecaef637SRudolf Cornelissen /* shutoff panelsync and disable panel */ 591ecaef637SRudolf Cornelissen DAC2W(FP_TG_CTRL, ((DAC2R(FP_TG_CTRL) & 0xcfffffcc) | 0x20000022)); 592ecaef637SRudolf Cornelissen 593ecaef637SRudolf Cornelissen //fixme?: looks like we don't need this after all: 594b4f28c26SRudolf Cornelissen /* powerdown both LVDS (laptop panellink) and TMDS (DVI panellink) 595b4f28c26SRudolf Cornelissen * internal transmitters... */ 5968addb7c3SRudolf Cornelissen /* note: 5978addb7c3SRudolf Cornelissen * the powerbits in this register are hardwired to the DVI connectors, 5988addb7c3SRudolf Cornelissen * instead of to the DACs! (confirmed NV34) */ 5998addb7c3SRudolf Cornelissen //fixme... 600ecaef637SRudolf Cornelissen //DAC2W(FP_DEBUG0, (DAC2R(FP_DEBUG0) | 0x30000000)); 601b4f28c26SRudolf Cornelissen /* ... and powerdown external TMDS transmitter if it exists */ 602ed391abaSRudolf Cornelissen /* (confirmed OK on NV28 and NV34) */ 603ecaef637SRudolf Cornelissen //CRTC2W(0x59, (CRTC2R(0x59) & 0xfe)); 604*4022652cSRudolf Cornelissen 605*4022652cSRudolf Cornelissen sprintf(msg, "%s(panel-)", msg); 606b4f28c26SRudolf Cornelissen } 6074709c2c8SRudolf Cornelissen 608*4022652cSRudolf Cornelissen sprintf(msg, "%sdisplay off, ", msg); 60908705d96Sshatty } 61008705d96Sshatty 611ff50d0d1SRudolf Cornelissen if (h) 61208705d96Sshatty { 613ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0x7f)); 614*4022652cSRudolf Cornelissen sprintf(msg, "%shsync enabled, ", msg); 615ff50d0d1SRudolf Cornelissen } 616ff50d0d1SRudolf Cornelissen else 617ff50d0d1SRudolf Cornelissen { 618ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x80)); 619*4022652cSRudolf Cornelissen sprintf(msg, "%shsync disabled, ", msg); 620ff50d0d1SRudolf Cornelissen } 621ff50d0d1SRudolf Cornelissen if (v) 622ff50d0d1SRudolf Cornelissen { 623ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0xbf)); 624*4022652cSRudolf Cornelissen sprintf(msg, "%svsync enabled\n", msg); 625ff50d0d1SRudolf Cornelissen } 626ff50d0d1SRudolf Cornelissen else 627ff50d0d1SRudolf Cornelissen { 628ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x40)); 629*4022652cSRudolf Cornelissen sprintf(msg, "%svsync disabled\n", msg); 630ff50d0d1SRudolf Cornelissen } 63108705d96Sshatty 632*4022652cSRudolf Cornelissen LOG(4, (msg)); 633*4022652cSRudolf Cornelissen 63408705d96Sshatty return B_OK; 63508705d96Sshatty } 63608705d96Sshatty 637ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_display_pitch() 63808705d96Sshatty { 63908705d96Sshatty uint32 offset; 64008705d96Sshatty 64108705d96Sshatty LOG(4,("CRTC2: setting card pitch (offset between lines)\n")); 64208705d96Sshatty 64308705d96Sshatty /* figure out offset value hardware needs */ 644ff50d0d1SRudolf Cornelissen offset = si->fbc.bytes_per_row / 8; 64508705d96Sshatty 646ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: offset register set to: $%04x\n", offset)); 64708705d96Sshatty 64864c14e7eSRudolf Cornelissen /* enable access to secondary head */ 64964c14e7eSRudolf Cornelissen set_crtc_owner(1); 650255e5021SRudolf Cornelissen 651b4bdc2b6SRudolf Cornelissen /* program the card */ 652ff50d0d1SRudolf Cornelissen CRTC2W(PITCHL, (offset & 0x00ff)); 653ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT0, ((CRTC2R(REPAINT0) & 0x1f) | ((offset & 0x0700) >> 3))); 654ff50d0d1SRudolf Cornelissen 65508705d96Sshatty return B_OK; 65608705d96Sshatty } 65708705d96Sshatty 658ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_display_start(uint32 startadd,uint8 bpp) 65908705d96Sshatty { 660e0dd08e8SRudolf Cornelissen uint32 timeout = 0; 66108705d96Sshatty 662ff50d0d1SRudolf Cornelissen LOG(4,("CRTC2: setting card RAM to be displayed bpp %d\n", bpp)); 66308705d96Sshatty 664ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: startadd: $%08x\n", startadd)); 665ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: frameRAM: $%08x\n", si->framebuffer)); 666ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: framebuffer: $%08x\n", si->fbc.frame_buffer)); 667ff50d0d1SRudolf Cornelissen 668e0dd08e8SRudolf Cornelissen /* we might have no retraces during setmode! */ 669e0dd08e8SRudolf Cornelissen /* wait 25mS max. for retrace to occur (refresh > 40Hz) */ 670e0dd08e8SRudolf Cornelissen while (((NV_REG32(NV32_RASTER2) & 0x000007ff) < si->dm.timing.v_display) && 671e0dd08e8SRudolf Cornelissen (timeout < (25000/10))) 672e0dd08e8SRudolf Cornelissen { 673e0dd08e8SRudolf Cornelissen /* don't snooze much longer or retrace might get missed! */ 674e0dd08e8SRudolf Cornelissen snooze(10); 675e0dd08e8SRudolf Cornelissen timeout++; 676e0dd08e8SRudolf Cornelissen } 677ff50d0d1SRudolf Cornelissen 67864c14e7eSRudolf Cornelissen /* enable access to secondary head */ 67964c14e7eSRudolf Cornelissen set_crtc_owner(1); 680255e5021SRudolf Cornelissen 681ff50d0d1SRudolf Cornelissen /* upto 4Gb RAM adressing: must be used on NV10 and later! */ 682ff50d0d1SRudolf Cornelissen /* NOTE: 683ff50d0d1SRudolf Cornelissen * While this register also exists on pre-NV10 cards, it will 684ff50d0d1SRudolf Cornelissen * wrap-around at 16Mb boundaries!! */ 685ff50d0d1SRudolf Cornelissen 686ff50d0d1SRudolf Cornelissen /* 30bit adress in 32bit words */ 687ff50d0d1SRudolf Cornelissen NV_REG32(NV32_NV10FB2STADD32) = (startadd & 0xfffffffc); 688ff50d0d1SRudolf Cornelissen 689bc9d4aceSRudolf Cornelissen /* set byte adress: (b0 - 1) */ 690e0dd08e8SRudolf Cornelissen ATB2W(HORPIXPAN, ((startadd & 0x00000003) << 1)); 691ff50d0d1SRudolf Cornelissen 692ff50d0d1SRudolf Cornelissen return B_OK; 693ff50d0d1SRudolf Cornelissen } 694ff50d0d1SRudolf Cornelissen 695ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_init() 696ff50d0d1SRudolf Cornelissen { 697ff50d0d1SRudolf Cornelissen int i; 698ff50d0d1SRudolf Cornelissen uint32 * fb; 699ff50d0d1SRudolf Cornelissen /* cursor bitmap will be stored at the start of the framebuffer */ 700ff50d0d1SRudolf Cornelissen const uint32 curadd = 0; 701ff50d0d1SRudolf Cornelissen 70264c14e7eSRudolf Cornelissen /* enable access to secondary head */ 70364c14e7eSRudolf Cornelissen set_crtc_owner(1); 704255e5021SRudolf Cornelissen 705ff50d0d1SRudolf Cornelissen /* set cursor bitmap adress ... */ 706255e5021SRudolf Cornelissen if (si->ps.laptop) 707ff50d0d1SRudolf Cornelissen { 708ff50d0d1SRudolf Cornelissen /* must be used this way on pre-NV10 and on all 'Go' cards! */ 709ff50d0d1SRudolf Cornelissen 710ff50d0d1SRudolf Cornelissen /* cursorbitmap must start on 2Kbyte boundary: */ 711ff50d0d1SRudolf Cornelissen /* set adress bit11-16, and set 'no doublescan' (registerbit 1 = 0) */ 712ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, ((curadd & 0x0001f800) >> 9)); 713ff50d0d1SRudolf Cornelissen /* set adress bit17-23, and set graphics mode cursor(?) (registerbit 7 = 1) */ 714ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL1, (((curadd & 0x00fe0000) >> 17) | 0x80)); 715ff50d0d1SRudolf Cornelissen /* set adress bit24-31 */ 716ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL2, ((curadd & 0xff000000) >> 24)); 71708705d96Sshatty } 71808705d96Sshatty else 71908705d96Sshatty { 720ff50d0d1SRudolf Cornelissen /* upto 4Gb RAM adressing: 721ff50d0d1SRudolf Cornelissen * can be used on NV10 and later (except for 'Go' cards)! */ 722ff50d0d1SRudolf Cornelissen /* NOTE: 723ff50d0d1SRudolf Cornelissen * This register does not exist on pre-NV10 and 'Go' cards. */ 724ff50d0d1SRudolf Cornelissen 725ff50d0d1SRudolf Cornelissen /* cursorbitmap must still start on 2Kbyte boundary: */ 726ff50d0d1SRudolf Cornelissen NV_REG32(NV32_NV10CUR2ADD32) = (curadd & 0xfffff800); 72708705d96Sshatty } 72808705d96Sshatty 729ff50d0d1SRudolf Cornelissen /* set cursor colour: not needed because of direct nature of cursor bitmap. */ 730ff50d0d1SRudolf Cornelissen 731ff50d0d1SRudolf Cornelissen /*clear cursor*/ 732ff50d0d1SRudolf Cornelissen fb = (uint32 *) si->framebuffer + curadd; 733ff50d0d1SRudolf Cornelissen for (i=0;i<(2048/4);i++) 734ff50d0d1SRudolf Cornelissen { 735ff50d0d1SRudolf Cornelissen fb[i]=0; 736ff50d0d1SRudolf Cornelissen } 737ff50d0d1SRudolf Cornelissen 738ff50d0d1SRudolf Cornelissen /* select 32x32 pixel, 16bit color cursorbitmap, no doublescan */ 739ff50d0d1SRudolf Cornelissen NV_REG32(NV32_2CURCONF) = 0x02000100; 740ff50d0d1SRudolf Cornelissen 741df7dbd1dSRudolf Cornelissen /* activate hardware-sync between cursor updates and vertical retrace */ 742df7dbd1dSRudolf Cornelissen DAC2W(NV10_CURSYNC, (DAC2R(NV10_CURSYNC) | 0x02000000)); 743df7dbd1dSRudolf Cornelissen 744ff50d0d1SRudolf Cornelissen /* activate hardware cursor */ 745255e5021SRudolf Cornelissen nv_crtc2_cursor_show(); 746ff50d0d1SRudolf Cornelissen 747ff50d0d1SRudolf Cornelissen return B_OK; 748ff50d0d1SRudolf Cornelissen } 749ff50d0d1SRudolf Cornelissen 750ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_show() 751ff50d0d1SRudolf Cornelissen { 752255e5021SRudolf Cornelissen LOG(4,("CRTC2: enabling cursor\n")); 753255e5021SRudolf Cornelissen 75464c14e7eSRudolf Cornelissen /* enable access to secondary head */ 75564c14e7eSRudolf Cornelissen set_crtc_owner(1); 756255e5021SRudolf Cornelissen 757ff50d0d1SRudolf Cornelissen /* b0 = 1 enables cursor */ 758ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, (CRTC2R(CURCTL0) | 0x01)); 759ff50d0d1SRudolf Cornelissen 76011058c2fSRudolf Cornelissen /* workaround for hardware bug confirmed existing on NV43: 76111058c2fSRudolf Cornelissen * Cursor visibility is not updated without a position update if its hardware 76211058c2fSRudolf Cornelissen * retrace sync is enabled. */ 76311058c2fSRudolf Cornelissen if (si->ps.card_arch == NV40A) DAC2W(CURPOS, (DAC2R(CURPOS))); 76411058c2fSRudolf Cornelissen 765ff50d0d1SRudolf Cornelissen return B_OK; 766ff50d0d1SRudolf Cornelissen } 767ff50d0d1SRudolf Cornelissen 768ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_hide() 769ff50d0d1SRudolf Cornelissen { 770255e5021SRudolf Cornelissen LOG(4,("CRTC2: disabling cursor\n")); 771255e5021SRudolf Cornelissen 77264c14e7eSRudolf Cornelissen /* enable access to secondary head */ 77364c14e7eSRudolf Cornelissen set_crtc_owner(1); 774255e5021SRudolf Cornelissen 775ff50d0d1SRudolf Cornelissen /* b0 = 0 disables cursor */ 776ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, (CRTC2R(CURCTL0) & 0xfe)); 777ff50d0d1SRudolf Cornelissen 77811058c2fSRudolf Cornelissen /* workaround for hardware bug confirmed existing on NV43: 77911058c2fSRudolf Cornelissen * Cursor visibility is not updated without a position update if its hardware 78011058c2fSRudolf Cornelissen * retrace sync is enabled. */ 78111058c2fSRudolf Cornelissen if (si->ps.card_arch == NV40A) DAC2W(CURPOS, (DAC2R(CURPOS))); 78211058c2fSRudolf Cornelissen 783ff50d0d1SRudolf Cornelissen return B_OK; 784ff50d0d1SRudolf Cornelissen } 785ff50d0d1SRudolf Cornelissen 786ff50d0d1SRudolf Cornelissen /*set up cursor shape*/ 787ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_define(uint8* andMask,uint8* xorMask) 788ff50d0d1SRudolf Cornelissen { 789ff50d0d1SRudolf Cornelissen int x, y; 790ff50d0d1SRudolf Cornelissen uint8 b; 791ff50d0d1SRudolf Cornelissen uint16 *cursor; 792ff50d0d1SRudolf Cornelissen uint16 pixel; 793ff50d0d1SRudolf Cornelissen 794ff50d0d1SRudolf Cornelissen /* get a pointer to the cursor */ 795ff50d0d1SRudolf Cornelissen cursor = (uint16*) si->framebuffer; 796ff50d0d1SRudolf Cornelissen 797ff50d0d1SRudolf Cornelissen /* draw the cursor */ 798ff50d0d1SRudolf Cornelissen /* (Nvidia cards have a RGB15 direct color cursor bitmap, bit #16 is transparancy) */ 799ff50d0d1SRudolf Cornelissen for (y = 0; y < 16; y++) 800ff50d0d1SRudolf Cornelissen { 801ff50d0d1SRudolf Cornelissen b = 0x80; 802ff50d0d1SRudolf Cornelissen for (x = 0; x < 8; x++) 803ff50d0d1SRudolf Cornelissen { 804ff50d0d1SRudolf Cornelissen /* preset transparant */ 805ff50d0d1SRudolf Cornelissen pixel = 0x0000; 806ff50d0d1SRudolf Cornelissen /* set white if requested */ 807ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (!(*xorMask & b))) pixel = 0xffff; 808ff50d0d1SRudolf Cornelissen /* set black if requested */ 809ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (*xorMask & b)) pixel = 0x8000; 810ff50d0d1SRudolf Cornelissen /* set invert if requested */ 811ff50d0d1SRudolf Cornelissen if ( (*andMask & b) && (*xorMask & b)) pixel = 0x7fff; 812ff50d0d1SRudolf Cornelissen /* place the pixel in the bitmap */ 813ff50d0d1SRudolf Cornelissen cursor[x + (y * 32)] = pixel; 814ff50d0d1SRudolf Cornelissen b >>= 1; 815ff50d0d1SRudolf Cornelissen } 816ff50d0d1SRudolf Cornelissen xorMask++; 817ff50d0d1SRudolf Cornelissen andMask++; 818ff50d0d1SRudolf Cornelissen b = 0x80; 819ff50d0d1SRudolf Cornelissen for (; x < 16; x++) 820ff50d0d1SRudolf Cornelissen { 821ff50d0d1SRudolf Cornelissen /* preset transparant */ 822ff50d0d1SRudolf Cornelissen pixel = 0x0000; 823ff50d0d1SRudolf Cornelissen /* set white if requested */ 824ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (!(*xorMask & b))) pixel = 0xffff; 825ff50d0d1SRudolf Cornelissen /* set black if requested */ 826ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (*xorMask & b)) pixel = 0x8000; 827ff50d0d1SRudolf Cornelissen /* set invert if requested */ 828ff50d0d1SRudolf Cornelissen if ( (*andMask & b) && (*xorMask & b)) pixel = 0x7fff; 829ff50d0d1SRudolf Cornelissen /* place the pixel in the bitmap */ 830ff50d0d1SRudolf Cornelissen cursor[x + (y * 32)] = pixel; 831ff50d0d1SRudolf Cornelissen b >>= 1; 832ff50d0d1SRudolf Cornelissen } 833ff50d0d1SRudolf Cornelissen xorMask++; 834ff50d0d1SRudolf Cornelissen andMask++; 835ff50d0d1SRudolf Cornelissen } 836ff50d0d1SRudolf Cornelissen 837ff50d0d1SRudolf Cornelissen return B_OK; 838ff50d0d1SRudolf Cornelissen } 839ff50d0d1SRudolf Cornelissen 840ff50d0d1SRudolf Cornelissen /* position the cursor */ 841ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_position(uint16 x, uint16 y) 842ff50d0d1SRudolf Cornelissen { 8430b7b8998SRudolf Cornelissen /* the cursor position is updated during retrace by card hardware */ 844ff50d0d1SRudolf Cornelissen 845ff50d0d1SRudolf Cornelissen /* update cursorposition */ 846ff50d0d1SRudolf Cornelissen DAC2W(CURPOS, ((x & 0x0fff) | ((y & 0x0fff) << 16))); 847ff50d0d1SRudolf Cornelissen 84808705d96Sshatty return B_OK; 84908705d96Sshatty } 85091731297SRudolf Cornelissen 85191731297SRudolf Cornelissen status_t nv_crtc2_stop_tvout(void) 85291731297SRudolf Cornelissen { 853d7dfe68dSRudolf Cornelissen LOG(4,("CRTC2: stopping TV output\n")); 854d7dfe68dSRudolf Cornelissen 85591731297SRudolf Cornelissen /* enable access to secondary head */ 85691731297SRudolf Cornelissen set_crtc_owner(1); 85791731297SRudolf Cornelissen 85891731297SRudolf Cornelissen /* just to be sure Vsync is _really_ enabled */ 85991731297SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0xbf)); 86091731297SRudolf Cornelissen 86191731297SRudolf Cornelissen /* wait for one image to be generated to make sure VGA has kicked in and is 86291731297SRudolf Cornelissen * running OK before continuing... 86391731297SRudolf Cornelissen * (Kicking in will fail often if we do not wait here) */ 86491731297SRudolf Cornelissen /* Note: 86591731297SRudolf Cornelissen * The used CRTC's Vsync is required to be enabled here. The DPMS state 86691731297SRudolf Cornelissen * programming in the driver makes sure this is the case. 86791731297SRudolf Cornelissen * (except for driver startup: see nv_general.c.) */ 86891731297SRudolf Cornelissen 86991731297SRudolf Cornelissen /* make sure we are 'in' active VGA picture */ 87091731297SRudolf Cornelissen while (NV_REG8(NV8_INSTAT1) & 0x08) snooze(1); 87191731297SRudolf Cornelissen /* wait for next vertical retrace start on VGA */ 87291731297SRudolf Cornelissen while (!(NV_REG8(NV8_INSTAT1) & 0x08)) snooze(1); 87391731297SRudolf Cornelissen /* now wait until we are 'in' active VGA picture again */ 87491731297SRudolf Cornelissen while (NV_REG8(NV8_INSTAT1) & 0x08) snooze(1); 87591731297SRudolf Cornelissen 87691731297SRudolf Cornelissen 87791731297SRudolf Cornelissen /* set CRTC to master mode (b7 = 0) if it wasn't slaved for a panel before */ 87891731297SRudolf Cornelissen if (!(si->ps.slaved_tmds2)) CRTC2W(PIXEL, (CRTC2R(PIXEL) & 0x03)); 87991731297SRudolf Cornelissen 88091731297SRudolf Cornelissen /* CAUTION: 88191731297SRudolf Cornelissen * On old cards, PLLSEL (and TV_SETUP?) cannot be read (sometimes?), but 88291731297SRudolf Cornelissen * write actions do succeed ... 88391731297SRudolf Cornelissen * This is confirmed for both ISA and PCI access, on NV04 and NV11. */ 88491731297SRudolf Cornelissen 88591731297SRudolf Cornelissen /* setup TVencoder connection */ 88691731297SRudolf Cornelissen /* b1-0 = %00: encoder type is SLAVE; 88791731297SRudolf Cornelissen * b24 = 1: VIP datapos is b0-7 */ 88891731297SRudolf Cornelissen //fixme if needed: setup completely instead of relying on pre-init by BIOS.. 88991731297SRudolf Cornelissen //(it seems to work OK on NV04 and NV11 although read reg. doesn't seem to work) 89091731297SRudolf Cornelissen DAC2W(TV_SETUP, ((DAC2R(TV_SETUP) & ~0x00000003) | 0x01000000)); 89191731297SRudolf Cornelissen 89291731297SRudolf Cornelissen /* tell GPU to use pixelclock from internal source instead of using TVencoder */ 89391731297SRudolf Cornelissen DACW(PLLSEL, 0x30000f00); 89491731297SRudolf Cornelissen 89591731297SRudolf Cornelissen /* HTOTAL, VTOTAL and OVERFLOW return their default CRTC use, instead of 89691731297SRudolf Cornelissen * H, V-low and V-high 'shadow' counters(?)(b0, 4 and 6 = 0) (b7 use = unknown) */ 89791731297SRudolf Cornelissen CRTC2W(TREG, 0x00); 89891731297SRudolf Cornelissen 89991731297SRudolf Cornelissen /* select panel encoder, not TV encoder if needed (b0 = 1). 90091731297SRudolf Cornelissen * Note: 90191731297SRudolf Cornelissen * Both are devices (often) using the CRTC in slaved mode. */ 90291731297SRudolf Cornelissen if (si->ps.slaved_tmds2) CRTC2W(LCD, (CRTC2R(LCD) | 0x01)); 90391731297SRudolf Cornelissen 90491731297SRudolf Cornelissen return B_OK; 90591731297SRudolf Cornelissen } 90691731297SRudolf Cornelissen 90791731297SRudolf Cornelissen status_t nv_crtc2_start_tvout(void) 90891731297SRudolf Cornelissen { 909d7dfe68dSRudolf Cornelissen LOG(4,("CRTC2: starting TV output\n")); 910d7dfe68dSRudolf Cornelissen 911a658603aSRudolf Cornelissen /* switch TV encoder to CRTC2 */ 912a658603aSRudolf Cornelissen NV_REG32(NV32_FUNCSEL) &= ~0x00000100; 913a658603aSRudolf Cornelissen NV_REG32(NV32_2FUNCSEL) |= 0x00000100; 914a658603aSRudolf Cornelissen 91591731297SRudolf Cornelissen /* enable access to secondary head */ 91691731297SRudolf Cornelissen set_crtc_owner(1); 91791731297SRudolf Cornelissen 91891731297SRudolf Cornelissen /* CAUTION: 91991731297SRudolf Cornelissen * On old cards, PLLSEL (and TV_SETUP?) cannot be read (sometimes?), but 92091731297SRudolf Cornelissen * write actions do succeed ... 92191731297SRudolf Cornelissen * This is confirmed for both ISA and PCI access, on NV04 and NV11. */ 92291731297SRudolf Cornelissen 92391731297SRudolf Cornelissen /* setup TVencoder connection */ 92491731297SRudolf Cornelissen /* b1-0 = %01: encoder type is MASTER; 92591731297SRudolf Cornelissen * b24 = 1: VIP datapos is b0-7 */ 92691731297SRudolf Cornelissen //fixme if needed: setup completely instead of relying on pre-init by BIOS.. 92791731297SRudolf Cornelissen //(it seems to work OK on NV04 and NV11 although read reg. doesn't seem to work) 92891731297SRudolf Cornelissen DAC2W(TV_SETUP, ((DAC2R(TV_SETUP) & ~0x00000002) | 0x01000001)); 92991731297SRudolf Cornelissen 93091731297SRudolf Cornelissen /* tell GPU to use pixelclock from TVencoder instead of using internal source */ 93191731297SRudolf Cornelissen /* (nessecary or display will 'shiver' on both TV and VGA.) */ 93291731297SRudolf Cornelissen DACW(PLLSEL, 0x100c0f00); 93391731297SRudolf Cornelissen 93491731297SRudolf Cornelissen /* Set overscan color to 'black' */ 93591731297SRudolf Cornelissen /* note: 93691731297SRudolf Cornelissen * Change this instruction for a visible overscan color if you're trying to 93791731297SRudolf Cornelissen * center the output on TV. Use it as a guide-'line' then ;-) */ 93891731297SRudolf Cornelissen ATB2W(OSCANCOLOR, 0x00); 93991731297SRudolf Cornelissen 94091731297SRudolf Cornelissen /* set CRTC to slaved mode (b7 = 1) and clear TVadjust (b3-5 = %000) */ 94191731297SRudolf Cornelissen CRTC2W(PIXEL, ((CRTC2R(PIXEL) & 0xc7) | 0x80)); 94291731297SRudolf Cornelissen /* select TV encoder, not panel encoder (b0 = 0). 94391731297SRudolf Cornelissen * Note: 94491731297SRudolf Cornelissen * Both are devices (often) using the CRTC in slaved mode. */ 94591731297SRudolf Cornelissen CRTC2W(LCD, (CRTC2R(LCD) & 0xfe)); 94691731297SRudolf Cornelissen 94791731297SRudolf Cornelissen /* HTOTAL, VTOTAL and OVERFLOW return their default CRTC use, instead of 94891731297SRudolf Cornelissen * H, V-low and V-high 'shadow' counters(?)(b0, 4 and 6 = 0) (b7 use = unknown) */ 94991731297SRudolf Cornelissen CRTC2W(TREG, 0x80); 95091731297SRudolf Cornelissen 95191731297SRudolf Cornelissen return B_OK; 95291731297SRudolf Cornelissen } 953