1 /* second CTRC functionality for GeForce cards */
3 Rudolf Cornelissen 11/2002-9/2004
6 #define MODULE_BIT 0x00020000
10 /*Adjust passed parameters to a valid mode line*/
11 status_t
eng_crtc2_validate_timing(
12 uint16
*hd_e
,uint16
*hs_s
,uint16
*hs_e
,uint16
*ht
,
13 uint16
*vd_e
,uint16
*vs_s
,uint16
*vs_e
,uint16
*vt
17 /* make all parameters multiples of 8 */
23 /* confine to required number of bits, taking logic into account */
24 if (*hd_e
> ((0x01ff - 2) << 3)) *hd_e
= ((0x01ff - 2) << 3);
25 if (*hs_s
> ((0x01ff - 1) << 3)) *hs_s
= ((0x01ff - 1) << 3);
26 if (*hs_e
> ( 0x01ff << 3)) *hs_e
= ( 0x01ff << 3);
27 if (*ht
> ((0x01ff + 5) << 3)) *ht
= ((0x01ff + 5) << 3);
29 /* NOTE: keep horizontal timing at multiples of 8! */
30 /* confine to a reasonable width */
31 if (*hd_e
< 640) *hd_e
= 640;
32 if (*hd_e
> 2048) *hd_e
= 2048;
34 /* if hor. total does not leave room for a sensible sync pulse, increase it! */
35 if (*ht
< (*hd_e
+ 80)) *ht
= (*hd_e
+ 80);
37 /* if hor. total does not adhere to max. blanking pulse width, decrease it! */
38 if (*ht
> (*hd_e
+ 0x3f8)) *ht
= (*hd_e
+ 0x3f8);
40 /* make sure sync pulse is not during display */
41 if (*hs_e
> (*ht
- 8)) *hs_e
= (*ht
- 8);
42 if (*hs_s
< (*hd_e
+ 8)) *hs_s
= (*hd_e
+ 8);
44 /* correct sync pulse if it is too long:
45 * there are only 5 bits available to save this in the card registers! */
46 if (*hs_e
> (*hs_s
+ 0xf8)) *hs_e
= (*hs_s
+ 0xf8);
49 /* confine to required number of bits, taking logic into account */
50 //fixme if needed: on GeForce cards there are 12 instead of 11 bits...
51 if (*vd_e
> (0x7ff - 2)) *vd_e
= (0x7ff - 2);
52 if (*vs_s
> (0x7ff - 1)) *vs_s
= (0x7ff - 1);
53 if (*vs_e
> 0x7ff ) *vs_e
= 0x7ff ;
54 if (*vt
> (0x7ff + 2)) *vt
= (0x7ff + 2);
56 /* confine to a reasonable height */
57 if (*vd_e
< 480) *vd_e
= 480;
58 if (*vd_e
> 1536) *vd_e
= 1536;
60 /*if vertical total does not leave room for a sync pulse, increase it!*/
61 if (*vt
< (*vd_e
+ 3)) *vt
= (*vd_e
+ 3);
63 /* if vert. total does not adhere to max. blanking pulse width, decrease it! */
64 if (*vt
> (*vd_e
+ 0xff)) *vt
= (*vd_e
+ 0xff);
66 /* make sure sync pulse is not during display */
67 if (*vs_e
> (*vt
- 1)) *vs_e
= (*vt
- 1);
68 if (*vs_s
< (*vd_e
+ 1)) *vs_s
= (*vd_e
+ 1);
70 /* correct sync pulse if it is too long:
71 * there are only 4 bits available to save this in the card registers! */
72 if (*vs_e
> (*vs_s
+ 0x0f)) *vs_e
= (*vs_s
+ 0x0f);
77 /*set a mode line - inputs are in pixels*/
78 status_t
eng_crtc2_set_timing(display_mode target
)
82 uint32 htotal
; /*total horizontal total VCLKs*/
83 uint32 hdisp_e
; /*end of horizontal display (begins at 0)*/
84 uint32 hsync_s
; /*begin of horizontal sync pulse*/
85 uint32 hsync_e
; /*end of horizontal sync pulse*/
86 uint32 hblnk_s
; /*begin horizontal blanking*/
87 uint32 hblnk_e
; /*end horizontal blanking*/
89 uint32 vtotal
; /*total vertical total scanlines*/
90 uint32 vdisp_e
; /*end of vertical display*/
91 uint32 vsync_s
; /*begin of vertical sync pulse*/
92 uint32 vsync_e
; /*end of vertical sync pulse*/
93 uint32 vblnk_s
; /*begin vertical blanking*/
94 uint32 vblnk_e
; /*end vertical blanking*/
96 uint32 linecomp
; /*split screen and vdisp_e interrupt*/
98 LOG(4,("CRTC2: setting timing\n"));
100 /* setup tuned internal modeline for flatpanel if connected and active */
102 * - the CRTC modeline must end earlier than the panel modeline to keep correct
104 * - if the CRTC modeline ends too soon, pixelnoise will occur in 8 (or so) pixel
105 * wide horizontal stripes. This can be observed earliest on fullscreen overlay,
106 * and if it gets worse, also normal desktop output will suffer. The stripes
107 * are mainly visible at the left of the screen, over the entire screen height. */
108 if (si
->ps
.tmds2_active
)
110 LOG(2,("CRTC2: DFP active: tuning modeline\n"));
112 /* horizontal timing */
113 target
.timing
.h_sync_start
=
114 ((uint16
)((si
->ps
.p2_timing
.h_sync_start
/ ((float)si
->ps
.p2_timing
.h_display
)) *
115 target
.timing
.h_display
)) & 0xfff8;
117 target
.timing
.h_sync_end
=
118 ((uint16
)((si
->ps
.p2_timing
.h_sync_end
/ ((float)si
->ps
.p2_timing
.h_display
)) *
119 target
.timing
.h_display
)) & 0xfff8;
121 target
.timing
.h_total
=
122 (((uint16
)((si
->ps
.p2_timing
.h_total
/ ((float)si
->ps
.p2_timing
.h_display
)) *
123 target
.timing
.h_display
)) & 0xfff8) - 8;
125 /* in native mode the CRTC needs some extra time to keep synced correctly;
126 * OTOH the overlay unit distorts if we reserve too much time! */
127 if (target
.timing
.h_display
== si
->ps
.p2_timing
.h_display
)
129 /* NV11 timing has different constraints than later cards */
130 if (si
->ps
.card_type
== NV11
)
131 target
.timing
.h_total
-= 56;
133 /* confirmed NV34 with 1680x1050 panel */
134 target
.timing
.h_total
-= 32;
137 if (target
.timing
.h_sync_start
== target
.timing
.h_display
)
138 target
.timing
.h_sync_start
+= 8;
139 if (target
.timing
.h_sync_end
== target
.timing
.h_total
)
140 target
.timing
.h_sync_end
-= 8;
142 /* vertical timing */
143 target
.timing
.v_sync_start
=
144 ((uint16
)((si
->ps
.p2_timing
.v_sync_start
/ ((float)si
->ps
.p2_timing
.v_display
)) *
145 target
.timing
.v_display
));
147 target
.timing
.v_sync_end
=
148 ((uint16
)((si
->ps
.p2_timing
.v_sync_end
/ ((float)si
->ps
.p2_timing
.v_display
)) *
149 target
.timing
.v_display
));
151 target
.timing
.v_total
=
152 ((uint16
)((si
->ps
.p2_timing
.v_total
/ ((float)si
->ps
.p2_timing
.v_display
)) *
153 target
.timing
.v_display
)) - 1;
155 if (target
.timing
.v_sync_start
== target
.timing
.v_display
)
156 target
.timing
.v_sync_start
+= 1;
157 if (target
.timing
.v_sync_end
== target
.timing
.v_total
)
158 target
.timing
.v_sync_end
-= 1;
160 /* disable GPU scaling testmode so automatic scaling will be done */
164 /* Modify parameters as required by standard VGA */
165 htotal
= ((target
.timing
.h_total
>> 3) - 5);
166 hdisp_e
= ((target
.timing
.h_display
>> 3) - 1);
168 hblnk_e
= (htotal
+ 4);//0;
169 hsync_s
= (target
.timing
.h_sync_start
>> 3);
170 hsync_e
= (target
.timing
.h_sync_end
>> 3);
172 vtotal
= target
.timing
.v_total
- 2;
173 vdisp_e
= target
.timing
.v_display
- 1;
175 vblnk_e
= (vtotal
+ 1);
176 vsync_s
= target
.timing
.v_sync_start
;//-1;
177 vsync_e
= target
.timing
.v_sync_end
;//-1;
179 /* prevent memory adress counter from being reset (linecomp may not occur) */
180 linecomp
= target
.timing
.v_display
;
182 /* enable access to secondary head */
185 /* Note for laptop and DVI flatpanels:
186 * CRTC timing has a seperate set of registers from flatpanel timing.
187 * The flatpanel timing registers have scaling registers that are used to match
188 * these two modelines. */
190 LOG(4,("CRTC2: Setting full timing...\n"));
192 /* log the mode that will be set */
193 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
));
194 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
));
196 /* actually program the card! */
197 /* unlock CRTC registers at index 0-7 */
198 CRTC2W(VSYNCE
, (CRTC2R(VSYNCE
) & 0x7f));
199 /* horizontal standard VGA regs */
200 CRTC2W(HTOTAL
, (htotal
& 0xff));
201 CRTC2W(HDISPE
, (hdisp_e
& 0xff));
202 CRTC2W(HBLANKS
, (hblnk_s
& 0xff));
203 /* also unlock vertical retrace registers in advance */
204 CRTC2W(HBLANKE
, ((hblnk_e
& 0x1f) | 0x80));
205 CRTC2W(HSYNCS
, (hsync_s
& 0xff));
206 CRTC2W(HSYNCE
, ((hsync_e
& 0x1f) | ((hblnk_e
& 0x20) << 2)));
208 /* vertical standard VGA regs */
209 CRTC2W(VTOTAL
, (vtotal
& 0xff));
212 ((vtotal
& 0x100) >> (8 - 0)) | ((vtotal
& 0x200) >> (9 - 5)) |
213 ((vdisp_e
& 0x100) >> (8 - 1)) | ((vdisp_e
& 0x200) >> (9 - 6)) |
214 ((vsync_s
& 0x100) >> (8 - 2)) | ((vsync_s
& 0x200) >> (9 - 7)) |
215 ((vblnk_s
& 0x100) >> (8 - 3)) | ((linecomp
& 0x100) >> (8 - 4))
217 CRTC2W(PRROWSCN
, 0x00); /* not used */
218 CRTC2W(MAXSCLIN
, (((vblnk_s
& 0x200) >> (9 - 5)) | ((linecomp
& 0x200) >> (9 - 6))));
219 CRTC2W(VSYNCS
, (vsync_s
& 0xff));
220 CRTC2W(VSYNCE
, ((CRTC2R(VSYNCE
) & 0xf0) | (vsync_e
& 0x0f)));
221 CRTC2W(VDISPE
, (vdisp_e
& 0xff));
222 CRTC2W(VBLANKS
, (vblnk_s
& 0xff));
223 CRTC2W(VBLANKE
, (vblnk_e
& 0xff));
224 CRTC2W(LINECOMP
, (linecomp
& 0xff));
226 /* horizontal extended regs */
227 //fixme: we reset bit4. is this correct??
228 CRTC2W(HEB
, (CRTC2R(HEB
) & 0xe0) |
230 ((htotal
& 0x100) >> (8 - 0)) |
231 ((hdisp_e
& 0x100) >> (8 - 1)) |
232 ((hblnk_s
& 0x100) >> (8 - 2)) |
233 ((hsync_s
& 0x100) >> (8 - 3))
236 /* (mostly) vertical extended regs */
239 ((vtotal
& 0x400) >> (10 - 0)) |
240 ((vdisp_e
& 0x400) >> (10 - 1)) |
241 ((vsync_s
& 0x400) >> (10 - 2)) |
242 ((vblnk_s
& 0x400) >> (10 - 3)) |
243 ((hblnk_e
& 0x040) >> (6 - 4))
244 //fixme: we still miss one linecomp bit!?! is this it??
245 //| ((linecomp & 0x400) >> 3)
248 /* more vertical extended regs */
251 ((vtotal
& 0x800) >> (11 - 0)) |
252 ((vdisp_e
& 0x800) >> (11 - 2)) |
253 ((vsync_s
& 0x800) >> (11 - 4)) |
254 ((vblnk_s
& 0x800) >> (11 - 6))
255 //fixme: do we miss another linecomp bit!?!
258 /* setup 'large screen' mode */
259 if (target
.timing
.h_display
>= 1280)
260 CRTC2W(REPAINT1
, (CRTC2R(REPAINT1
) & 0xfb));
262 CRTC2W(REPAINT1
, (CRTC2R(REPAINT1
) | 0x04));
264 /* setup HSYNC & VSYNC polarity */
265 LOG(2,("CRTC2: sync polarity: "));
266 temp
= ENG_REG8(RG8_MISCR
);
267 if (target
.timing
.flags
& B_POSITIVE_HSYNC
)
277 if (target
.timing
.flags
& B_POSITIVE_VSYNC
)
287 ENG_REG8(RG8_MISCW
) = temp
;
289 LOG(2,(", MISC reg readback: $%02x\n", ENG_REG8(RG8_MISCR
)));
292 /* always disable interlaced operation */
293 /* (interlace is supported on upto and including NV10, NV15, and NV30 and up) */
294 CRTC2W(INTERLACE
, 0xff);
296 /* disable CRTC slaved mode unless a panel is in use */
297 // fixme: this kills TVout when it was in use...
298 if (!si
->ps
.tmds2_active
) CRTC2W(PIXEL
, (CRTC2R(PIXEL
) & 0x7f));
300 /* setup flatpanel if connected and active */
301 if (si
->ps
.tmds2_active
)
303 uint32 iscale_x
, iscale_y
;
305 /* calculate inverse scaling factors used by hardware in 20.12 format */
306 iscale_x
= (((1 << 12) * target
.timing
.h_display
) / si
->ps
.p2_timing
.h_display
);
307 iscale_y
= (((1 << 12) * target
.timing
.v_display
) / si
->ps
.p2_timing
.v_display
);
309 /* unblock flatpanel timing programming (or something like that..) */
310 CRTC2W(FP_HTIMING
, 0);
311 CRTC2W(FP_VTIMING
, 0);
312 LOG(2,("CRTC2: FP_HTIMING reg readback: $%02x\n", CRTC2R(FP_HTIMING
)));
313 LOG(2,("CRTC2: FP_VTIMING reg readback: $%02x\n", CRTC2R(FP_VTIMING
)));
315 /* enable full width visibility on flatpanel */
316 DAC2W(FP_HVALID_S
, 0);
317 DAC2W(FP_HVALID_E
, (si
->ps
.p2_timing
.h_display
- 1));
318 /* enable full height visibility on flatpanel */
319 DAC2W(FP_VVALID_S
, 0);
320 DAC2W(FP_VVALID_E
, (si
->ps
.p2_timing
.v_display
- 1));
322 /* nVidia cards support upscaling except on ??? */
323 /* NV11 cards can upscale after all! */
324 if (0)//si->ps.card_type == NV11)
326 /* disable last fetched line limiting */
327 DAC2W(FP_DEBUG2
, 0x00000000);
328 /* inform panel to scale if needed */
329 if ((iscale_x
!= (1 << 12)) || (iscale_y
!= (1 << 12)))
331 LOG(2,("CRTC2: DFP needs to do scaling\n"));
332 DAC2W(FP_TG_CTRL
, (DAC2R(FP_TG_CTRL
) | 0x00000100));
336 LOG(2,("CRTC2: no scaling for DFP needed\n"));
337 DAC2W(FP_TG_CTRL
, (DAC2R(FP_TG_CTRL
) & 0xfffffeff));
344 LOG(2,("CRTC2: GPU scales for DFP if needed\n"));
346 /* calculate display mode aspect */
347 dm_aspect
= (target
.timing
.h_display
/ ((float)target
.timing
.v_display
));
349 /* limit last fetched line if vertical scaling is done */
350 if (iscale_y
!= (1 << 12))
351 DAC2W(FP_DEBUG2
, ((1 << 28) | ((target
.timing
.v_display
- 1) << 16)));
353 DAC2W(FP_DEBUG2
, 0x00000000);
355 /* inform panel not to scale */
356 DAC2W(FP_TG_CTRL
, (DAC2R(FP_TG_CTRL
) & 0xfffffeff));
358 /* GPU scaling is automatically setup by hardware, so only modify this
359 * scalingfactor for non 4:3 (1.33) aspect panels;
360 * let's consider 1280x1024 1:33 aspect (it's 1.25 aspect actually!) */
362 /* correct for widescreen panels relative to mode...
363 * (so if panel is more widescreen than mode being set) */
364 /* BTW: known widescreen panels:
367 * 1680 x 1050 (1.60),
368 * 1920 x 1200 (1.60). */
369 /* known 4:3 aspect non-standard resolution panels:
370 * 1400 x 1050 (1.33). */
372 * allow 0.10 difference so 1280x1024 panels will be used fullscreen! */
373 if ((iscale_x
!= (1 << 12)) && (si
->ps
.panel2_aspect
> (dm_aspect
+ 0.10)))
377 LOG(2,("CRTC2: (relative) widescreen panel: tuning horizontal scaling\n"));
379 /* X-scaling should be the same as Y-scaling */
381 /* enable testmode (b12) and program new X-scaling factor */
382 DAC2W(FP_DEBUG1
, (((iscale_x
>> 1) & 0x00000fff) | (1 << 12)));
383 /* center/cut-off left and right side of screen */
384 diff
= ((si
->ps
.p2_timing
.h_display
-
385 (target
.timing
.h_display
* ((1 << 12) / ((float)iscale_x
))))
387 DAC2W(FP_HVALID_S
, diff
);
388 DAC2W(FP_HVALID_E
, ((si
->ps
.p2_timing
.h_display
- diff
) - 1));
390 /* correct for portrait panels... */
392 * allow 0.10 difference so 1280x1024 panels will be used fullscreen! */
393 if ((iscale_y
!= (1 << 12)) && (si
->ps
.panel2_aspect
< (dm_aspect
- 0.10)))
395 LOG(2,("CRTC2: (relative) portrait panel: should tune vertical scaling\n"));
396 /* fixme: implement if this kind of portrait panels exist on nVidia... */
400 /* do some logging.. */
401 LOG(2,("CRTC2: FP_HVALID_S reg readback: $%08x\n", DAC2R(FP_HVALID_S
)));
402 LOG(2,("CRTC2: FP_HVALID_E reg readback: $%08x\n", DAC2R(FP_HVALID_E
)));
403 LOG(2,("CRTC2: FP_VVALID_S reg readback: $%08x\n", DAC2R(FP_VVALID_S
)));
404 LOG(2,("CRTC2: FP_VVALID_E reg readback: $%08x\n", DAC2R(FP_VVALID_E
)));
405 LOG(2,("CRTC2: FP_DEBUG0 reg readback: $%08x\n", DAC2R(FP_DEBUG0
)));
406 LOG(2,("CRTC2: FP_DEBUG1 reg readback: $%08x\n", DAC2R(FP_DEBUG1
)));
407 LOG(2,("CRTC2: FP_DEBUG2 reg readback: $%08x\n", DAC2R(FP_DEBUG2
)));
408 LOG(2,("CRTC2: FP_DEBUG3 reg readback: $%08x\n", DAC2R(FP_DEBUG3
)));
409 LOG(2,("CRTC2: FP_TG_CTRL reg readback: $%08x\n", DAC2R(FP_TG_CTRL
)));
415 status_t
eng_crtc2_depth(int mode
)
420 /* set VCLK scaling */
425 /* genctrl b4 & b5 reset: 'direct mode' */
426 genctrl
= 0x00101100;
430 /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */
431 genctrl
= 0x00100130;
435 /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */
436 genctrl
= 0x00101130;
440 /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */
441 genctrl
= 0x00100130;
445 /* genctrl b4 & b5 set: 'indirect mode' (via colorpalette) */
446 genctrl
= 0x00101130;
449 /* enable access to secondary head */
452 CRTC2W(PIXEL
, ((CRTC2R(PIXEL
) & 0xfc) | viddelay
));
453 DAC2W(GENCTRL
, genctrl
);
458 status_t
eng_crtc2_dpms(bool display
, bool h
, bool v
)
462 LOG(4,("CRTC2: setting DPMS: "));
464 /* enable access to secondary head */
467 /* start synchronous reset: required before turning screen off! */
470 /* turn screen off */
471 temp
= SEQR(CLKMODE
);
474 SEQW(CLKMODE
, (temp
& ~0x20));
476 /* end synchronous reset if display should be enabled */
479 //'safe mode' test! feedback needed with this 'setting'!
480 if (0)//si->ps.tmds2_active)
482 /* powerup both LVDS (laptop panellink) and TMDS (DVI panellink)
483 * internal transmitters... */
485 * the powerbits in this register are hardwired to the DVI connectors,
486 * instead of to the DACs! (confirmed NV34) */
488 DAC2W(FP_DEBUG0
, (DAC2R(FP_DEBUG0
) & 0xcfffffff));
489 /* ... and powerup external TMDS transmitter if it exists */
490 /* (confirmed OK on NV28 and NV34) */
491 CRTC2W(0x59, (CRTC2R(0x59) | 0x01));
494 LOG(4,("display on, "));
498 SEQW(CLKMODE
, (temp
| 0x20));
500 //'safe mode' test! feedback needed with this 'setting'!
501 if (0)//si->ps.tmds2_active)
503 /* powerdown both LVDS (laptop panellink) and TMDS (DVI panellink)
504 * internal transmitters... */
506 * the powerbits in this register are hardwired to the DVI connectors,
507 * instead of to the DACs! (confirmed NV34) */
509 DAC2W(FP_DEBUG0
, (DAC2R(FP_DEBUG0
) | 0x30000000));
510 /* ... and powerdown external TMDS transmitter if it exists */
511 /* (confirmed OK on NV28 and NV34) */
512 CRTC2W(0x59, (CRTC2R(0x59) & 0xfe));
515 LOG(4,("display off, "));
520 CRTC2W(REPAINT1
, (CRTC2R(REPAINT1
) & 0x7f));
521 LOG(4,("hsync enabled, "));
525 CRTC2W(REPAINT1
, (CRTC2R(REPAINT1
) | 0x80));
526 LOG(4,("hsync disabled, "));
530 CRTC2W(REPAINT1
, (CRTC2R(REPAINT1
) & 0xbf));
531 LOG(4,("vsync enabled\n"));
535 CRTC2W(REPAINT1
, (CRTC2R(REPAINT1
) | 0x40));
536 LOG(4,("vsync disabled\n"));
542 status_t
eng_crtc2_dpms_fetch(bool *display
, bool *h
, bool *v
)
544 /* enable access to secondary head */
547 *display
= !(SEQR(CLKMODE
) & 0x20);
548 *h
= !(CRTC2R(REPAINT1
) & 0x80);
549 *v
= !(CRTC2R(REPAINT1
) & 0x40);
551 LOG(4,("CTRC2: fetched DPMS state: "));
552 if (*display
) LOG(4,("display on, "));
553 else LOG(4,("display off, "));
554 if (*h
) LOG(4,("hsync enabled, "));
555 else LOG(4,("hsync disabled, "));
556 if (*v
) LOG(4,("vsync enabled\n"));
557 else LOG(4,("vsync disabled\n"));
562 status_t
eng_crtc2_set_display_pitch()
566 LOG(4,("CRTC2: setting card pitch (offset between lines)\n"));
568 /* figure out offset value hardware needs */
569 offset
= si
->fbc
.bytes_per_row
/ 8;
571 LOG(2,("CRTC2: offset register set to: $%04x\n", offset
));
573 /* enable access to secondary head */
576 /* program the card */
577 CRTC2W(PITCHL
, (offset
& 0x00ff));
578 CRTC2W(REPAINT0
, ((CRTC2R(REPAINT0
) & 0x1f) | ((offset
& 0x0700) >> 3)));
583 status_t
eng_crtc2_set_display_start(uint32 startadd
,uint8 bpp
)
587 LOG(4,("CRTC2: setting card RAM to be displayed bpp %d\n", bpp
));
589 LOG(2,("CRTC2: startadd: $%08x\n", startadd
));
590 LOG(2,("CRTC2: frameRAM: $%08x\n", si
->framebuffer
));
591 LOG(2,("CRTC2: framebuffer: $%08x\n", si
->fbc
.frame_buffer
));
593 /* we might have no retraces during setmode! */
594 /* wait 25mS max. for retrace to occur (refresh > 40Hz) */
595 while (((ENG_REG32(RG32_RASTER2
) & 0x000007ff) < si
->dm
.timing
.v_display
) &&
596 (timeout
< (25000/10)))
598 /* don't snooze much longer or retrace might get missed! */
603 /* enable access to secondary head */
606 /* upto 4Gb RAM adressing: must be used on NV10 and later! */
608 * While this register also exists on pre-NV10 cards, it will
609 * wrap-around at 16Mb boundaries!! */
611 /* 30bit adress in 32bit words */
612 ENG_REG32(RG32_NV10FB2STADD32
) = (startadd
& 0xfffffffc);
614 /* set byte adress: (b0 - 1) */
615 ATB2W(HORPIXPAN
, ((startadd
& 0x00000003) << 1));
620 status_t
eng_crtc2_cursor_init()
624 /* cursor bitmap will be stored at the start of the framebuffer */
625 const uint32 curadd
= 0;
627 /* enable access to secondary head */
630 /* set cursor bitmap adress ... */
633 /* must be used this way on pre-NV10 and on all 'Go' cards! */
635 /* cursorbitmap must start on 2Kbyte boundary: */
636 /* set adress bit11-16, and set 'no doublescan' (registerbit 1 = 0) */
637 CRTC2W(CURCTL0
, ((curadd
& 0x0001f800) >> 9));
638 /* set adress bit17-23, and set graphics mode cursor(?) (registerbit 7 = 1) */
639 CRTC2W(CURCTL1
, (((curadd
& 0x00fe0000) >> 17) | 0x80));
640 /* set adress bit24-31 */
641 CRTC2W(CURCTL2
, ((curadd
& 0xff000000) >> 24));
645 /* upto 4Gb RAM adressing:
646 * can be used on NV10 and later (except for 'Go' cards)! */
648 * This register does not exist on pre-NV10 and 'Go' cards. */
650 /* cursorbitmap must still start on 2Kbyte boundary: */
651 ENG_REG32(RG32_NV10CUR2ADD32
) = (curadd
& 0xfffff800);
654 /* set cursor colour: not needed because of direct nature of cursor bitmap. */
657 fb
= (uint32
*) si
->framebuffer
+ curadd
;
658 for (i
=0;i
<(2048/4);i
++)
663 /* select 32x32 pixel, 16bit color cursorbitmap, no doublescan */
664 ENG_REG32(RG32_2CURCONF
) = 0x02000100;
666 /* activate hardware cursor */
667 eng_crtc2_cursor_show();
672 status_t
eng_crtc2_cursor_show()
674 LOG(4,("CRTC2: enabling cursor\n"));
676 /* enable access to secondary head */
679 /* b0 = 1 enables cursor */
680 CRTC2W(CURCTL0
, (CRTC2R(CURCTL0
) | 0x01));
685 status_t
eng_crtc2_cursor_hide()
687 LOG(4,("CRTC2: disabling cursor\n"));
689 /* enable access to secondary head */
692 /* b0 = 0 disables cursor */
693 CRTC2W(CURCTL0
, (CRTC2R(CURCTL0
) & 0xfe));
698 /*set up cursor shape*/
699 status_t
eng_crtc2_cursor_define(uint8
* andMask
,uint8
* xorMask
)
706 /* get a pointer to the cursor */
707 cursor
= (uint16
*) si
->framebuffer
;
709 /* draw the cursor */
710 /* (Nvidia cards have a RGB15 direct color cursor bitmap, bit #16 is transparancy) */
711 for (y
= 0; y
< 16; y
++)
714 for (x
= 0; x
< 8; x
++)
716 /* preset transparant */
718 /* set white if requested */
719 if ((!(*andMask
& b
)) && (!(*xorMask
& b
))) pixel
= 0xffff;
720 /* set black if requested */
721 if ((!(*andMask
& b
)) && (*xorMask
& b
)) pixel
= 0x8000;
722 /* set invert if requested */
723 if ( (*andMask
& b
) && (*xorMask
& b
)) pixel
= 0x7fff;
724 /* place the pixel in the bitmap */
725 cursor
[x
+ (y
* 32)] = pixel
;
733 /* preset transparant */
735 /* set white if requested */
736 if ((!(*andMask
& b
)) && (!(*xorMask
& b
))) pixel
= 0xffff;
737 /* set black if requested */
738 if ((!(*andMask
& b
)) && (*xorMask
& b
)) pixel
= 0x8000;
739 /* set invert if requested */
740 if ( (*andMask
& b
) && (*xorMask
& b
)) pixel
= 0x7fff;
741 /* place the pixel in the bitmap */
742 cursor
[x
+ (y
* 32)] = pixel
;
752 /* position the cursor */
753 status_t
eng_crtc2_cursor_position(uint16 x
, uint16 y
)
757 /* make sure we are beyond the first line of the cursorbitmap being drawn during
758 * updating the position to prevent distortions: no double buffering feature */
760 * we need to return as quick as possible or some apps will exhibit lagging.. */
762 /* read the old cursor Y position */
763 yhigh
= ((DAC2R(CURPOS
) & 0x0fff0000) >> 16);
764 /* make sure we will wait until we are below both the old and new Y position:
765 * visible cursorbitmap drawing needs to be done at least... */
766 if (y
> yhigh
) yhigh
= y
;
768 if (yhigh
< (si
->dm
.timing
.v_display
- 16))
770 /* we have vertical lines below old and new cursorposition to spare. So we
771 * update the cursor postion 'mid-screen', but below that area. */
772 while (((uint16
)(ENG_REG32(RG32_RASTER2
) & 0x000007ff)) < (yhigh
+ 16))
779 /* no room to spare, just wait for retrace (is relatively slow) */
780 while ((ENG_REG32(RG32_RASTER2
) & 0x000007ff) < si
->dm
.timing
.v_display
)
782 /* don't snooze much longer or retrace might get missed! */
787 /* update cursorposition */
788 DAC2W(CURPOS
, ((x
& 0x0fff) | ((y
& 0x0fff) << 16)));