Rudolf Cornelissen 12/2003-10/2004
*/
#define MODULE_BIT 0x00010000
#include "std.h"
static status_t nv4_nv10_nv20_dac_pix_pll_find(
display_mode target,float * calc_pclk,uint8 * m_result,uint8 * n_result,uint8 * p_result, uint8 test);
bool eng_dac_crt_connected(void)
{
uint32 output, dac;
bool present;
output = DACR(OUTPUT);
dac = DACR(TSTCTRL);
DACW(TSTCTRL, (DACR(TSTCTRL) & 0xfffeffff));
DACW(OUTPUT, (output & 0x0000feee));
snooze(1000);
DACW(OUTPUT, (DACR(OUTPUT) | 0x00000001));
DACW(TSTDATA, ((0x2 << 30) | (0x140 << 20) | (0x140 << 10) | (0x140 << 0)));
DACW(TSTCTRL, (DACR(TSTCTRL) | 0x00001000));
snooze(1000);
if (DACR(TSTCTRL) & 0x10000000)
{
present = true;
LOG(4,("DAC: CRT detected on connector #1\n"));
}
else
{
present = false;
LOG(4,("DAC: no CRT detected on connector #1\n"));
}
DACW(TSTCTRL, (DACR(TSTCTRL) & 0xffffefff));
DACW(OUTPUT, output);
DACW(TSTCTRL, dac);
return present;
}
status_t eng_dac_mode(int mode,float brightness)
{
uint8 *r,*g,*b;
int i, ri;
r = si->color_data;
g = r + 256;
b = g + 256;
LOG(4,("DAC: Setting screen mode %d brightness %f\n", mode, brightness));
for (i = 0; i < 256; i++)
{
ri = i * brightness;
if (ri > 255) ri = 255;
b[i] = g[i] = r[i] = ri;
}
if (eng_dac_palette(r,g,b) != B_OK) return B_ERROR;
ENG_REG8(RG8_PALMASK) = 0xff;
LOG(2,("DAC: PAL pixrdmsk readback $%02x\n", ENG_REG8(RG8_PALMASK)));
return B_OK;
}
status_t eng_dac_palette(uint8 r[256],uint8 g[256],uint8 b[256])
{
int i;
LOG(4,("DAC: setting palette\n"));
ENG_REG8(RG8_PALINDW) = 0x00;
for (i = 0; i < 256; i++)
{
ENG_REG8(RG8_PALDATA) = r[i];
ENG_REG8(RG8_PALDATA) = g[i];
ENG_REG8(RG8_PALDATA) = b[i];
}
if (ENG_REG8(RG8_PALINDW) != 0x00)
{
LOG(8,("DAC: PAL write index incorrect after programming\n"));
return B_ERROR;
}
if (1)
{
uint8 R, G, B;
ENG_REG8(RG8_PALINDR) = 0x00;
for (i = 0; i < 256; i++)
{
R = ENG_REG8(RG8_PALDATA);
G = ENG_REG8(RG8_PALDATA);
B = ENG_REG8(RG8_PALDATA);
if ((r[i] != R) || (g[i] != G) || (b[i] != B))
LOG(1,("DAC palette %d: w %x %x %x, r %x %x %x\n", i, r[i], g[i], b[i], R, G, B));
}
}
return B_OK;
}
status_t eng_dac_set_pix_pll(display_mode target)
{
uint8 m=0,n=0,p=0;
float pix_setting, req_pclk;
status_t result;
* and there's no overlapping settings range that makes them all work.
* note:
* this assumes the cards BIOS correctly programmed the panel (is likely) */
if (si->ps.tmds1_active && !si->settings.pgm_panel)
{
LOG(4,("DAC: Not programming DFP refresh (specified in skel.settings)\n"));
return B_OK;
}
* The pixelclock drives the flatpanel modeline, not the CRTC modeline. */
if (si->ps.tmds1_active)
{
LOG(4,("DAC: Fixing DFP refresh to 60Hz!\n"));
target.timing.pixel_clock = si->ps.p1_timing.pixel_clock;
}
req_pclk = (target.timing.pixel_clock)/1000.0;
LOG(4,("DAC: Setting PIX PLL for pixelclock %f\n", req_pclk));
result = eng_dac_pix_pll_find(target,&pix_setting,&m,&n,&p, 1);
if (result != B_OK)
{
return result;
}
DACW(PIXPLLC, ((p << 16) | (n << 8) | m));
if (si->ps.ext_pll) DACW(PIXPLLC2, 0x80000401);
{
time++;
snooze(1);
}
if (time > 2000)
LOG(2,("DAC: PIX PLL frequency not locked!\n"));
else
LOG(2,("DAC: PIX PLL frequency locked\n"));
DXIW(PIXCLKCTRL,DXIR(PIXCLKCTRL)&0x0B); //enable the PIXPLL
*/
snooze(1000);
LOG(2,("DAC: PIX PLL frequency should be locked now...\n"));
return B_OK;
}
status_t eng_dac_pix_pll_find
(display_mode target,float * calc_pclk,uint8 * m_result,uint8 * n_result,uint8 * p_result, uint8 test)
{
switch (si->ps.card_type) {
default: return nv4_nv10_nv20_dac_pix_pll_find(target, calc_pclk, m_result, n_result, p_result, test);
}
return B_ERROR;
}
static status_t nv4_nv10_nv20_dac_pix_pll_find(
display_mode target,float * calc_pclk,uint8 * m_result,uint8 * n_result,uint8 * p_result, uint8 test)
{
int m = 0, n = 0, p = 0;
float error, error_best = 999999999;
int best[3];
float f_vco, max_pclk;
float req_pclk = target.timing.pixel_clock/1000.0;
* current card (see G100, G200 and G400 specs). */
{
case G100:
LOG(4,("DAC: G100 restrictions apply\n"));
m_max = 7;
break;
case G200:
LOG(4,("DAC: G200 restrictions apply\n"));
m_max = 7;
break;
default:
LOG(4,("DAC: G400/G400MAX restrictions apply\n"));
m_max = 32;
break;
}
*/
LOG(4,("DAC: NV4/NV10/NV20 restrictions apply\n"));
switch (target.space)
{
case B_CMAP8:
max_pclk = si->ps.max_dac1_clock_8;
break;
case B_RGB15_LITTLE:
case B_RGB16_LITTLE:
max_pclk = si->ps.max_dac1_clock_16;
break;
case B_RGB24_LITTLE:
max_pclk = si->ps.max_dac1_clock_24;
break;
case B_RGB32_LITTLE:
max_pclk = si->ps.max_dac1_clock_32;
break;
default:
max_pclk = si->ps.max_dac1_clock_32;
break;
}
if ((target.flags & DUALHEAD_BITS) && (target.space == B_RGB32_LITTLE))
max_pclk = si->ps.max_dac1_clock_32dh;
if (req_pclk < (si->ps.min_pixel_vco / 16.0))
{
LOG(4,("DAC: clamping pixclock: requested %fMHz, set to %fMHz\n",
req_pclk, (float)(si->ps.min_pixel_vco / 16.0)));
req_pclk = (si->ps.min_pixel_vco / 16.0);
}
if (req_pclk > max_pclk)
{
LOG(4,("DAC: clamping pixclock: requested %fMHz, set to %fMHz\n",
req_pclk, (float)max_pclk));
req_pclk = max_pclk;
}
for (p=0x01; p < 0x20; p = p<<1)
{
f_vco = req_pclk * p;
if ((f_vco >= si->ps.min_pixel_vco) && (f_vco <= si->ps.max_pixel_vco))
{
if (si->ps.ext_pll) f_vco /= 4;
for (m = 7; m <= 14; m++)
{
if (si->ps.card_type == NV36)
{
if (((si->ps.f_ref / m) < 3.2) || ((si->ps.f_ref / m) > 6.4)) continue;
}
else
{
if (((si->ps.f_ref / m) < 1.0) || ((si->ps.f_ref / m) > 2.0)) continue;
}
n = (int)(((f_vco * m) / si->ps.f_ref) + 0.5);
if ((n < 1) || (n > 255)) continue;
if (si->ps.ext_pll)
{
error = fabs((req_pclk / 4) - (((si->ps.f_ref / m) * n) / p));
}
else
error = fabs(req_pclk - (((si->ps.f_ref / m) * n) / p));
if (error < error_best)
{
error_best = error;
best[0]=m;
best[1]=n;
best[2]=p;
}
}
}
}
m = best[0];
n = best[1];
p = best[2];
f_vco = ((si->ps.f_ref / m) * n);
if (si->ps.ext_pll) f_vco *= 4;
LOG(2,("DAC: pix VCO frequency found %fMhz\n", f_vco));
*calc_pclk = (f_vco / p);
*m_result = m;
*n_result = n;
switch(p)
{
case 1:
p = 0x00;
break;
case 2:
p = 0x01;
break;
case 4:
p = 0x02;
break;
case 8:
p = 0x03;
break;
case 16:
p = 0x04;
break;
}
*p_result = p;
LOG(2,("DAC: pix PLL check: requested %fMHz got %fMHz, mnp 0x%02x 0x%02x 0x%02x\n",
req_pclk, *calc_pclk, *m_result, *n_result, *p_result));
return B_OK;
}
status_t eng_dac_sys_pll_find(
float req_sclk, float* calc_sclk, uint8* m_result, uint8* n_result, uint8* p_result, uint8 test)
{
int m = 0, n = 0, p = 0, m_max, p_max;
float error, error_best = 999999999;
int best[3];
float f_vco, discr_low, discr_high;
* current requested clock */
switch (si->ps.card_arch)
{
case NV04A:
LOG(4,("DAC: NV04 restrictions apply\n"));
discr_low = 1.0;
discr_high = 2.0;
m_max = 14;
p_max = 16;
break;
default:
switch (si->ps.card_type)
{
case NV28:
LOG(4,("DAC: NV28 restrictions apply\n"));
* apparantly we would get distortions on high PLL output frequencies if
* we use the phase-discriminator at low frequencies */
if (req_sclk > 340.0) m_max = 2;
else if (req_sclk > 200.0) m_max = 4;
else if (req_sclk > 150.0) m_max = 6;
else m_max = 14;
p_max = 32;
discr_low = 1.0;
discr_high = 27.0;
break;
default:
LOG(4,("DAC: NV10/NV20/NV30 restrictions apply\n"));
* apparantly we would get distortions on high PLL output frequencies if
* we use the phase-discriminator at low frequencies */
if (req_sclk > 340.0) m_max = 2;
else if (req_sclk > 250.0) m_max = 6;
else m_max = 14;
p_max = 16;
if (si->ps.card_type == NV36) discr_low = 3.2;
else discr_low = 1.0;
discr_high = 14.0;
break;
}
break;
}
LOG(4,("DAC: PLL reference frequency postscaler divider range is 1 - %d\n", m_max));
LOG(4,("DAC: PLL VCO output postscaler divider range is 1 - %d\n", p_max));
LOG(4,("DAC: PLL discriminator input frequency range is %2.2fMhz - %2.2fMhz\n",
discr_low, discr_high));
if (req_sclk < (si->ps.min_system_vco / ((float)p_max)))
{
LOG(4,("DAC: clamping sysclock: requested %fMHz, set to %fMHz\n",
req_sclk, (si->ps.min_system_vco / ((float)p_max))));
req_sclk = (si->ps.min_system_vco / ((float)p_max));
}
if (req_sclk > si->ps.max_system_vco)
{
LOG(4,("DAC: clamping sysclock: requested %fMHz, set to %fMHz\n",
req_sclk, (float)si->ps.max_system_vco));
req_sclk = si->ps.max_system_vco;
}
for (p=0x01; p <= p_max; p = p<<1)
{
f_vco = req_sclk * p;
if ((f_vco >= si->ps.min_system_vco) && (f_vco <= si->ps.max_system_vco))
{
if (si->ps.ext_pll) f_vco /= 4;
for (m = 1; m <= m_max; m++)
{
if (((si->ps.f_ref / m) < discr_low) || ((si->ps.f_ref / m) > discr_high))
continue;
n = (int)(((f_vco * m) / si->ps.f_ref) + 0.5);
if ((n < 1) || (n > 255)) continue;
if (si->ps.ext_pll)
{
error = fabs((req_sclk / 4) - (((si->ps.f_ref / m) * n) / p));
}
else
error = fabs(req_sclk - (((si->ps.f_ref / m) * n) / p));
if (error < error_best)
{
error_best = error;
best[0]=m;
best[1]=n;
best[2]=p;
}
}
}
}
m = best[0];
n = best[1];
p = best[2];
f_vco = ((si->ps.f_ref / m) * n);
if (si->ps.ext_pll) f_vco *= 4;
LOG(2,("DAC: sys VCO frequency found %fMhz\n", f_vco));
*calc_sclk = (f_vco / p);
*m_result = m;
*n_result = n;
switch(p)
{
case 1:
p = 0x00;
break;
case 2:
p = 0x01;
break;
case 4:
p = 0x02;
break;
case 8:
p = 0x03;
break;
case 16:
p = 0x04;
break;
case 32:
p = 0x05;
break;
}
*p_result = p;
LOG(2,("DAC: sys PLL check: requested %fMHz got %fMHz, mnp 0x%02x 0x%02x 0x%02x\n",
req_sclk, *calc_sclk, *m_result, *n_result, *p_result));
return B_OK;
}