3 Rudolf Cornelissen 12/2003-10/2004
6 #define MODULE_BIT 0x00010000
10 static status_t
nv4_nv10_nv20_dac_pix_pll_find(
11 display_mode target
,float * calc_pclk
,uint8
* m_result
,uint8
* n_result
,uint8
* p_result
, uint8 test
);
13 /* see if an analog VGA monitor is connected to connector #1 */
14 bool eng_dac_crt_connected(void)
19 /* save output connector setting */
20 output
= DACR(OUTPUT
);
25 DACW(TSTCTRL
, (DACR(TSTCTRL
) & 0xfffeffff));
26 /* select primary head and turn off CRT (and DVI?) outputs */
27 DACW(OUTPUT
, (output
& 0x0000feee));
28 /* wait for signal lines to stabilize */
30 /* re-enable CRT output */
31 DACW(OUTPUT
, (DACR(OUTPUT
) | 0x00000001));
33 /* setup RGB test signal levels to approx 30% of DAC range and enable them */
34 DACW(TSTDATA
, ((0x2 << 30) | (0x140 << 20) | (0x140 << 10) | (0x140 << 0)));
35 /* route test signals to output */
36 DACW(TSTCTRL
, (DACR(TSTCTRL
) | 0x00001000));
37 /* wait for signal lines to stabilize */
40 /* do actual detection: all signals paths high == CRT connected */
41 if (DACR(TSTCTRL
) & 0x10000000)
44 LOG(4,("DAC: CRT detected on connector #1\n"));
49 LOG(4,("DAC: no CRT detected on connector #1\n"));
52 /* kill test signal routing */
53 DACW(TSTCTRL
, (DACR(TSTCTRL
) & 0xffffefff));
55 /* restore output connector setting */
57 /* restore DAC state */
63 /*set the mode, brightness is a value from 0->2 (where 1 is equivalent to direct)*/
64 status_t
eng_dac_mode(int mode
,float brightness
)
69 /*set colour arrays to point to space reserved in shared info*/
74 LOG(4,("DAC: Setting screen mode %d brightness %f\n", mode
, brightness
));
75 /* init the palette for brightness specified */
76 /* (Nvidia cards always use MSbits from screenbuffer as index for PAL) */
77 for (i
= 0; i
< 256; i
++)
80 if (ri
> 255) ri
= 255;
81 b
[i
] = g
[i
] = r
[i
] = ri
;
84 if (eng_dac_palette(r
,g
,b
) != B_OK
) return B_ERROR
;
86 /* disable palette RAM adressing mask */
87 ENG_REG8(RG8_PALMASK
) = 0xff;
88 LOG(2,("DAC: PAL pixrdmsk readback $%02x\n", ENG_REG8(RG8_PALMASK
)));
93 /*program the DAC palette using the given r,g,b values*/
94 status_t
eng_dac_palette(uint8 r
[256],uint8 g
[256],uint8 b
[256])
98 LOG(4,("DAC: setting palette\n"));
100 /* select first PAL adress before starting programming */
101 ENG_REG8(RG8_PALINDW
) = 0x00;
103 /* loop through all 256 to program DAC */
104 for (i
= 0; i
< 256; i
++)
106 /* the 6 implemented bits are on b0-b5 of the bus */
107 ENG_REG8(RG8_PALDATA
) = r
[i
];
108 ENG_REG8(RG8_PALDATA
) = g
[i
];
109 ENG_REG8(RG8_PALDATA
) = b
[i
];
111 if (ENG_REG8(RG8_PALINDW
) != 0x00)
113 LOG(8,("DAC: PAL write index incorrect after programming\n"));
120 /* select first PAL adress to read (modulo 3 counter) */
121 ENG_REG8(RG8_PALINDR
) = 0x00;
122 for (i
= 0; i
< 256; i
++)
124 R
= ENG_REG8(RG8_PALDATA
);
125 G
= ENG_REG8(RG8_PALDATA
);
126 B
= ENG_REG8(RG8_PALDATA
);
127 if ((r
[i
] != R
) || (g
[i
] != G
) || (b
[i
] != B
))
128 LOG(1,("DAC palette %d: w %x %x %x, r %x %x %x\n", i
, r
[i
], g
[i
], b
[i
], R
, G
, B
)); // apsed
135 /*program the pixpll - frequency in kHz*/
136 status_t
eng_dac_set_pix_pll(display_mode target
)
141 float pix_setting
, req_pclk
;
144 /* we offer this option because some panels have very tight restrictions,
145 * and there's no overlapping settings range that makes them all work.
147 * this assumes the cards BIOS correctly programmed the panel (is likely) */
148 //fixme: when VESA DDC EDID stuff is implemented, this option can be deleted...
149 if (si
->ps
.tmds1_active
&& !si
->settings
.pgm_panel
)
151 LOG(4,("DAC: Not programming DFP refresh (specified in skel.settings)\n"));
155 /* fix a DVI or laptop flatpanel to 60Hz refresh! */
157 * The pixelclock drives the flatpanel modeline, not the CRTC modeline. */
158 if (si
->ps
.tmds1_active
)
160 LOG(4,("DAC: Fixing DFP refresh to 60Hz!\n"));
162 /* use the panel's modeline to determine the needed pixelclock */
163 target
.timing
.pixel_clock
= si
->ps
.p1_timing
.pixel_clock
;
166 req_pclk
= (target
.timing
.pixel_clock
)/1000.0;
167 LOG(4,("DAC: Setting PIX PLL for pixelclock %f\n", req_pclk
));
169 /* signal that we actually want to set the mode */
170 result
= eng_dac_pix_pll_find(target
,&pix_setting
,&m
,&n
,&p
, 1);
176 /*reprogram (disable,select,wait for stability,enable)*/
177 // DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0x0F)|0x04); /*disable the PIXPLL*/
178 // DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0x0C)|0x01); /*select the PIXPLL*/
180 /* program new frequency */
181 DACW(PIXPLLC
, ((p
<< 16) | (n
<< 8) | m
));
183 /* program 2nd set N and M scalers if they exist (b31=1 enables them) */
184 if (si
->ps
.ext_pll
) DACW(PIXPLLC2
, 0x80000401);
186 /* Wait for the PIXPLL frequency to lock until timeout occurs */
187 //fixme: do NV cards have a LOCK indication bit??
188 /* while((!(DXIR(PIXPLLSTAT)&0x40)) & (time <= 2000))
195 LOG(2,("DAC: PIX PLL frequency not locked!\n"));
197 LOG(2,("DAC: PIX PLL frequency locked\n"));
198 DXIW(PIXCLKCTRL,DXIR(PIXCLKCTRL)&0x0B); //enable the PIXPLL
202 /* Give the PIXPLL frequency some time to lock... */
204 LOG(2,("DAC: PIX PLL frequency should be locked now...\n"));
209 /* find nearest valid pix pll */
210 status_t eng_dac_pix_pll_find
211 (display_mode target
,float * calc_pclk
,uint8
* m_result
,uint8
* n_result
,uint8
* p_result
, uint8 test
)
213 switch (si
->ps
.card_type
) {
214 default: return nv4_nv10_nv20_dac_pix_pll_find(target
, calc_pclk
, m_result
, n_result
, p_result
, test
);
219 /* find nearest valid pixel PLL setting */
220 static status_t
nv4_nv10_nv20_dac_pix_pll_find(
221 display_mode target
,float * calc_pclk
,uint8
* m_result
,uint8
* n_result
,uint8
* p_result
, uint8 test
)
223 int m
= 0, n
= 0, p
= 0/*, m_max*/;
224 float error
, error_best
= 999999999;
226 float f_vco
, max_pclk
;
227 float req_pclk
= target
.timing
.pixel_clock
/1000.0;
229 /* determine the max. reference-frequency postscaler setting for the
230 * current card (see G100, G200 and G400 specs). */
231 /* switch(si->ps.card_type)
234 LOG(4,("DAC: G100 restrictions apply\n"));
238 LOG(4,("DAC: G200 restrictions apply\n"));
242 LOG(4,("DAC: G400/G400MAX restrictions apply\n"));
247 LOG(4,("DAC: NV4/NV10/NV20 restrictions apply\n"));
249 /* determine the max. pixelclock for the current videomode */
250 switch (target
.space
)
253 max_pclk
= si
->ps
.max_dac1_clock_8
;
257 max_pclk
= si
->ps
.max_dac1_clock_16
;
260 max_pclk
= si
->ps
.max_dac1_clock_24
;
263 max_pclk
= si
->ps
.max_dac1_clock_32
;
266 /* use fail-safe value */
267 max_pclk
= si
->ps
.max_dac1_clock_32
;
270 /* if some dualhead mode is active, an extra restriction might apply */
271 if ((target
.flags
& DUALHEAD_BITS
) && (target
.space
== B_RGB32_LITTLE
))
272 max_pclk
= si
->ps
.max_dac1_clock_32dh
;
274 /* Make sure the requested pixelclock is within the PLL's operational limits */
275 /* lower limit is min_pixel_vco divided by highest postscaler-factor */
276 if (req_pclk
< (si
->ps
.min_pixel_vco
/ 16.0))
278 LOG(4,("DAC: clamping pixclock: requested %fMHz, set to %fMHz\n",
279 req_pclk
, (float)(si
->ps
.min_pixel_vco
/ 16.0)));
280 req_pclk
= (si
->ps
.min_pixel_vco
/ 16.0);
282 /* upper limit is given by pins in combination with current active mode */
283 if (req_pclk
> max_pclk
)
285 LOG(4,("DAC: clamping pixclock: requested %fMHz, set to %fMHz\n",
286 req_pclk
, (float)max_pclk
));
290 /* iterate through all valid PLL postscaler settings */
291 for (p
=0x01; p
< 0x20; p
= p
<<1)
293 /* calculate the needed VCO frequency for this postscaler setting */
294 f_vco
= req_pclk
* p
;
296 /* check if this is within range of the VCO specs */
297 if ((f_vco
>= si
->ps
.min_pixel_vco
) && (f_vco
<= si
->ps
.max_pixel_vco
))
299 /* FX5600 and FX5700 tweak for 2nd set N and M scalers */
300 if (si
->ps
.ext_pll
) f_vco
/= 4;
302 /* iterate trough all valid reference-frequency postscaler settings */
303 for (m
= 7; m
<= 14; m
++)
305 /* check if phase-discriminator will be within operational limits */
306 //fixme: PLL calcs will be resetup/splitup/updated...
307 if (si
->ps
.card_type
== NV36
)
309 if (((si
->ps
.f_ref
/ m
) < 3.2) || ((si
->ps
.f_ref
/ m
) > 6.4)) continue;
313 if (((si
->ps
.f_ref
/ m
) < 1.0) || ((si
->ps
.f_ref
/ m
) > 2.0)) continue;
316 /* calculate VCO postscaler setting for current setup.. */
317 n
= (int)(((f_vco
* m
) / si
->ps
.f_ref
) + 0.5);
319 /* ..and check for validity */
320 if ((n
< 1) || (n
> 255)) continue;
322 /* find error in frequency this setting gives */
325 /* FX5600 and FX5700 tweak for 2nd set N and M scalers */
326 error
= fabs((req_pclk
/ 4) - (((si
->ps
.f_ref
/ m
) * n
) / p
));
329 error
= fabs(req_pclk
- (((si
->ps
.f_ref
/ m
) * n
) / p
));
331 /* note the setting if best yet */
332 if (error
< error_best
)
343 /* setup the scalers programming values for found optimum setting */
348 /* log the VCO frequency found */
349 f_vco
= ((si
->ps
.f_ref
/ m
) * n
);
350 /* FX5600 and FX5700 tweak for 2nd set N and M scalers */
351 if (si
->ps
.ext_pll
) f_vco
*= 4;
353 LOG(2,("DAC: pix VCO frequency found %fMhz\n", f_vco
));
355 /* return the results */
356 *calc_pclk
= (f_vco
/ p
);
379 /* display the found pixelclock values */
380 LOG(2,("DAC: pix PLL check: requested %fMHz got %fMHz, mnp 0x%02x 0x%02x 0x%02x\n",
381 req_pclk
, *calc_pclk
, *m_result
, *n_result
, *p_result
));
386 /* find nearest valid system PLL setting */
387 status_t
eng_dac_sys_pll_find(
388 float req_sclk
, float* calc_sclk
, uint8
* m_result
, uint8
* n_result
, uint8
* p_result
, uint8 test
)
390 int m
= 0, n
= 0, p
= 0, m_max
, p_max
;
391 float error
, error_best
= 999999999;
393 float f_vco
, discr_low
, discr_high
;
395 /* determine the max. reference-frequency postscaler setting for the
396 * current requested clock */
397 switch (si
->ps
.card_arch
)
400 LOG(4,("DAC: NV04 restrictions apply\n"));
401 /* set phase-discriminator frequency range (Mhz) (verified) */
404 /* set max. useable reference frequency postscaler divider factor */
406 /* set max. useable VCO output postscaler divider factor */
410 switch (si
->ps
.card_type
)
413 //fixme: how about some other cards???
414 LOG(4,("DAC: NV28 restrictions apply\n"));
415 /* set max. useable reference frequency postscaler divider factor;
416 * apparantly we would get distortions on high PLL output frequencies if
417 * we use the phase-discriminator at low frequencies */
418 if (req_sclk
> 340.0) m_max
= 2; /* Fpll > 340Mhz */
419 else if (req_sclk
> 200.0) m_max
= 4; /* 200Mhz < Fpll <= 340Mhz */
420 else if (req_sclk
> 150.0) m_max
= 6; /* 150Mhz < Fpll <= 200Mhz */
421 else m_max
= 14; /* Fpll < 150Mhz */
423 /* set max. useable VCO output postscaler divider factor */
425 /* set phase-discriminator frequency range (Mhz) (verified) */
430 LOG(4,("DAC: NV10/NV20/NV30 restrictions apply\n"));
431 /* set max. useable reference frequency postscaler divider factor;
432 * apparantly we would get distortions on high PLL output frequencies if
433 * we use the phase-discriminator at low frequencies */
434 if (req_sclk
> 340.0) m_max
= 2; /* Fpll > 340Mhz */
435 else if (req_sclk
> 250.0) m_max
= 6; /* 250Mhz < Fpll <= 340Mhz */
436 else m_max
= 14; /* Fpll < 250Mhz */
438 /* set max. useable VCO output postscaler divider factor */
440 /* set phase-discriminator frequency range (Mhz) (verified) */
441 if (si
->ps
.card_type
== NV36
) discr_low
= 3.2;
442 else discr_low
= 1.0;
443 /* (high discriminator spec is failsafe) */
450 LOG(4,("DAC: PLL reference frequency postscaler divider range is 1 - %d\n", m_max
));
451 LOG(4,("DAC: PLL VCO output postscaler divider range is 1 - %d\n", p_max
));
452 LOG(4,("DAC: PLL discriminator input frequency range is %2.2fMhz - %2.2fMhz\n",
453 discr_low
, discr_high
));
455 /* Make sure the requested clock is within the PLL's operational limits */
456 /* lower limit is min_system_vco divided by highest postscaler-factor */
457 if (req_sclk
< (si
->ps
.min_system_vco
/ ((float)p_max
)))
459 LOG(4,("DAC: clamping sysclock: requested %fMHz, set to %fMHz\n",
460 req_sclk
, (si
->ps
.min_system_vco
/ ((float)p_max
))));
461 req_sclk
= (si
->ps
.min_system_vco
/ ((float)p_max
));
463 /* upper limit is given by pins */
464 if (req_sclk
> si
->ps
.max_system_vco
)
466 LOG(4,("DAC: clamping sysclock: requested %fMHz, set to %fMHz\n",
467 req_sclk
, (float)si
->ps
.max_system_vco
));
468 req_sclk
= si
->ps
.max_system_vco
;
471 /* iterate through all valid PLL postscaler settings */
472 for (p
=0x01; p
<= p_max
; p
= p
<<1)
474 /* calculate the needed VCO frequency for this postscaler setting */
475 f_vco
= req_sclk
* p
;
477 /* check if this is within range of the VCO specs */
478 if ((f_vco
>= si
->ps
.min_system_vco
) && (f_vco
<= si
->ps
.max_system_vco
))
480 /* FX5600 and FX5700 tweak for 2nd set N and M scalers */
481 if (si
->ps
.ext_pll
) f_vco
/= 4;
483 /* iterate trough all valid reference-frequency postscaler settings */
484 for (m
= 1; m
<= m_max
; m
++)
486 /* check if phase-discriminator will be within operational limits */
487 if (((si
->ps
.f_ref
/ m
) < discr_low
) || ((si
->ps
.f_ref
/ m
) > discr_high
))
490 /* calculate VCO postscaler setting for current setup.. */
491 n
= (int)(((f_vco
* m
) / si
->ps
.f_ref
) + 0.5);
493 /* ..and check for validity */
494 if ((n
< 1) || (n
> 255)) continue;
496 /* find error in frequency this setting gives */
499 /* FX5600 and FX5700 tweak for 2nd set N and M scalers */
500 error
= fabs((req_sclk
/ 4) - (((si
->ps
.f_ref
/ m
) * n
) / p
));
503 error
= fabs(req_sclk
- (((si
->ps
.f_ref
/ m
) * n
) / p
));
505 /* note the setting if best yet */
506 if (error
< error_best
)
517 /* setup the scalers programming values for found optimum setting */
522 /* log the VCO frequency found */
523 f_vco
= ((si
->ps
.f_ref
/ m
) * n
);
524 /* FX5600 and FX5700 tweak for 2nd set N and M scalers */
525 if (si
->ps
.ext_pll
) f_vco
*= 4;
527 LOG(2,("DAC: sys VCO frequency found %fMhz\n", f_vco
));
529 /* return the results */
530 *calc_sclk
= (f_vco
/ p
);
556 /* display the found pixelclock values */
557 LOG(2,("DAC: sys PLL check: requested %fMHz got %fMHz, mnp 0x%02x 0x%02x 0x%02x\n",
558 req_sclk
, *calc_sclk
, *m_result
, *n_result
, *p_result
));