1ff50d0d1SRudolf Cornelissen /* second CTRC functionality for GeForce cards */ 2ff50d0d1SRudolf Cornelissen /* Author: 3*155a2ad0SRudolf Cornelissen Rudolf Cornelissen 11/2002-2/2006 408705d96Sshatty */ 508705d96Sshatty 608705d96Sshatty #define MODULE_BIT 0x00020000 708705d96Sshatty 808705d96Sshatty #include "nv_std.h" 908705d96Sshatty 10*155a2ad0SRudolf Cornelissen /* 11*155a2ad0SRudolf Cornelissen Enable/Disable interrupts. Just a wrapper around the 12*155a2ad0SRudolf Cornelissen ioctl() to the kernel driver. 13*155a2ad0SRudolf Cornelissen */ 14*155a2ad0SRudolf Cornelissen status_t nv_crtc2_interrupt_enable(bool flag) 15*155a2ad0SRudolf Cornelissen { 16*155a2ad0SRudolf Cornelissen status_t result = B_OK; 17*155a2ad0SRudolf Cornelissen nv_set_vblank_int svi; 18*155a2ad0SRudolf Cornelissen 19*155a2ad0SRudolf Cornelissen if (si->ps.int_assigned) 20*155a2ad0SRudolf Cornelissen { 21*155a2ad0SRudolf Cornelissen /* set the magic number so the driver knows we're for real */ 22*155a2ad0SRudolf Cornelissen svi.magic = NV_PRIVATE_DATA_MAGIC; 23*155a2ad0SRudolf Cornelissen svi.crtc = 1; 24*155a2ad0SRudolf Cornelissen svi.do_it = flag; 25*155a2ad0SRudolf Cornelissen /* contact driver and get a pointer to the registers and shared data */ 26*155a2ad0SRudolf Cornelissen result = ioctl(fd, NV_RUN_INTERRUPTS, &svi, sizeof(svi)); 27*155a2ad0SRudolf Cornelissen } 28*155a2ad0SRudolf Cornelissen 29*155a2ad0SRudolf Cornelissen return result; 30*155a2ad0SRudolf Cornelissen } 31*155a2ad0SRudolf Cornelissen 32a393eaf8SRudolf Cornelissen /* doing general fail-safe default setup here */ 33a393eaf8SRudolf Cornelissen //fixme: this is a _very_ basic setup, and it's preliminary... 34a393eaf8SRudolf Cornelissen status_t nv_crtc2_update_fifo() 35a393eaf8SRudolf Cornelissen { 36a393eaf8SRudolf Cornelissen uint8 bytes_per_pixel = 1; 37a393eaf8SRudolf Cornelissen uint32 drain; 38a393eaf8SRudolf Cornelissen 39a393eaf8SRudolf Cornelissen /* we are only using this on >>coldstarted<< cards which really need this */ 40a393eaf8SRudolf Cornelissen //fixme: re-enable or remove after general user confirmation of behaviour... 41a393eaf8SRudolf Cornelissen if (/*(si->settings.usebios) ||*/ (si->ps.card_type != NV11)) return B_OK; 42a393eaf8SRudolf Cornelissen 43d320dfafSRudolf Cornelissen /* enable access to secondary head */ 44a393eaf8SRudolf Cornelissen set_crtc_owner(1); 45a393eaf8SRudolf Cornelissen 46a393eaf8SRudolf Cornelissen /* set CRTC FIFO low watermark according to memory drain */ 47a393eaf8SRudolf Cornelissen switch(si->dm.space) 48a393eaf8SRudolf Cornelissen { 49a393eaf8SRudolf Cornelissen case B_CMAP8: 50a393eaf8SRudolf Cornelissen bytes_per_pixel = 1; 51a393eaf8SRudolf Cornelissen break; 52a393eaf8SRudolf Cornelissen case B_RGB15_LITTLE: 53a393eaf8SRudolf Cornelissen case B_RGB16_LITTLE: 54a393eaf8SRudolf Cornelissen bytes_per_pixel = 2; 55a393eaf8SRudolf Cornelissen break; 56a393eaf8SRudolf Cornelissen case B_RGB24_LITTLE: 57a393eaf8SRudolf Cornelissen bytes_per_pixel = 3; 58a393eaf8SRudolf Cornelissen break; 59a393eaf8SRudolf Cornelissen case B_RGB32_LITTLE: 60a393eaf8SRudolf Cornelissen bytes_per_pixel = 4; 61a393eaf8SRudolf Cornelissen break; 62a393eaf8SRudolf Cornelissen } 63a393eaf8SRudolf Cornelissen /* fixme: 64a393eaf8SRudolf Cornelissen * - I should probably include the refreshrate as well; 65a393eaf8SRudolf Cornelissen * - and the memory clocking speed, core clocking speed, RAM buswidth.. */ 66a393eaf8SRudolf Cornelissen drain = si->dm.timing.h_display * si->dm.timing.v_display * bytes_per_pixel; 67a393eaf8SRudolf Cornelissen 68a393eaf8SRudolf Cornelissen /* Doesn't work for other than 32bit space (yet?) */ 69a393eaf8SRudolf Cornelissen if (si->dm.space != B_RGB32_LITTLE) 70a393eaf8SRudolf Cornelissen { 71a393eaf8SRudolf Cornelissen /* BIOS defaults */ 72a393eaf8SRudolf Cornelissen CRTC2W(FIFO, 0x03); 73a393eaf8SRudolf Cornelissen CRTC2W(FIFO_LWM, 0x20); 74a393eaf8SRudolf Cornelissen LOG(4,("CRTC2: FIFO low-watermark set to $20, burst size 256 (BIOS defaults)\n")); 75a393eaf8SRudolf Cornelissen return B_OK; 76a393eaf8SRudolf Cornelissen } 77a393eaf8SRudolf Cornelissen 78a393eaf8SRudolf Cornelissen if (drain > (((uint32)1280) * 1024 * 4)) 79a393eaf8SRudolf Cornelissen { 80a393eaf8SRudolf Cornelissen /* set CRTC FIFO burst size for 'smaller' bursts */ 81a393eaf8SRudolf Cornelissen CRTC2W(FIFO, 0x01); 82a393eaf8SRudolf Cornelissen /* Instruct CRTC to fetch new data 'earlier' */ 83a393eaf8SRudolf Cornelissen CRTC2W(FIFO_LWM, 0x40); 84a393eaf8SRudolf Cornelissen LOG(4,("CRTC2: FIFO low-watermark set to $40, burst size 64\n")); 85a393eaf8SRudolf Cornelissen } 86a393eaf8SRudolf Cornelissen else 87a393eaf8SRudolf Cornelissen { 88a393eaf8SRudolf Cornelissen if (drain > (((uint32)1024) * 768 * 4)) 89a393eaf8SRudolf Cornelissen { 90a393eaf8SRudolf Cornelissen /* BIOS default */ 91a393eaf8SRudolf Cornelissen CRTC2W(FIFO, 0x02); 92a393eaf8SRudolf Cornelissen /* Instruct CRTC to fetch new data 'earlier' */ 93a393eaf8SRudolf Cornelissen CRTC2W(FIFO_LWM, 0x40); 94a393eaf8SRudolf Cornelissen LOG(4,("CRTC2: FIFO low-watermark set to $40, burst size 128\n")); 95a393eaf8SRudolf Cornelissen } 96a393eaf8SRudolf Cornelissen else 97a393eaf8SRudolf Cornelissen { 98a393eaf8SRudolf Cornelissen /* BIOS defaults */ 99a393eaf8SRudolf Cornelissen CRTC2W(FIFO, 0x03); 100a393eaf8SRudolf Cornelissen CRTC2W(FIFO_LWM, 0x20); 101a393eaf8SRudolf Cornelissen LOG(4,("CRTC2: FIFO low-watermark set to $20, burst size 256 (BIOS defaults)\n")); 102a393eaf8SRudolf Cornelissen } 103a393eaf8SRudolf Cornelissen } 104a393eaf8SRudolf Cornelissen 105a393eaf8SRudolf Cornelissen return B_OK; 106a393eaf8SRudolf Cornelissen } 107a393eaf8SRudolf Cornelissen 108ff50d0d1SRudolf Cornelissen /* Adjust passed parameters to a valid mode line */ 109ff50d0d1SRudolf Cornelissen status_t nv_crtc2_validate_timing( 110ff50d0d1SRudolf Cornelissen uint16 *hd_e,uint16 *hs_s,uint16 *hs_e,uint16 *ht, 111ff50d0d1SRudolf Cornelissen uint16 *vd_e,uint16 *vs_s,uint16 *vs_e,uint16 *vt 112ff50d0d1SRudolf Cornelissen ) 11308705d96Sshatty { 114ff50d0d1SRudolf Cornelissen /* horizontal */ 115ff50d0d1SRudolf Cornelissen /* make all parameters multiples of 8 */ 116ff50d0d1SRudolf Cornelissen *hd_e &= 0xfff8; 117ff50d0d1SRudolf Cornelissen *hs_s &= 0xfff8; 118ff50d0d1SRudolf Cornelissen *hs_e &= 0xfff8; 119ff50d0d1SRudolf Cornelissen *ht &= 0xfff8; 120ff50d0d1SRudolf Cornelissen 121ff50d0d1SRudolf Cornelissen /* confine to required number of bits, taking logic into account */ 122ff50d0d1SRudolf Cornelissen if (*hd_e > ((0x01ff - 2) << 3)) *hd_e = ((0x01ff - 2) << 3); 123ff50d0d1SRudolf Cornelissen if (*hs_s > ((0x01ff - 1) << 3)) *hs_s = ((0x01ff - 1) << 3); 124ff50d0d1SRudolf Cornelissen if (*hs_e > ( 0x01ff << 3)) *hs_e = ( 0x01ff << 3); 125ff50d0d1SRudolf Cornelissen if (*ht > ((0x01ff + 5) << 3)) *ht = ((0x01ff + 5) << 3); 126ff50d0d1SRudolf Cornelissen 127ff50d0d1SRudolf Cornelissen /* NOTE: keep horizontal timing at multiples of 8! */ 128ff50d0d1SRudolf Cornelissen /* confine to a reasonable width */ 129ff50d0d1SRudolf Cornelissen if (*hd_e < 640) *hd_e = 640; 130ff50d0d1SRudolf Cornelissen if (*hd_e > 2048) *hd_e = 2048; 131ff50d0d1SRudolf Cornelissen 132ff50d0d1SRudolf Cornelissen /* if hor. total does not leave room for a sensible sync pulse, increase it! */ 133ff50d0d1SRudolf Cornelissen if (*ht < (*hd_e + 80)) *ht = (*hd_e + 80); 134ff50d0d1SRudolf Cornelissen 1350ecea71bSRudolf Cornelissen /* if hor. total does not adhere to max. blanking pulse width, decrease it! */ 1360ecea71bSRudolf Cornelissen if (*ht > (*hd_e + 0x3f8)) *ht = (*hd_e + 0x3f8); 1370ecea71bSRudolf Cornelissen 138ff50d0d1SRudolf Cornelissen /* make sure sync pulse is not during display */ 139ff50d0d1SRudolf Cornelissen if (*hs_e > (*ht - 8)) *hs_e = (*ht - 8); 140ff50d0d1SRudolf Cornelissen if (*hs_s < (*hd_e + 8)) *hs_s = (*hd_e + 8); 141ff50d0d1SRudolf Cornelissen 142ff50d0d1SRudolf Cornelissen /* correct sync pulse if it is too long: 143ff50d0d1SRudolf Cornelissen * there are only 5 bits available to save this in the card registers! */ 144ff50d0d1SRudolf Cornelissen if (*hs_e > (*hs_s + 0xf8)) *hs_e = (*hs_s + 0xf8); 145ff50d0d1SRudolf Cornelissen 146ff50d0d1SRudolf Cornelissen /*vertical*/ 147ff50d0d1SRudolf Cornelissen /* confine to required number of bits, taking logic into account */ 148ff50d0d1SRudolf Cornelissen //fixme if needed: on GeForce cards there are 12 instead of 11 bits... 149ff50d0d1SRudolf Cornelissen if (*vd_e > (0x7ff - 2)) *vd_e = (0x7ff - 2); 150ff50d0d1SRudolf Cornelissen if (*vs_s > (0x7ff - 1)) *vs_s = (0x7ff - 1); 151ff50d0d1SRudolf Cornelissen if (*vs_e > 0x7ff ) *vs_e = 0x7ff ; 152ff50d0d1SRudolf Cornelissen if (*vt > (0x7ff + 2)) *vt = (0x7ff + 2); 153ff50d0d1SRudolf Cornelissen 154ff50d0d1SRudolf Cornelissen /* confine to a reasonable height */ 155ff50d0d1SRudolf Cornelissen if (*vd_e < 480) *vd_e = 480; 156ff50d0d1SRudolf Cornelissen if (*vd_e > 1536) *vd_e = 1536; 157ff50d0d1SRudolf Cornelissen 158ff50d0d1SRudolf Cornelissen /*if vertical total does not leave room for a sync pulse, increase it!*/ 159ff50d0d1SRudolf Cornelissen if (*vt < (*vd_e + 3)) *vt = (*vd_e + 3); 160ff50d0d1SRudolf Cornelissen 1610ecea71bSRudolf Cornelissen /* if vert. total does not adhere to max. blanking pulse width, decrease it! */ 1620ecea71bSRudolf Cornelissen if (*vt > (*vd_e + 0xff)) *vt = (*vd_e + 0xff); 1630ecea71bSRudolf Cornelissen 164ff50d0d1SRudolf Cornelissen /* make sure sync pulse is not during display */ 165ff50d0d1SRudolf Cornelissen if (*vs_e > (*vt - 1)) *vs_e = (*vt - 1); 166ff50d0d1SRudolf Cornelissen if (*vs_s < (*vd_e + 1)) *vs_s = (*vd_e + 1); 167ff50d0d1SRudolf Cornelissen 168ff50d0d1SRudolf Cornelissen /* correct sync pulse if it is too long: 169ff50d0d1SRudolf Cornelissen * there are only 4 bits available to save this in the card registers! */ 170ff50d0d1SRudolf Cornelissen if (*vs_e > (*vs_s + 0x0f)) *vs_e = (*vs_s + 0x0f); 171ff50d0d1SRudolf Cornelissen 172ff50d0d1SRudolf Cornelissen return B_OK; 173ff50d0d1SRudolf Cornelissen } 174ff50d0d1SRudolf Cornelissen 175ff50d0d1SRudolf Cornelissen /*set a mode line - inputs are in pixels*/ 176ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_timing(display_mode target) 177ff50d0d1SRudolf Cornelissen { 178ff50d0d1SRudolf Cornelissen uint8 temp; 179ff50d0d1SRudolf Cornelissen 180ff50d0d1SRudolf Cornelissen uint32 htotal; /*total horizontal total VCLKs*/ 181ff50d0d1SRudolf Cornelissen uint32 hdisp_e; /*end of horizontal display (begins at 0)*/ 182ff50d0d1SRudolf Cornelissen uint32 hsync_s; /*begin of horizontal sync pulse*/ 183ff50d0d1SRudolf Cornelissen uint32 hsync_e; /*end of horizontal sync pulse*/ 184ff50d0d1SRudolf Cornelissen uint32 hblnk_s; /*begin horizontal blanking*/ 185ff50d0d1SRudolf Cornelissen uint32 hblnk_e; /*end horizontal blanking*/ 186ff50d0d1SRudolf Cornelissen 187ff50d0d1SRudolf Cornelissen uint32 vtotal; /*total vertical total scanlines*/ 188ff50d0d1SRudolf Cornelissen uint32 vdisp_e; /*end of vertical display*/ 189ff50d0d1SRudolf Cornelissen uint32 vsync_s; /*begin of vertical sync pulse*/ 190ff50d0d1SRudolf Cornelissen uint32 vsync_e; /*end of vertical sync pulse*/ 191ff50d0d1SRudolf Cornelissen uint32 vblnk_s; /*begin vertical blanking*/ 192ff50d0d1SRudolf Cornelissen uint32 vblnk_e; /*end vertical blanking*/ 193ff50d0d1SRudolf Cornelissen 194ff50d0d1SRudolf Cornelissen uint32 linecomp; /*split screen and vdisp_e interrupt*/ 19508705d96Sshatty 19608705d96Sshatty LOG(4,("CRTC2: setting timing\n")); 19708705d96Sshatty 198c9210b6fSRudolf Cornelissen /* setup tuned internal modeline for flatpanel if connected and active */ 1992cb6fc9cSRudolf Cornelissen /* notes: 2002cb6fc9cSRudolf Cornelissen * - the CRTC modeline must end earlier than the panel modeline to keep correct 2012cb6fc9cSRudolf Cornelissen * sync going; 2022cb6fc9cSRudolf Cornelissen * - if the CRTC modeline ends too soon, pixelnoise will occur in 8 (or so) pixel 2032cb6fc9cSRudolf Cornelissen * wide horizontal stripes. This can be observed earliest on fullscreen overlay, 2042cb6fc9cSRudolf Cornelissen * and if it gets worse, also normal desktop output will suffer. The stripes 2052cb6fc9cSRudolf Cornelissen * are mainly visible at the left of the screen, over the entire screen height. */ 206c567e072SRudolf Cornelissen if (si->ps.tmds2_active) 207c567e072SRudolf Cornelissen { 208c567e072SRudolf Cornelissen LOG(2,("CRTC2: DFP active: tuning modeline\n")); 209c567e072SRudolf Cornelissen 210c567e072SRudolf Cornelissen /* horizontal timing */ 21116fc5a30SRudolf Cornelissen target.timing.h_sync_start = 212268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.h_sync_start / ((float)si->ps.p2_timing.h_display)) * 21316fc5a30SRudolf Cornelissen target.timing.h_display)) & 0xfff8; 21416fc5a30SRudolf Cornelissen 21516fc5a30SRudolf Cornelissen target.timing.h_sync_end = 216268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.h_sync_end / ((float)si->ps.p2_timing.h_display)) * 21716fc5a30SRudolf Cornelissen target.timing.h_display)) & 0xfff8; 21816fc5a30SRudolf Cornelissen 21916fc5a30SRudolf Cornelissen target.timing.h_total = 220268624c4SRudolf Cornelissen (((uint16)((si->ps.p2_timing.h_total / ((float)si->ps.p2_timing.h_display)) * 221bef5b86aSRudolf Cornelissen target.timing.h_display)) & 0xfff8) - 8; 22216fc5a30SRudolf Cornelissen 223139d62e9SRudolf Cornelissen /* in native mode the CRTC needs some extra time to keep synced correctly; 224139d62e9SRudolf Cornelissen * OTOH the overlay unit distorts if we reserve too much time! */ 2257ae8e6dcSRudolf Cornelissen if (target.timing.h_display == si->ps.p2_timing.h_display) 22604e6b7ceSRudolf Cornelissen { 227139d62e9SRudolf Cornelissen /* NV11 timing has different constraints than later cards */ 228139d62e9SRudolf Cornelissen if (si->ps.card_type == NV11) 2292cb6fc9cSRudolf Cornelissen target.timing.h_total -= 56; 230139d62e9SRudolf Cornelissen else 231139d62e9SRudolf Cornelissen /* confirmed NV34 with 1680x1050 panel */ 232139d62e9SRudolf Cornelissen target.timing.h_total -= 32; 23304e6b7ceSRudolf Cornelissen } 23404e6b7ceSRudolf Cornelissen 23516fc5a30SRudolf Cornelissen if (target.timing.h_sync_start == target.timing.h_display) 23616fc5a30SRudolf Cornelissen target.timing.h_sync_start += 8; 23716fc5a30SRudolf Cornelissen if (target.timing.h_sync_end == target.timing.h_total) 23816fc5a30SRudolf Cornelissen target.timing.h_sync_end -= 8; 239c567e072SRudolf Cornelissen 240c567e072SRudolf Cornelissen /* vertical timing */ 24116fc5a30SRudolf Cornelissen target.timing.v_sync_start = 242268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_sync_start / ((float)si->ps.p2_timing.v_display)) * 24316fc5a30SRudolf Cornelissen target.timing.v_display)); 24416fc5a30SRudolf Cornelissen 24516fc5a30SRudolf Cornelissen target.timing.v_sync_end = 246268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_sync_end / ((float)si->ps.p2_timing.v_display)) * 24716fc5a30SRudolf Cornelissen target.timing.v_display)); 24816fc5a30SRudolf Cornelissen 24916fc5a30SRudolf Cornelissen target.timing.v_total = 250268624c4SRudolf Cornelissen ((uint16)((si->ps.p2_timing.v_total / ((float)si->ps.p2_timing.v_display)) * 251b97caf33SRudolf Cornelissen target.timing.v_display)) - 1; 25216fc5a30SRudolf Cornelissen 25316fc5a30SRudolf Cornelissen if (target.timing.v_sync_start == target.timing.v_display) 25416fc5a30SRudolf Cornelissen target.timing.v_sync_start += 1; 25516fc5a30SRudolf Cornelissen if (target.timing.v_sync_end == target.timing.v_total) 25616fc5a30SRudolf Cornelissen target.timing.v_sync_end -= 1; 257e6708074SRudolf Cornelissen 258e6708074SRudolf Cornelissen /* disable GPU scaling testmode so automatic scaling will be done */ 259e6708074SRudolf Cornelissen DAC2W(FP_DEBUG1, 0); 260c567e072SRudolf Cornelissen } 261c567e072SRudolf Cornelissen 262ff50d0d1SRudolf Cornelissen /* Modify parameters as required by standard VGA */ 263ff50d0d1SRudolf Cornelissen htotal = ((target.timing.h_total >> 3) - 5); 264ff50d0d1SRudolf Cornelissen hdisp_e = ((target.timing.h_display >> 3) - 1); 265ff50d0d1SRudolf Cornelissen hblnk_s = hdisp_e; 266da3804eeSRudolf Cornelissen hblnk_e = (htotal + 4); 267ff50d0d1SRudolf Cornelissen hsync_s = (target.timing.h_sync_start >> 3); 268ff50d0d1SRudolf Cornelissen hsync_e = (target.timing.h_sync_end >> 3); 269ff50d0d1SRudolf Cornelissen 270ff50d0d1SRudolf Cornelissen vtotal = target.timing.v_total - 2; 271ff50d0d1SRudolf Cornelissen vdisp_e = target.timing.v_display - 1; 272ff50d0d1SRudolf Cornelissen vblnk_s = vdisp_e; 273ff50d0d1SRudolf Cornelissen vblnk_e = (vtotal + 1); 274da3804eeSRudolf Cornelissen vsync_s = target.timing.v_sync_start; 275da3804eeSRudolf Cornelissen vsync_e = target.timing.v_sync_end; 276ff50d0d1SRudolf Cornelissen 277ff50d0d1SRudolf Cornelissen /* prevent memory adress counter from being reset (linecomp may not occur) */ 278ff50d0d1SRudolf Cornelissen linecomp = target.timing.v_display; 279ff50d0d1SRudolf Cornelissen 28064c14e7eSRudolf Cornelissen /* enable access to secondary head */ 28164c14e7eSRudolf Cornelissen set_crtc_owner(1); 282255e5021SRudolf Cornelissen 283a16d55ddSRudolf Cornelissen /* Note for laptop and DVI flatpanels: 284a16d55ddSRudolf Cornelissen * CRTC timing has a seperate set of registers from flatpanel timing. 285a16d55ddSRudolf Cornelissen * The flatpanel timing registers have scaling registers that are used to match 286a16d55ddSRudolf Cornelissen * these two modelines. */ 28708705d96Sshatty { 288a16d55ddSRudolf Cornelissen LOG(4,("CRTC2: Setting full timing...\n")); 28908705d96Sshatty 290ff50d0d1SRudolf Cornelissen /* log the mode that will be set */ 291ff50d0d1SRudolf 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)); 292ff50d0d1SRudolf 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)); 29308705d96Sshatty 294ff50d0d1SRudolf Cornelissen /* actually program the card! */ 295ff50d0d1SRudolf Cornelissen /* unlock CRTC registers at index 0-7 */ 296ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCE, (CRTC2R(VSYNCE) & 0x7f)); 297ff50d0d1SRudolf Cornelissen /* horizontal standard VGA regs */ 298ff50d0d1SRudolf Cornelissen CRTC2W(HTOTAL, (htotal & 0xff)); 299ff50d0d1SRudolf Cornelissen CRTC2W(HDISPE, (hdisp_e & 0xff)); 300ff50d0d1SRudolf Cornelissen CRTC2W(HBLANKS, (hblnk_s & 0xff)); 301ff50d0d1SRudolf Cornelissen /* also unlock vertical retrace registers in advance */ 302ff50d0d1SRudolf Cornelissen CRTC2W(HBLANKE, ((hblnk_e & 0x1f) | 0x80)); 303ff50d0d1SRudolf Cornelissen CRTC2W(HSYNCS, (hsync_s & 0xff)); 304ff50d0d1SRudolf Cornelissen CRTC2W(HSYNCE, ((hsync_e & 0x1f) | ((hblnk_e & 0x20) << 2))); 30508705d96Sshatty 306ff50d0d1SRudolf Cornelissen /* vertical standard VGA regs */ 307ff50d0d1SRudolf Cornelissen CRTC2W(VTOTAL, (vtotal & 0xff)); 308ff50d0d1SRudolf Cornelissen CRTC2W(OVERFLOW, 309ff50d0d1SRudolf Cornelissen ( 310ff50d0d1SRudolf Cornelissen ((vtotal & 0x100) >> (8 - 0)) | ((vtotal & 0x200) >> (9 - 5)) | 311ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x100) >> (8 - 1)) | ((vdisp_e & 0x200) >> (9 - 6)) | 312ff50d0d1SRudolf Cornelissen ((vsync_s & 0x100) >> (8 - 2)) | ((vsync_s & 0x200) >> (9 - 7)) | 313ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x100) >> (8 - 3)) | ((linecomp & 0x100) >> (8 - 4)) 314ff50d0d1SRudolf Cornelissen )); 315ff50d0d1SRudolf Cornelissen CRTC2W(PRROWSCN, 0x00); /* not used */ 316ff50d0d1SRudolf Cornelissen CRTC2W(MAXSCLIN, (((vblnk_s & 0x200) >> (9 - 5)) | ((linecomp & 0x200) >> (9 - 6)))); 317ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCS, (vsync_s & 0xff)); 318ff50d0d1SRudolf Cornelissen CRTC2W(VSYNCE, ((CRTC2R(VSYNCE) & 0xf0) | (vsync_e & 0x0f))); 319ff50d0d1SRudolf Cornelissen CRTC2W(VDISPE, (vdisp_e & 0xff)); 320ff50d0d1SRudolf Cornelissen CRTC2W(VBLANKS, (vblnk_s & 0xff)); 321ff50d0d1SRudolf Cornelissen CRTC2W(VBLANKE, (vblnk_e & 0xff)); 322ff50d0d1SRudolf Cornelissen CRTC2W(LINECOMP, (linecomp & 0xff)); 32308705d96Sshatty 324ff50d0d1SRudolf Cornelissen /* horizontal extended regs */ 325ff50d0d1SRudolf Cornelissen //fixme: we reset bit4. is this correct?? 326ff50d0d1SRudolf Cornelissen CRTC2W(HEB, (CRTC2R(HEB) & 0xe0) | 327ff50d0d1SRudolf Cornelissen ( 328ff50d0d1SRudolf Cornelissen ((htotal & 0x100) >> (8 - 0)) | 329ff50d0d1SRudolf Cornelissen ((hdisp_e & 0x100) >> (8 - 1)) | 330ff50d0d1SRudolf Cornelissen ((hblnk_s & 0x100) >> (8 - 2)) | 331ff50d0d1SRudolf Cornelissen ((hsync_s & 0x100) >> (8 - 3)) 332ff50d0d1SRudolf Cornelissen )); 33308705d96Sshatty 334ff50d0d1SRudolf Cornelissen /* (mostly) vertical extended regs */ 335ff50d0d1SRudolf Cornelissen CRTC2W(LSR, 336ff50d0d1SRudolf Cornelissen ( 337ff50d0d1SRudolf Cornelissen ((vtotal & 0x400) >> (10 - 0)) | 338ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x400) >> (10 - 1)) | 339ff50d0d1SRudolf Cornelissen ((vsync_s & 0x400) >> (10 - 2)) | 340ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x400) >> (10 - 3)) | 341ff50d0d1SRudolf Cornelissen ((hblnk_e & 0x040) >> (6 - 4)) 342ff50d0d1SRudolf Cornelissen //fixme: we still miss one linecomp bit!?! is this it?? 343ff50d0d1SRudolf Cornelissen //| ((linecomp & 0x400) >> 3) 344ff50d0d1SRudolf Cornelissen )); 34508705d96Sshatty 346ff50d0d1SRudolf Cornelissen /* more vertical extended regs */ 347ff50d0d1SRudolf Cornelissen CRTC2W(EXTRA, 348ff50d0d1SRudolf Cornelissen ( 349ff50d0d1SRudolf Cornelissen ((vtotal & 0x800) >> (11 - 0)) | 350ff50d0d1SRudolf Cornelissen ((vdisp_e & 0x800) >> (11 - 2)) | 351ff50d0d1SRudolf Cornelissen ((vsync_s & 0x800) >> (11 - 4)) | 352ff50d0d1SRudolf Cornelissen ((vblnk_s & 0x800) >> (11 - 6)) 353ff50d0d1SRudolf Cornelissen //fixme: do we miss another linecomp bit!?! 354ff50d0d1SRudolf Cornelissen )); 35508705d96Sshatty 356ff50d0d1SRudolf Cornelissen /* setup 'large screen' mode */ 357ff50d0d1SRudolf Cornelissen if (target.timing.h_display >= 1280) 358ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0xfb)); 35908705d96Sshatty else 360ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x04)); 36108705d96Sshatty 362ff50d0d1SRudolf Cornelissen /* setup HSYNC & VSYNC polarity */ 363ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: sync polarity: ")); 364255e5021SRudolf Cornelissen temp = NV_REG8(NV8_MISCR); 365ff50d0d1SRudolf Cornelissen if (target.timing.flags & B_POSITIVE_HSYNC) 366ff50d0d1SRudolf Cornelissen { 367ff50d0d1SRudolf Cornelissen LOG(2,("H:pos ")); 368ff50d0d1SRudolf Cornelissen temp &= ~0x40; 36908705d96Sshatty } 370ff50d0d1SRudolf Cornelissen else 371ff50d0d1SRudolf Cornelissen { 372ff50d0d1SRudolf Cornelissen LOG(2,("H:neg ")); 373ff50d0d1SRudolf Cornelissen temp |= 0x40; 374ff50d0d1SRudolf Cornelissen } 375ff50d0d1SRudolf Cornelissen if (target.timing.flags & B_POSITIVE_VSYNC) 376ff50d0d1SRudolf Cornelissen { 377ff50d0d1SRudolf Cornelissen LOG(2,("V:pos ")); 378ff50d0d1SRudolf Cornelissen temp &= ~0x80; 379ff50d0d1SRudolf Cornelissen } 380ff50d0d1SRudolf Cornelissen else 381ff50d0d1SRudolf Cornelissen { 382ff50d0d1SRudolf Cornelissen LOG(2,("V:neg ")); 383ff50d0d1SRudolf Cornelissen temp |= 0x80; 384ff50d0d1SRudolf Cornelissen } 385255e5021SRudolf Cornelissen NV_REG8(NV8_MISCW) = temp; 386ff50d0d1SRudolf Cornelissen 387255e5021SRudolf Cornelissen LOG(2,(", MISC reg readback: $%02x\n", NV_REG8(NV8_MISCR))); 388ff50d0d1SRudolf Cornelissen } 389ff50d0d1SRudolf Cornelissen 390ff50d0d1SRudolf Cornelissen /* always disable interlaced operation */ 391255e5021SRudolf Cornelissen /* (interlace is supported on upto and including NV10, NV15, and NV30 and up) */ 392ff50d0d1SRudolf Cornelissen CRTC2W(INTERLACE, 0xff); 39308705d96Sshatty 394bc9c6041SRudolf Cornelissen /* disable CRTC slaved mode unless a panel is in use */ 395bc9c6041SRudolf Cornelissen // fixme: this kills TVout when it was in use... 396bc9c6041SRudolf Cornelissen if (!si->ps.tmds2_active) CRTC2W(PIXEL, (CRTC2R(PIXEL) & 0x7f)); 397bc9c6041SRudolf Cornelissen 3981e37a9acSRudolf Cornelissen /* setup flatpanel if connected and active */ 399a16d55ddSRudolf Cornelissen if (si->ps.tmds2_active) 400a16d55ddSRudolf Cornelissen { 401a16d55ddSRudolf Cornelissen uint32 iscale_x, iscale_y; 402a16d55ddSRudolf Cornelissen 403a973fe9eSRudolf Cornelissen /* calculate inverse scaling factors used by hardware in 20.12 format */ 4040fccffc2SRudolf Cornelissen iscale_x = (((1 << 12) * target.timing.h_display) / si->ps.p2_timing.h_display); 4050fccffc2SRudolf Cornelissen iscale_y = (((1 << 12) * target.timing.v_display) / si->ps.p2_timing.v_display); 4061e37a9acSRudolf Cornelissen 4071e37a9acSRudolf Cornelissen /* unblock flatpanel timing programming (or something like that..) */ 4081e37a9acSRudolf Cornelissen CRTC2W(FP_HTIMING, 0); 4091e37a9acSRudolf Cornelissen CRTC2W(FP_VTIMING, 0); 410e6708074SRudolf Cornelissen LOG(2,("CRTC2: FP_HTIMING reg readback: $%02x\n", CRTC2R(FP_HTIMING))); 411e6708074SRudolf Cornelissen LOG(2,("CRTC2: FP_VTIMING reg readback: $%02x\n", CRTC2R(FP_VTIMING))); 4121e37a9acSRudolf Cornelissen 413a973fe9eSRudolf Cornelissen /* enable full width visibility on flatpanel */ 414a973fe9eSRudolf Cornelissen DAC2W(FP_HVALID_S, 0); 4150fccffc2SRudolf Cornelissen DAC2W(FP_HVALID_E, (si->ps.p2_timing.h_display - 1)); 416a973fe9eSRudolf Cornelissen /* enable full height visibility on flatpanel */ 417a973fe9eSRudolf Cornelissen DAC2W(FP_VVALID_S, 0); 4180fccffc2SRudolf Cornelissen DAC2W(FP_VVALID_E, (si->ps.p2_timing.v_display - 1)); 419a973fe9eSRudolf Cornelissen 4204709c2c8SRudolf Cornelissen /* nVidia cards support upscaling except on ??? */ 4214709c2c8SRudolf Cornelissen /* NV11 cards can upscale after all! */ 422e6708074SRudolf Cornelissen if (0)//si->ps.card_type == NV11) 4231e37a9acSRudolf Cornelissen { 4241e37a9acSRudolf Cornelissen /* disable last fetched line limiting */ 4251e37a9acSRudolf Cornelissen DAC2W(FP_DEBUG2, 0x00000000); 426c567e072SRudolf Cornelissen /* inform panel to scale if needed */ 427c567e072SRudolf Cornelissen if ((iscale_x != (1 << 12)) || (iscale_y != (1 << 12))) 428c567e072SRudolf Cornelissen { 429c567e072SRudolf Cornelissen LOG(2,("CRTC2: DFP needs to do scaling\n")); 4301e37a9acSRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) | 0x00000100)); 4311e37a9acSRudolf Cornelissen } 4321e37a9acSRudolf Cornelissen else 4331e37a9acSRudolf Cornelissen { 434c567e072SRudolf Cornelissen LOG(2,("CRTC2: no scaling for DFP needed\n")); 435c567e072SRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) & 0xfffffeff)); 436c567e072SRudolf Cornelissen } 437c567e072SRudolf Cornelissen } 438c567e072SRudolf Cornelissen else 439c567e072SRudolf Cornelissen { 440a973fe9eSRudolf Cornelissen float dm_aspect; 441a973fe9eSRudolf Cornelissen 442c567e072SRudolf Cornelissen LOG(2,("CRTC2: GPU scales for DFP if needed\n")); 4431e37a9acSRudolf Cornelissen 444a973fe9eSRudolf Cornelissen /* calculate display mode aspect */ 445a973fe9eSRudolf Cornelissen dm_aspect = (target.timing.h_display / ((float)target.timing.v_display)); 446a973fe9eSRudolf Cornelissen 447a16d55ddSRudolf Cornelissen /* limit last fetched line if vertical scaling is done */ 4481e37a9acSRudolf Cornelissen if (iscale_y != (1 << 12)) 449a16d55ddSRudolf Cornelissen DAC2W(FP_DEBUG2, ((1 << 28) | ((target.timing.v_display - 1) << 16))); 450a16d55ddSRudolf Cornelissen else 451a16d55ddSRudolf Cornelissen DAC2W(FP_DEBUG2, 0x00000000); 4521e37a9acSRudolf Cornelissen 4531e37a9acSRudolf Cornelissen /* inform panel not to scale */ 4541e37a9acSRudolf Cornelissen DAC2W(FP_TG_CTRL, (DAC2R(FP_TG_CTRL) & 0xfffffeff)); 455c65998faSRudolf Cornelissen 456c65998faSRudolf Cornelissen /* GPU scaling is automatically setup by hardware, so only modify this 457c65998faSRudolf Cornelissen * scalingfactor for non 4:3 (1.33) aspect panels; 458c65998faSRudolf Cornelissen * let's consider 1280x1024 1:33 aspect (it's 1.25 aspect actually!) */ 459c65998faSRudolf Cornelissen 460a973fe9eSRudolf Cornelissen /* correct for widescreen panels relative to mode... 461a973fe9eSRudolf Cornelissen * (so if panel is more widescreen than mode being set) */ 462a973fe9eSRudolf Cornelissen /* BTW: known widescreen panels: 463c65998faSRudolf Cornelissen * 1280 x 800 (1.60), 464c65998faSRudolf Cornelissen * 1440 x 900 (1.60), 465b97caf33SRudolf Cornelissen * 1680 x 1050 (1.60), 466b97caf33SRudolf Cornelissen * 1920 x 1200 (1.60). */ 467c65998faSRudolf Cornelissen /* known 4:3 aspect non-standard resolution panels: 468c65998faSRudolf Cornelissen * 1400 x 1050 (1.33). */ 469a973fe9eSRudolf Cornelissen /* NOTE: 470a973fe9eSRudolf Cornelissen * allow 0.10 difference so 1280x1024 panels will be used fullscreen! */ 471a973fe9eSRudolf Cornelissen if ((iscale_x != (1 << 12)) && (si->ps.panel2_aspect > (dm_aspect + 0.10))) 472c65998faSRudolf Cornelissen { 473a973fe9eSRudolf Cornelissen uint16 diff; 474a973fe9eSRudolf Cornelissen 475a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: (relative) widescreen panel: tuning horizontal scaling\n")); 476a973fe9eSRudolf Cornelissen 477a973fe9eSRudolf Cornelissen /* X-scaling should be the same as Y-scaling */ 478a973fe9eSRudolf Cornelissen iscale_x = iscale_y; 479c65998faSRudolf Cornelissen /* enable testmode (b12) and program new X-scaling factor */ 480c65998faSRudolf Cornelissen DAC2W(FP_DEBUG1, (((iscale_x >> 1) & 0x00000fff) | (1 << 12))); 481a973fe9eSRudolf Cornelissen /* center/cut-off left and right side of screen */ 4820fccffc2SRudolf Cornelissen diff = ((si->ps.p2_timing.h_display - 48379098812SRudolf Cornelissen ((target.timing.h_display * (1 << 12)) / iscale_x)) 484a973fe9eSRudolf Cornelissen / 2); 485a973fe9eSRudolf Cornelissen DAC2W(FP_HVALID_S, diff); 4860fccffc2SRudolf Cornelissen DAC2W(FP_HVALID_E, ((si->ps.p2_timing.h_display - diff) - 1)); 487c65998faSRudolf Cornelissen } 488c65998faSRudolf Cornelissen /* correct for portrait panels... */ 489a973fe9eSRudolf Cornelissen /* NOTE: 490a973fe9eSRudolf Cornelissen * allow 0.10 difference so 1280x1024 panels will be used fullscreen! */ 491a973fe9eSRudolf Cornelissen if ((iscale_y != (1 << 12)) && (si->ps.panel2_aspect < (dm_aspect - 0.10))) 492c65998faSRudolf Cornelissen { 493a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: (relative) portrait panel: should tune vertical scaling\n")); 494a973fe9eSRudolf Cornelissen /* fixme: implement if this kind of portrait panels exist on nVidia... */ 495c65998faSRudolf Cornelissen } 4961e37a9acSRudolf Cornelissen } 4971e37a9acSRudolf Cornelissen 4981e37a9acSRudolf Cornelissen /* do some logging.. */ 499a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_HVALID_S reg readback: $%08x\n", DAC2R(FP_HVALID_S))); 500a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_HVALID_E reg readback: $%08x\n", DAC2R(FP_HVALID_E))); 501a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_VVALID_S reg readback: $%08x\n", DAC2R(FP_VVALID_S))); 502a973fe9eSRudolf Cornelissen LOG(2,("CRTC2: FP_VVALID_E reg readback: $%08x\n", DAC2R(FP_VVALID_E))); 5031e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG0 reg readback: $%08x\n", DAC2R(FP_DEBUG0))); 5041e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG1 reg readback: $%08x\n", DAC2R(FP_DEBUG1))); 5051e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG2 reg readback: $%08x\n", DAC2R(FP_DEBUG2))); 5061e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_DEBUG3 reg readback: $%08x\n", DAC2R(FP_DEBUG3))); 5071e37a9acSRudolf Cornelissen LOG(2,("CRTC2: FP_TG_CTRL reg readback: $%08x\n", DAC2R(FP_TG_CTRL))); 508a16d55ddSRudolf Cornelissen } 509a16d55ddSRudolf Cornelissen 51008705d96Sshatty return B_OK; 51108705d96Sshatty } 51208705d96Sshatty 513ff50d0d1SRudolf Cornelissen status_t nv_crtc2_depth(int mode) 51408705d96Sshatty { 515ff50d0d1SRudolf Cornelissen uint8 viddelay = 0; 516ff50d0d1SRudolf Cornelissen uint32 genctrl = 0; 517ff50d0d1SRudolf Cornelissen 518ff50d0d1SRudolf Cornelissen /* set VCLK scaling */ 51908705d96Sshatty switch(mode) 52008705d96Sshatty { 521ff50d0d1SRudolf Cornelissen case BPP8: 522ff50d0d1SRudolf Cornelissen viddelay = 0x01; 523ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 reset: 'direct mode' */ 524ff50d0d1SRudolf Cornelissen genctrl = 0x00101100; 52508705d96Sshatty break; 526ff50d0d1SRudolf Cornelissen case BPP15: 527ff50d0d1SRudolf Cornelissen viddelay = 0x02; 528ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 529ff50d0d1SRudolf Cornelissen genctrl = 0x00100130; 530ff50d0d1SRudolf Cornelissen break; 531ff50d0d1SRudolf Cornelissen case BPP16: 532ff50d0d1SRudolf Cornelissen viddelay = 0x02; 533ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 534ff50d0d1SRudolf Cornelissen genctrl = 0x00101130; 535ff50d0d1SRudolf Cornelissen break; 536ff50d0d1SRudolf Cornelissen case BPP24: 537ff50d0d1SRudolf Cornelissen viddelay = 0x03; 538ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 539ff50d0d1SRudolf Cornelissen genctrl = 0x00100130; 540ff50d0d1SRudolf Cornelissen break; 541ff50d0d1SRudolf Cornelissen case BPP32: 542ff50d0d1SRudolf Cornelissen viddelay = 0x03; 543ff50d0d1SRudolf Cornelissen /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */ 544ff50d0d1SRudolf Cornelissen genctrl = 0x00101130; 54508705d96Sshatty break; 54608705d96Sshatty } 54764c14e7eSRudolf Cornelissen /* enable access to secondary head */ 54864c14e7eSRudolf Cornelissen set_crtc_owner(1); 549255e5021SRudolf Cornelissen 550ff50d0d1SRudolf Cornelissen CRTC2W(PIXEL, ((CRTC2R(PIXEL) & 0xfc) | viddelay)); 551ff50d0d1SRudolf Cornelissen DAC2W(GENCTRL, genctrl); 55208705d96Sshatty 55308705d96Sshatty return B_OK; 55408705d96Sshatty } 55508705d96Sshatty 5564022652cSRudolf Cornelissen status_t nv_crtc2_dpms(bool display, bool h, bool v, bool do_panel) 55708705d96Sshatty { 558d97178c9SRudolf Cornelissen uint8 temp; 5594022652cSRudolf Cornelissen char msg[100]; 560ff50d0d1SRudolf Cornelissen 5614022652cSRudolf Cornelissen sprintf(msg, "CRTC2: setting DPMS: "); 562ff50d0d1SRudolf Cornelissen 56364c14e7eSRudolf Cornelissen /* enable access to secondary head */ 56464c14e7eSRudolf Cornelissen set_crtc_owner(1); 565255e5021SRudolf Cornelissen 566ff50d0d1SRudolf Cornelissen /* start synchronous reset: required before turning screen off! */ 567d97178c9SRudolf Cornelissen SEQW(RESET, 0x01); 568ff50d0d1SRudolf Cornelissen 569d97178c9SRudolf Cornelissen temp = SEQR(CLKMODE); 570ff50d0d1SRudolf Cornelissen if (display) 57108705d96Sshatty { 572ecaef637SRudolf Cornelissen /* turn screen on */ 573d97178c9SRudolf Cornelissen SEQW(CLKMODE, (temp & ~0x20)); 574ff50d0d1SRudolf Cornelissen 575ecaef637SRudolf Cornelissen /* end synchronous reset because display should be enabled */ 576d97178c9SRudolf Cornelissen SEQW(RESET, 0x03); 577ff50d0d1SRudolf Cornelissen 57884cbe0e3SRudolf Cornelissen if (do_panel && si->ps.tmds2_active) 57984cbe0e3SRudolf Cornelissen { 58084cbe0e3SRudolf Cornelissen if (!si->ps.laptop) 581b4f28c26SRudolf Cornelissen { 582ecaef637SRudolf Cornelissen /* restore original panelsync and panel-enable */ 583ecaef637SRudolf Cornelissen uint32 panelsync = 0x00000000; 584ecaef637SRudolf Cornelissen if(si->ps.p2_timing.flags & B_POSITIVE_VSYNC) panelsync |= 0x00000001; 585ecaef637SRudolf Cornelissen if(si->ps.p2_timing.flags & B_POSITIVE_HSYNC) panelsync |= 0x00000010; 586ecaef637SRudolf Cornelissen /* display enable polarity (not an official flag) */ 587ecaef637SRudolf Cornelissen if(si->ps.p2_timing.flags & B_BLANK_PEDESTAL) panelsync |= 0x10000000; 588ecaef637SRudolf Cornelissen DAC2W(FP_TG_CTRL, ((DAC2R(FP_TG_CTRL) & 0xcfffffcc) | panelsync)); 589ecaef637SRudolf Cornelissen 590ecaef637SRudolf Cornelissen //fixme?: looks like we don't need this after all: 591b4f28c26SRudolf Cornelissen /* powerup both LVDS (laptop panellink) and TMDS (DVI panellink) 592b4f28c26SRudolf Cornelissen * internal transmitters... */ 5938addb7c3SRudolf Cornelissen /* note: 5948addb7c3SRudolf Cornelissen * the powerbits in this register are hardwired to the DVI connectors, 5958addb7c3SRudolf Cornelissen * instead of to the DACs! (confirmed NV34) */ 5968addb7c3SRudolf Cornelissen //fixme... 597ecaef637SRudolf Cornelissen //DAC2W(FP_DEBUG0, (DAC2R(FP_DEBUG0) & 0xcfffffff)); 598b4f28c26SRudolf Cornelissen /* ... and powerup external TMDS transmitter if it exists */ 599ed391abaSRudolf Cornelissen /* (confirmed OK on NV28 and NV34) */ 600ecaef637SRudolf Cornelissen //CRTC2W(0x59, (CRTC2R(0x59) | 0x01)); 6014022652cSRudolf Cornelissen 6024022652cSRudolf Cornelissen sprintf(msg, "%s(panel-)", msg); 603b4f28c26SRudolf Cornelissen } 60484cbe0e3SRudolf Cornelissen else 60584cbe0e3SRudolf Cornelissen { 60684cbe0e3SRudolf Cornelissen //fixme: see if LVDS head can be determined with two panels there... 60784cbe0e3SRudolf Cornelissen if (!si->ps.tmds1_active && (si->ps.card_type != NV11)) 60884cbe0e3SRudolf Cornelissen { 60984cbe0e3SRudolf Cornelissen /* b2 = 0 = enable laptop panel backlight */ 61084cbe0e3SRudolf Cornelissen /* note: this seems to be a write-only register. */ 61184cbe0e3SRudolf Cornelissen NV_REG32(NV32_LVDS_PWR) = 0x00000003; 61284cbe0e3SRudolf Cornelissen 61384cbe0e3SRudolf Cornelissen sprintf(msg, "%s(panel-)", msg); 61484cbe0e3SRudolf Cornelissen } 61584cbe0e3SRudolf Cornelissen } 61684cbe0e3SRudolf Cornelissen } 6174709c2c8SRudolf Cornelissen 6184022652cSRudolf Cornelissen sprintf(msg, "%sdisplay on, ", msg); 61908705d96Sshatty } 62008705d96Sshatty else 62108705d96Sshatty { 622ecaef637SRudolf Cornelissen /* turn screen off */ 623d97178c9SRudolf Cornelissen SEQW(CLKMODE, (temp | 0x20)); 624ff50d0d1SRudolf Cornelissen 62584cbe0e3SRudolf Cornelissen if (do_panel && si->ps.tmds2_active) 62684cbe0e3SRudolf Cornelissen { 62784cbe0e3SRudolf Cornelissen if (!si->ps.laptop) 628b4f28c26SRudolf Cornelissen { 629ecaef637SRudolf Cornelissen /* shutoff panelsync and disable panel */ 630ecaef637SRudolf Cornelissen DAC2W(FP_TG_CTRL, ((DAC2R(FP_TG_CTRL) & 0xcfffffcc) | 0x20000022)); 631ecaef637SRudolf Cornelissen 632ecaef637SRudolf Cornelissen //fixme?: looks like we don't need this after all: 633b4f28c26SRudolf Cornelissen /* powerdown both LVDS (laptop panellink) and TMDS (DVI panellink) 634b4f28c26SRudolf Cornelissen * internal transmitters... */ 6358addb7c3SRudolf Cornelissen /* note: 6368addb7c3SRudolf Cornelissen * the powerbits in this register are hardwired to the DVI connectors, 6378addb7c3SRudolf Cornelissen * instead of to the DACs! (confirmed NV34) */ 6388addb7c3SRudolf Cornelissen //fixme... 639ecaef637SRudolf Cornelissen //DAC2W(FP_DEBUG0, (DAC2R(FP_DEBUG0) | 0x30000000)); 640b4f28c26SRudolf Cornelissen /* ... and powerdown external TMDS transmitter if it exists */ 641ed391abaSRudolf Cornelissen /* (confirmed OK on NV28 and NV34) */ 642ecaef637SRudolf Cornelissen //CRTC2W(0x59, (CRTC2R(0x59) & 0xfe)); 6434022652cSRudolf Cornelissen 6444022652cSRudolf Cornelissen sprintf(msg, "%s(panel-)", msg); 645b4f28c26SRudolf Cornelissen } 64684cbe0e3SRudolf Cornelissen else 64784cbe0e3SRudolf Cornelissen { 64884cbe0e3SRudolf Cornelissen //fixme: see if LVDS head can be determined with two panels there... 64984cbe0e3SRudolf Cornelissen if (!si->ps.tmds1_active && (si->ps.card_type != NV11)) 65084cbe0e3SRudolf Cornelissen { 65184cbe0e3SRudolf Cornelissen /* b2 = 1 = disable laptop panel backlight */ 65284cbe0e3SRudolf Cornelissen /* note: this seems to be a write-only register. */ 65384cbe0e3SRudolf Cornelissen NV_REG32(NV32_LVDS_PWR) = 0x00000007; 65484cbe0e3SRudolf Cornelissen 65584cbe0e3SRudolf Cornelissen sprintf(msg, "%s(panel-)", msg); 65684cbe0e3SRudolf Cornelissen } 65784cbe0e3SRudolf Cornelissen } 65884cbe0e3SRudolf Cornelissen } 6594709c2c8SRudolf Cornelissen 6604022652cSRudolf Cornelissen sprintf(msg, "%sdisplay off, ", msg); 66108705d96Sshatty } 66208705d96Sshatty 663ff50d0d1SRudolf Cornelissen if (h) 66408705d96Sshatty { 665ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0x7f)); 6664022652cSRudolf Cornelissen sprintf(msg, "%shsync enabled, ", msg); 667ff50d0d1SRudolf Cornelissen } 668ff50d0d1SRudolf Cornelissen else 669ff50d0d1SRudolf Cornelissen { 670ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x80)); 6714022652cSRudolf Cornelissen sprintf(msg, "%shsync disabled, ", msg); 672ff50d0d1SRudolf Cornelissen } 673ff50d0d1SRudolf Cornelissen if (v) 674ff50d0d1SRudolf Cornelissen { 675ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0xbf)); 6764022652cSRudolf Cornelissen sprintf(msg, "%svsync enabled\n", msg); 677ff50d0d1SRudolf Cornelissen } 678ff50d0d1SRudolf Cornelissen else 679ff50d0d1SRudolf Cornelissen { 680ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) | 0x40)); 6814022652cSRudolf Cornelissen sprintf(msg, "%svsync disabled\n", msg); 682ff50d0d1SRudolf Cornelissen } 68308705d96Sshatty 6844022652cSRudolf Cornelissen LOG(4, (msg)); 6854022652cSRudolf Cornelissen 68608705d96Sshatty return B_OK; 68708705d96Sshatty } 68808705d96Sshatty 689ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_display_pitch() 69008705d96Sshatty { 69108705d96Sshatty uint32 offset; 69208705d96Sshatty 69308705d96Sshatty LOG(4,("CRTC2: setting card pitch (offset between lines)\n")); 69408705d96Sshatty 69508705d96Sshatty /* figure out offset value hardware needs */ 696ff50d0d1SRudolf Cornelissen offset = si->fbc.bytes_per_row / 8; 69708705d96Sshatty 698ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: offset register set to: $%04x\n", offset)); 69908705d96Sshatty 70064c14e7eSRudolf Cornelissen /* enable access to secondary head */ 70164c14e7eSRudolf Cornelissen set_crtc_owner(1); 702255e5021SRudolf Cornelissen 703b4bdc2b6SRudolf Cornelissen /* program the card */ 704ff50d0d1SRudolf Cornelissen CRTC2W(PITCHL, (offset & 0x00ff)); 705ff50d0d1SRudolf Cornelissen CRTC2W(REPAINT0, ((CRTC2R(REPAINT0) & 0x1f) | ((offset & 0x0700) >> 3))); 706ff50d0d1SRudolf Cornelissen 70708705d96Sshatty return B_OK; 70808705d96Sshatty } 70908705d96Sshatty 710ff50d0d1SRudolf Cornelissen status_t nv_crtc2_set_display_start(uint32 startadd,uint8 bpp) 71108705d96Sshatty { 712e0dd08e8SRudolf Cornelissen uint32 timeout = 0; 71308705d96Sshatty 714ff50d0d1SRudolf Cornelissen LOG(4,("CRTC2: setting card RAM to be displayed bpp %d\n", bpp)); 71508705d96Sshatty 716ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: startadd: $%08x\n", startadd)); 717ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: frameRAM: $%08x\n", si->framebuffer)); 718ff50d0d1SRudolf Cornelissen LOG(2,("CRTC2: framebuffer: $%08x\n", si->fbc.frame_buffer)); 719ff50d0d1SRudolf Cornelissen 720e0dd08e8SRudolf Cornelissen /* we might have no retraces during setmode! */ 721e0dd08e8SRudolf Cornelissen /* wait 25mS max. for retrace to occur (refresh > 40Hz) */ 722e0dd08e8SRudolf Cornelissen while (((NV_REG32(NV32_RASTER2) & 0x000007ff) < si->dm.timing.v_display) && 723e0dd08e8SRudolf Cornelissen (timeout < (25000/10))) 724e0dd08e8SRudolf Cornelissen { 725e0dd08e8SRudolf Cornelissen /* don't snooze much longer or retrace might get missed! */ 726e0dd08e8SRudolf Cornelissen snooze(10); 727e0dd08e8SRudolf Cornelissen timeout++; 728e0dd08e8SRudolf Cornelissen } 729ff50d0d1SRudolf Cornelissen 73064c14e7eSRudolf Cornelissen /* enable access to secondary head */ 73164c14e7eSRudolf Cornelissen set_crtc_owner(1); 732255e5021SRudolf Cornelissen 733ff50d0d1SRudolf Cornelissen /* upto 4Gb RAM adressing: must be used on NV10 and later! */ 734ff50d0d1SRudolf Cornelissen /* NOTE: 735ff50d0d1SRudolf Cornelissen * While this register also exists on pre-NV10 cards, it will 736ff50d0d1SRudolf Cornelissen * wrap-around at 16Mb boundaries!! */ 737ff50d0d1SRudolf Cornelissen 738ff50d0d1SRudolf Cornelissen /* 30bit adress in 32bit words */ 739ff50d0d1SRudolf Cornelissen NV_REG32(NV32_NV10FB2STADD32) = (startadd & 0xfffffffc); 740ff50d0d1SRudolf Cornelissen 741bc9d4aceSRudolf Cornelissen /* set byte adress: (b0 - 1) */ 742e0dd08e8SRudolf Cornelissen ATB2W(HORPIXPAN, ((startadd & 0x00000003) << 1)); 743ff50d0d1SRudolf Cornelissen 744ff50d0d1SRudolf Cornelissen return B_OK; 745ff50d0d1SRudolf Cornelissen } 746ff50d0d1SRudolf Cornelissen 747ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_init() 748ff50d0d1SRudolf Cornelissen { 749ff50d0d1SRudolf Cornelissen int i; 750eab3aa0cSRudolf Cornelissen vuint32 * fb; 751ff50d0d1SRudolf Cornelissen /* cursor bitmap will be stored at the start of the framebuffer */ 752ff50d0d1SRudolf Cornelissen const uint32 curadd = 0; 753ff50d0d1SRudolf Cornelissen 75464c14e7eSRudolf Cornelissen /* enable access to secondary head */ 75564c14e7eSRudolf Cornelissen set_crtc_owner(1); 756255e5021SRudolf Cornelissen 757ff50d0d1SRudolf Cornelissen /* set cursor bitmap adress ... */ 758255e5021SRudolf Cornelissen if (si->ps.laptop) 759ff50d0d1SRudolf Cornelissen { 760ff50d0d1SRudolf Cornelissen /* must be used this way on pre-NV10 and on all 'Go' cards! */ 761ff50d0d1SRudolf Cornelissen 762ff50d0d1SRudolf Cornelissen /* cursorbitmap must start on 2Kbyte boundary: */ 763ff50d0d1SRudolf Cornelissen /* set adress bit11-16, and set 'no doublescan' (registerbit 1 = 0) */ 764ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, ((curadd & 0x0001f800) >> 9)); 765ff50d0d1SRudolf Cornelissen /* set adress bit17-23, and set graphics mode cursor(?) (registerbit 7 = 1) */ 766ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL1, (((curadd & 0x00fe0000) >> 17) | 0x80)); 767ff50d0d1SRudolf Cornelissen /* set adress bit24-31 */ 768ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL2, ((curadd & 0xff000000) >> 24)); 76908705d96Sshatty } 77008705d96Sshatty else 77108705d96Sshatty { 772ff50d0d1SRudolf Cornelissen /* upto 4Gb RAM adressing: 773ff50d0d1SRudolf Cornelissen * can be used on NV10 and later (except for 'Go' cards)! */ 774ff50d0d1SRudolf Cornelissen /* NOTE: 775ff50d0d1SRudolf Cornelissen * This register does not exist on pre-NV10 and 'Go' cards. */ 776ff50d0d1SRudolf Cornelissen 777ff50d0d1SRudolf Cornelissen /* cursorbitmap must still start on 2Kbyte boundary: */ 778ff50d0d1SRudolf Cornelissen NV_REG32(NV32_NV10CUR2ADD32) = (curadd & 0xfffff800); 77908705d96Sshatty } 78008705d96Sshatty 781ff50d0d1SRudolf Cornelissen /* set cursor colour: not needed because of direct nature of cursor bitmap. */ 782ff50d0d1SRudolf Cornelissen 783ff50d0d1SRudolf Cornelissen /*clear cursor*/ 784eab3aa0cSRudolf Cornelissen fb = (vuint32 *) si->framebuffer + curadd; 785ff50d0d1SRudolf Cornelissen for (i=0;i<(2048/4);i++) 786ff50d0d1SRudolf Cornelissen { 787ff50d0d1SRudolf Cornelissen fb[i]=0; 788ff50d0d1SRudolf Cornelissen } 789ff50d0d1SRudolf Cornelissen 790ff50d0d1SRudolf Cornelissen /* select 32x32 pixel, 16bit color cursorbitmap, no doublescan */ 791ff50d0d1SRudolf Cornelissen NV_REG32(NV32_2CURCONF) = 0x02000100; 792ff50d0d1SRudolf Cornelissen 793df7dbd1dSRudolf Cornelissen /* activate hardware-sync between cursor updates and vertical retrace */ 794df7dbd1dSRudolf Cornelissen DAC2W(NV10_CURSYNC, (DAC2R(NV10_CURSYNC) | 0x02000000)); 795df7dbd1dSRudolf Cornelissen 796ff50d0d1SRudolf Cornelissen /* activate hardware cursor */ 797255e5021SRudolf Cornelissen nv_crtc2_cursor_show(); 798ff50d0d1SRudolf Cornelissen 799ff50d0d1SRudolf Cornelissen return B_OK; 800ff50d0d1SRudolf Cornelissen } 801ff50d0d1SRudolf Cornelissen 802ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_show() 803ff50d0d1SRudolf Cornelissen { 804255e5021SRudolf Cornelissen LOG(4,("CRTC2: enabling cursor\n")); 805255e5021SRudolf Cornelissen 80664c14e7eSRudolf Cornelissen /* enable access to secondary head */ 80764c14e7eSRudolf Cornelissen set_crtc_owner(1); 808255e5021SRudolf Cornelissen 809ff50d0d1SRudolf Cornelissen /* b0 = 1 enables cursor */ 810ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, (CRTC2R(CURCTL0) | 0x01)); 811ff50d0d1SRudolf Cornelissen 81211058c2fSRudolf Cornelissen /* workaround for hardware bug confirmed existing on NV43: 81311058c2fSRudolf Cornelissen * Cursor visibility is not updated without a position update if its hardware 81411058c2fSRudolf Cornelissen * retrace sync is enabled. */ 81511058c2fSRudolf Cornelissen if (si->ps.card_arch == NV40A) DAC2W(CURPOS, (DAC2R(CURPOS))); 81611058c2fSRudolf Cornelissen 817ff50d0d1SRudolf Cornelissen return B_OK; 818ff50d0d1SRudolf Cornelissen } 819ff50d0d1SRudolf Cornelissen 820ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_hide() 821ff50d0d1SRudolf Cornelissen { 822255e5021SRudolf Cornelissen LOG(4,("CRTC2: disabling cursor\n")); 823255e5021SRudolf Cornelissen 82464c14e7eSRudolf Cornelissen /* enable access to secondary head */ 82564c14e7eSRudolf Cornelissen set_crtc_owner(1); 826255e5021SRudolf Cornelissen 827ff50d0d1SRudolf Cornelissen /* b0 = 0 disables cursor */ 828ff50d0d1SRudolf Cornelissen CRTC2W(CURCTL0, (CRTC2R(CURCTL0) & 0xfe)); 829ff50d0d1SRudolf Cornelissen 83011058c2fSRudolf Cornelissen /* workaround for hardware bug confirmed existing on NV43: 83111058c2fSRudolf Cornelissen * Cursor visibility is not updated without a position update if its hardware 83211058c2fSRudolf Cornelissen * retrace sync is enabled. */ 83311058c2fSRudolf Cornelissen if (si->ps.card_arch == NV40A) DAC2W(CURPOS, (DAC2R(CURPOS))); 83411058c2fSRudolf Cornelissen 835ff50d0d1SRudolf Cornelissen return B_OK; 836ff50d0d1SRudolf Cornelissen } 837ff50d0d1SRudolf Cornelissen 838ff50d0d1SRudolf Cornelissen /*set up cursor shape*/ 839ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_define(uint8* andMask,uint8* xorMask) 840ff50d0d1SRudolf Cornelissen { 841ff50d0d1SRudolf Cornelissen int x, y; 842ff50d0d1SRudolf Cornelissen uint8 b; 843eab3aa0cSRudolf Cornelissen vuint16 *cursor; 844ff50d0d1SRudolf Cornelissen uint16 pixel; 845ff50d0d1SRudolf Cornelissen 846ff50d0d1SRudolf Cornelissen /* get a pointer to the cursor */ 847eab3aa0cSRudolf Cornelissen cursor = (vuint16*) si->framebuffer; 848ff50d0d1SRudolf Cornelissen 849ff50d0d1SRudolf Cornelissen /* draw the cursor */ 850ff50d0d1SRudolf Cornelissen /* (Nvidia cards have a RGB15 direct color cursor bitmap, bit #16 is transparancy) */ 851ff50d0d1SRudolf Cornelissen for (y = 0; y < 16; y++) 852ff50d0d1SRudolf Cornelissen { 853ff50d0d1SRudolf Cornelissen b = 0x80; 854ff50d0d1SRudolf Cornelissen for (x = 0; x < 8; x++) 855ff50d0d1SRudolf Cornelissen { 856ff50d0d1SRudolf Cornelissen /* preset transparant */ 857ff50d0d1SRudolf Cornelissen pixel = 0x0000; 858ff50d0d1SRudolf Cornelissen /* set white if requested */ 859ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (!(*xorMask & b))) pixel = 0xffff; 860ff50d0d1SRudolf Cornelissen /* set black if requested */ 861ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (*xorMask & b)) pixel = 0x8000; 862ff50d0d1SRudolf Cornelissen /* set invert if requested */ 863ff50d0d1SRudolf Cornelissen if ( (*andMask & b) && (*xorMask & b)) pixel = 0x7fff; 864ff50d0d1SRudolf Cornelissen /* place the pixel in the bitmap */ 865ff50d0d1SRudolf Cornelissen cursor[x + (y * 32)] = pixel; 866ff50d0d1SRudolf Cornelissen b >>= 1; 867ff50d0d1SRudolf Cornelissen } 868ff50d0d1SRudolf Cornelissen xorMask++; 869ff50d0d1SRudolf Cornelissen andMask++; 870ff50d0d1SRudolf Cornelissen b = 0x80; 871ff50d0d1SRudolf Cornelissen for (; x < 16; x++) 872ff50d0d1SRudolf Cornelissen { 873ff50d0d1SRudolf Cornelissen /* preset transparant */ 874ff50d0d1SRudolf Cornelissen pixel = 0x0000; 875ff50d0d1SRudolf Cornelissen /* set white if requested */ 876ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (!(*xorMask & b))) pixel = 0xffff; 877ff50d0d1SRudolf Cornelissen /* set black if requested */ 878ff50d0d1SRudolf Cornelissen if ((!(*andMask & b)) && (*xorMask & b)) pixel = 0x8000; 879ff50d0d1SRudolf Cornelissen /* set invert if requested */ 880ff50d0d1SRudolf Cornelissen if ( (*andMask & b) && (*xorMask & b)) pixel = 0x7fff; 881ff50d0d1SRudolf Cornelissen /* place the pixel in the bitmap */ 882ff50d0d1SRudolf Cornelissen cursor[x + (y * 32)] = pixel; 883ff50d0d1SRudolf Cornelissen b >>= 1; 884ff50d0d1SRudolf Cornelissen } 885ff50d0d1SRudolf Cornelissen xorMask++; 886ff50d0d1SRudolf Cornelissen andMask++; 887ff50d0d1SRudolf Cornelissen } 888ff50d0d1SRudolf Cornelissen 889ff50d0d1SRudolf Cornelissen return B_OK; 890ff50d0d1SRudolf Cornelissen } 891ff50d0d1SRudolf Cornelissen 892ff50d0d1SRudolf Cornelissen /* position the cursor */ 893ff50d0d1SRudolf Cornelissen status_t nv_crtc2_cursor_position(uint16 x, uint16 y) 894ff50d0d1SRudolf Cornelissen { 8950b7b8998SRudolf Cornelissen /* the cursor position is updated during retrace by card hardware */ 896ff50d0d1SRudolf Cornelissen 897ff50d0d1SRudolf Cornelissen /* update cursorposition */ 898ff50d0d1SRudolf Cornelissen DAC2W(CURPOS, ((x & 0x0fff) | ((y & 0x0fff) << 16))); 899ff50d0d1SRudolf Cornelissen 90008705d96Sshatty return B_OK; 90108705d96Sshatty } 90291731297SRudolf Cornelissen 90391731297SRudolf Cornelissen status_t nv_crtc2_stop_tvout(void) 90491731297SRudolf Cornelissen { 90596cc3084SRudolf Cornelissen uint16 cnt; 90696cc3084SRudolf Cornelissen 907d7dfe68dSRudolf Cornelissen LOG(4,("CRTC2: stopping TV output\n")); 908d7dfe68dSRudolf Cornelissen 90991731297SRudolf Cornelissen /* enable access to secondary head */ 91091731297SRudolf Cornelissen set_crtc_owner(1); 91191731297SRudolf Cornelissen 91291731297SRudolf Cornelissen /* just to be sure Vsync is _really_ enabled */ 91391731297SRudolf Cornelissen CRTC2W(REPAINT1, (CRTC2R(REPAINT1) & 0xbf)); 91491731297SRudolf Cornelissen 91591731297SRudolf Cornelissen /* wait for one image to be generated to make sure VGA has kicked in and is 91691731297SRudolf Cornelissen * running OK before continuing... 91791731297SRudolf Cornelissen * (Kicking in will fail often if we do not wait here) */ 91891731297SRudolf Cornelissen /* Note: 91991731297SRudolf Cornelissen * The used CRTC's Vsync is required to be enabled here. The DPMS state 92091731297SRudolf Cornelissen * programming in the driver makes sure this is the case. 92191731297SRudolf Cornelissen * (except for driver startup: see nv_general.c.) */ 92291731297SRudolf Cornelissen 92396cc3084SRudolf Cornelissen /* make sure we are 'in' active VGA picture: wait with timeout! */ 92496cc3084SRudolf Cornelissen cnt = 1; 92596cc3084SRudolf Cornelissen while ((NV_REG8(NV8_INSTAT1) & 0x08) && cnt) 92696cc3084SRudolf Cornelissen { 92796cc3084SRudolf Cornelissen snooze(1); 92896cc3084SRudolf Cornelissen cnt++; 92996cc3084SRudolf Cornelissen } 93096cc3084SRudolf Cornelissen /* wait for next vertical retrace start on VGA: wait with timeout! */ 93196cc3084SRudolf Cornelissen cnt = 1; 93296cc3084SRudolf Cornelissen while ((!(NV_REG8(NV8_INSTAT1) & 0x08)) && cnt) 93396cc3084SRudolf Cornelissen { 93496cc3084SRudolf Cornelissen snooze(1); 93596cc3084SRudolf Cornelissen cnt++; 93696cc3084SRudolf Cornelissen } 93796cc3084SRudolf Cornelissen /* now wait until we are 'in' active VGA picture again: wait with timeout! */ 93896cc3084SRudolf Cornelissen cnt = 1; 93996cc3084SRudolf Cornelissen while ((NV_REG8(NV8_INSTAT1) & 0x08) && cnt) 94096cc3084SRudolf Cornelissen { 94196cc3084SRudolf Cornelissen snooze(1); 94296cc3084SRudolf Cornelissen cnt++; 94396cc3084SRudolf Cornelissen } 94491731297SRudolf Cornelissen 94591731297SRudolf Cornelissen /* set CRTC to master mode (b7 = 0) if it wasn't slaved for a panel before */ 94691731297SRudolf Cornelissen if (!(si->ps.slaved_tmds2)) CRTC2W(PIXEL, (CRTC2R(PIXEL) & 0x03)); 94791731297SRudolf Cornelissen 94891731297SRudolf Cornelissen /* CAUTION: 94991731297SRudolf Cornelissen * On old cards, PLLSEL (and TV_SETUP?) cannot be read (sometimes?), but 95091731297SRudolf Cornelissen * write actions do succeed ... 95191731297SRudolf Cornelissen * This is confirmed for both ISA and PCI access, on NV04 and NV11. */ 95291731297SRudolf Cornelissen 95391731297SRudolf Cornelissen /* setup TVencoder connection */ 95491731297SRudolf Cornelissen /* b1-0 = %00: encoder type is SLAVE; 95591731297SRudolf Cornelissen * b24 = 1: VIP datapos is b0-7 */ 95691731297SRudolf Cornelissen //fixme if needed: setup completely instead of relying on pre-init by BIOS.. 95791731297SRudolf Cornelissen //(it seems to work OK on NV04 and NV11 although read reg. doesn't seem to work) 95891731297SRudolf Cornelissen DAC2W(TV_SETUP, ((DAC2R(TV_SETUP) & ~0x00000003) | 0x01000000)); 95991731297SRudolf Cornelissen 96091731297SRudolf Cornelissen /* tell GPU to use pixelclock from internal source instead of using TVencoder */ 96191731297SRudolf Cornelissen DACW(PLLSEL, 0x30000f00); 96291731297SRudolf Cornelissen 96391731297SRudolf Cornelissen /* HTOTAL, VTOTAL and OVERFLOW return their default CRTC use, instead of 96491731297SRudolf Cornelissen * H, V-low and V-high 'shadow' counters(?)(b0, 4 and 6 = 0) (b7 use = unknown) */ 96591731297SRudolf Cornelissen CRTC2W(TREG, 0x00); 96691731297SRudolf Cornelissen 96791731297SRudolf Cornelissen /* select panel encoder, not TV encoder if needed (b0 = 1). 96891731297SRudolf Cornelissen * Note: 96991731297SRudolf Cornelissen * Both are devices (often) using the CRTC in slaved mode. */ 97091731297SRudolf Cornelissen if (si->ps.slaved_tmds2) CRTC2W(LCD, (CRTC2R(LCD) | 0x01)); 97191731297SRudolf Cornelissen 97291731297SRudolf Cornelissen return B_OK; 97391731297SRudolf Cornelissen } 97491731297SRudolf Cornelissen 97591731297SRudolf Cornelissen status_t nv_crtc2_start_tvout(void) 97691731297SRudolf Cornelissen { 977d7dfe68dSRudolf Cornelissen LOG(4,("CRTC2: starting TV output\n")); 978d7dfe68dSRudolf Cornelissen 979a658603aSRudolf Cornelissen /* switch TV encoder to CRTC2 */ 980a658603aSRudolf Cornelissen NV_REG32(NV32_FUNCSEL) &= ~0x00000100; 981a658603aSRudolf Cornelissen NV_REG32(NV32_2FUNCSEL) |= 0x00000100; 982a658603aSRudolf Cornelissen 98391731297SRudolf Cornelissen /* enable access to secondary head */ 98491731297SRudolf Cornelissen set_crtc_owner(1); 98591731297SRudolf Cornelissen 98691731297SRudolf Cornelissen /* CAUTION: 98791731297SRudolf Cornelissen * On old cards, PLLSEL (and TV_SETUP?) cannot be read (sometimes?), but 98891731297SRudolf Cornelissen * write actions do succeed ... 98991731297SRudolf Cornelissen * This is confirmed for both ISA and PCI access, on NV04 and NV11. */ 99091731297SRudolf Cornelissen 99191731297SRudolf Cornelissen /* setup TVencoder connection */ 99291731297SRudolf Cornelissen /* b1-0 = %01: encoder type is MASTER; 99391731297SRudolf Cornelissen * b24 = 1: VIP datapos is b0-7 */ 99491731297SRudolf Cornelissen //fixme if needed: setup completely instead of relying on pre-init by BIOS.. 99591731297SRudolf Cornelissen //(it seems to work OK on NV04 and NV11 although read reg. doesn't seem to work) 99691731297SRudolf Cornelissen DAC2W(TV_SETUP, ((DAC2R(TV_SETUP) & ~0x00000002) | 0x01000001)); 99791731297SRudolf Cornelissen 99891731297SRudolf Cornelissen /* tell GPU to use pixelclock from TVencoder instead of using internal source */ 99991731297SRudolf Cornelissen /* (nessecary or display will 'shiver' on both TV and VGA.) */ 100091731297SRudolf Cornelissen DACW(PLLSEL, 0x100c0f00); 100191731297SRudolf Cornelissen 100291731297SRudolf Cornelissen /* Set overscan color to 'black' */ 100391731297SRudolf Cornelissen /* note: 100491731297SRudolf Cornelissen * Change this instruction for a visible overscan color if you're trying to 100591731297SRudolf Cornelissen * center the output on TV. Use it as a guide-'line' then ;-) */ 100691731297SRudolf Cornelissen ATB2W(OSCANCOLOR, 0x00); 100791731297SRudolf Cornelissen 100891731297SRudolf Cornelissen /* set CRTC to slaved mode (b7 = 1) and clear TVadjust (b3-5 = %000) */ 100991731297SRudolf Cornelissen CRTC2W(PIXEL, ((CRTC2R(PIXEL) & 0xc7) | 0x80)); 101091731297SRudolf Cornelissen /* select TV encoder, not panel encoder (b0 = 0). 101191731297SRudolf Cornelissen * Note: 101291731297SRudolf Cornelissen * Both are devices (often) using the CRTC in slaved mode. */ 101391731297SRudolf Cornelissen CRTC2W(LCD, (CRTC2R(LCD) & 0xfe)); 101491731297SRudolf Cornelissen 101591731297SRudolf Cornelissen /* HTOTAL, VTOTAL and OVERFLOW return their default CRTC use, instead of 101691731297SRudolf Cornelissen * H, V-low and V-high 'shadow' counters(?)(b0, 4 and 6 = 0) (b7 use = unknown) */ 101791731297SRudolf Cornelissen CRTC2W(TREG, 0x80); 101891731297SRudolf Cornelissen 101991731297SRudolf Cornelissen return B_OK; 102091731297SRudolf Cornelissen } 1021