1*68353368SRudolf Cornelissen /* program the secondary DAC */ 2*68353368SRudolf Cornelissen /* Author: 3*68353368SRudolf Cornelissen Rudolf Cornelissen 12/2003-9/2004 4*68353368SRudolf Cornelissen */ 5*68353368SRudolf Cornelissen 6*68353368SRudolf Cornelissen #define MODULE_BIT 0x00001000 7*68353368SRudolf Cornelissen 8*68353368SRudolf Cornelissen #include "nv_std.h" 9*68353368SRudolf Cornelissen 10*68353368SRudolf Cornelissen static status_t nv10_nv20_dac2_pix_pll_find( 11*68353368SRudolf Cornelissen display_mode target,float * calc_pclk,uint8 * m_result,uint8 * n_result,uint8 * p_result, uint8 test); 12*68353368SRudolf Cornelissen 13*68353368SRudolf Cornelissen /* see if an analog VGA monitor is connected to connector #2 */ 14*68353368SRudolf Cornelissen bool nv_dac2_crt_connected() 15*68353368SRudolf Cornelissen { 16*68353368SRudolf Cornelissen uint32 output, dac; 17*68353368SRudolf Cornelissen bool present; 18*68353368SRudolf Cornelissen 19*68353368SRudolf Cornelissen /* NOTE: 20*68353368SRudolf Cornelissen * NV11 can't do this: It will report DAC1 status instead because it HAS no 21*68353368SRudolf Cornelissen * actual secondary DAC function. */ 22*68353368SRudolf Cornelissen /* (It DOES have a secondary palette RAM and pixelclock PLL though.) */ 23*68353368SRudolf Cornelissen 24*68353368SRudolf Cornelissen /* save output connector setting */ 25*68353368SRudolf Cornelissen output = DAC2R(OUTPUT); 26*68353368SRudolf Cornelissen /* save DAC state */ 27*68353368SRudolf Cornelissen dac = DAC2R(TSTCTRL); 28*68353368SRudolf Cornelissen 29*68353368SRudolf Cornelissen /* turn on DAC2 */ 30*68353368SRudolf Cornelissen DAC2W(TSTCTRL, (DAC2R(TSTCTRL) & 0xfffeffff)); 31*68353368SRudolf Cornelissen /* select primary head and turn off CRT (and DVI?) outputs */ 32*68353368SRudolf Cornelissen DAC2W(OUTPUT, (output & 0x0000feee)); 33*68353368SRudolf Cornelissen /* wait for signal lines to stabilize */ 34*68353368SRudolf Cornelissen snooze(1000); 35*68353368SRudolf Cornelissen /* re-enable CRT output */ 36*68353368SRudolf Cornelissen DAC2W(OUTPUT, (DAC2R(OUTPUT) | 0x00000001)); 37*68353368SRudolf Cornelissen 38*68353368SRudolf Cornelissen /* setup RGB test signal levels to approx 30% of DAC range and enable them 39*68353368SRudolf Cornelissen * (NOTE: testsignal function block resides in DAC1 only (!)) */ 40*68353368SRudolf Cornelissen DACW(TSTDATA, ((0x2 << 30) | (0x140 << 20) | (0x140 << 10) | (0x140 << 0))); 41*68353368SRudolf Cornelissen /* route test signals to output 42*68353368SRudolf Cornelissen * (NOTE: testsignal function block resides in DAC1 only (!)) */ 43*68353368SRudolf Cornelissen DACW(TSTCTRL, (DACR(TSTCTRL) | 0x00001000)); 44*68353368SRudolf Cornelissen /* wait for signal lines to stabilize */ 45*68353368SRudolf Cornelissen snooze(1000); 46*68353368SRudolf Cornelissen 47*68353368SRudolf Cornelissen /* do actual detection: all signals paths high == CRT connected */ 48*68353368SRudolf Cornelissen if (DAC2R(TSTCTRL) & 0x10000000) 49*68353368SRudolf Cornelissen { 50*68353368SRudolf Cornelissen present = true; 51*68353368SRudolf Cornelissen LOG(4,("DAC2: CRT detected on connector #2\n")); 52*68353368SRudolf Cornelissen } 53*68353368SRudolf Cornelissen else 54*68353368SRudolf Cornelissen { 55*68353368SRudolf Cornelissen present = false; 56*68353368SRudolf Cornelissen LOG(4,("DAC2: no CRT detected on connector #2\n")); 57*68353368SRudolf Cornelissen } 58*68353368SRudolf Cornelissen 59*68353368SRudolf Cornelissen /* kill test signal routing 60*68353368SRudolf Cornelissen * (NOTE: testsignal function block resides in DAC1 only (!)) */ 61*68353368SRudolf Cornelissen DACW(TSTCTRL, (DACR(TSTCTRL) & 0xffffefff)); 62*68353368SRudolf Cornelissen 63*68353368SRudolf Cornelissen /* restore output connector setting */ 64*68353368SRudolf Cornelissen DAC2W(OUTPUT, output); 65*68353368SRudolf Cornelissen /* restore DAC state */ 66*68353368SRudolf Cornelissen DAC2W(TSTCTRL, dac); 67*68353368SRudolf Cornelissen 68*68353368SRudolf Cornelissen return present; 69*68353368SRudolf Cornelissen } 70*68353368SRudolf Cornelissen 71*68353368SRudolf Cornelissen /*set the mode, brightness is a value from 0->2 (where 1 is equivalent to direct)*/ 72*68353368SRudolf Cornelissen status_t nv_dac2_mode(int mode,float brightness) 73*68353368SRudolf Cornelissen { 74*68353368SRudolf Cornelissen uint8 *r,*g,*b; 75*68353368SRudolf Cornelissen int i, ri; 76*68353368SRudolf Cornelissen 77*68353368SRudolf Cornelissen /*set colour arrays to point to space reserved in shared info*/ 78*68353368SRudolf Cornelissen r = si->color_data; 79*68353368SRudolf Cornelissen g = r + 256; 80*68353368SRudolf Cornelissen b = g + 256; 81*68353368SRudolf Cornelissen 82*68353368SRudolf Cornelissen LOG(4,("DAC2: Setting screen mode %d brightness %f\n", mode, brightness)); 83*68353368SRudolf Cornelissen /* init the palette for brightness specified */ 84*68353368SRudolf Cornelissen /* (Nvidia cards always use MSbits from screenbuffer as index for PAL) */ 85*68353368SRudolf Cornelissen for (i = 0; i < 256; i++) 86*68353368SRudolf Cornelissen { 87*68353368SRudolf Cornelissen ri = i * brightness; 88*68353368SRudolf Cornelissen if (ri > 255) ri = 255; 89*68353368SRudolf Cornelissen b[i] = g[i] = r[i] = ri; 90*68353368SRudolf Cornelissen } 91*68353368SRudolf Cornelissen 92*68353368SRudolf Cornelissen if (nv_dac2_palette(r,g,b) != B_OK) return B_ERROR; 93*68353368SRudolf Cornelissen 94*68353368SRudolf Cornelissen /* disable palette RAM adressing mask */ 95*68353368SRudolf Cornelissen NV_REG8(NV8_PAL2MASK) = 0xff; 96*68353368SRudolf Cornelissen LOG(2,("DAC2: PAL pixrdmsk readback $%02x\n", NV_REG8(NV8_PAL2MASK))); 97*68353368SRudolf Cornelissen 98*68353368SRudolf Cornelissen return B_OK; 99*68353368SRudolf Cornelissen } 100*68353368SRudolf Cornelissen 101*68353368SRudolf Cornelissen /*program the DAC palette using the given r,g,b values*/ 102*68353368SRudolf Cornelissen status_t nv_dac2_palette(uint8 r[256],uint8 g[256],uint8 b[256]) 103*68353368SRudolf Cornelissen { 104*68353368SRudolf Cornelissen int i; 105*68353368SRudolf Cornelissen 106*68353368SRudolf Cornelissen LOG(4,("DAC2: setting palette\n")); 107*68353368SRudolf Cornelissen 108*68353368SRudolf Cornelissen /* select first PAL adress before starting programming */ 109*68353368SRudolf Cornelissen NV_REG8(NV8_PAL2INDW) = 0x00; 110*68353368SRudolf Cornelissen 111*68353368SRudolf Cornelissen /* loop through all 256 to program DAC */ 112*68353368SRudolf Cornelissen for (i = 0; i < 256; i++) 113*68353368SRudolf Cornelissen { 114*68353368SRudolf Cornelissen /* the 6 implemented bits are on b0-b5 of the bus */ 115*68353368SRudolf Cornelissen NV_REG8(NV8_PAL2DATA) = r[i]; 116*68353368SRudolf Cornelissen NV_REG8(NV8_PAL2DATA) = g[i]; 117*68353368SRudolf Cornelissen NV_REG8(NV8_PAL2DATA) = b[i]; 118*68353368SRudolf Cornelissen } 119*68353368SRudolf Cornelissen if (NV_REG8(NV8_PAL2INDW) != 0x00) 120*68353368SRudolf Cornelissen { 121*68353368SRudolf Cornelissen LOG(8,("DAC2: PAL write index incorrect after programming\n")); 122*68353368SRudolf Cornelissen return B_ERROR; 123*68353368SRudolf Cornelissen } 124*68353368SRudolf Cornelissen if (1) 125*68353368SRudolf Cornelissen {//reread LUT 126*68353368SRudolf Cornelissen uint8 R, G, B; 127*68353368SRudolf Cornelissen 128*68353368SRudolf Cornelissen /* select first PAL adress to read (modulo 3 counter) */ 129*68353368SRudolf Cornelissen NV_REG8(NV8_PAL2INDR) = 0x00; 130*68353368SRudolf Cornelissen for (i = 0; i < 256; i++) 131*68353368SRudolf Cornelissen { 132*68353368SRudolf Cornelissen R = NV_REG8(NV8_PAL2DATA); 133*68353368SRudolf Cornelissen G = NV_REG8(NV8_PAL2DATA); 134*68353368SRudolf Cornelissen B = NV_REG8(NV8_PAL2DATA); 135*68353368SRudolf Cornelissen if ((r[i] != R) || (g[i] != G) || (b[i] != B)) 136*68353368SRudolf Cornelissen LOG(1,("DAC2 palette %d: w %x %x %x, r %x %x %x\n", i, r[i], g[i], b[i], R, G, B)); // apsed 137*68353368SRudolf Cornelissen } 138*68353368SRudolf Cornelissen } 139*68353368SRudolf Cornelissen 140*68353368SRudolf Cornelissen return B_OK; 141*68353368SRudolf Cornelissen } 142*68353368SRudolf Cornelissen 143*68353368SRudolf Cornelissen /*program the pixpll - frequency in kHz*/ 144*68353368SRudolf Cornelissen status_t nv_dac2_set_pix_pll(display_mode target) 145*68353368SRudolf Cornelissen { 146*68353368SRudolf Cornelissen uint8 m=0,n=0,p=0; 147*68353368SRudolf Cornelissen // uint time = 0; 148*68353368SRudolf Cornelissen 149*68353368SRudolf Cornelissen float pix_setting, req_pclk; 150*68353368SRudolf Cornelissen status_t result; 151*68353368SRudolf Cornelissen 152*68353368SRudolf Cornelissen /* we offer this option because some panels have very tight restrictions, 153*68353368SRudolf Cornelissen * and there's no overlapping settings range that makes them all work. 154*68353368SRudolf Cornelissen * note: 155*68353368SRudolf Cornelissen * this assumes the cards BIOS correctly programmed the panel (is likely) */ 156*68353368SRudolf Cornelissen //fixme: when VESA DDC EDID stuff is implemented, this option can be deleted... 157*68353368SRudolf Cornelissen if (si->ps.tmds2_active && !si->settings.pgm_panel) 158*68353368SRudolf Cornelissen { 159*68353368SRudolf Cornelissen LOG(4,("DAC2: Not programming DFP refresh (specified in nv.settings)\n")); 160*68353368SRudolf Cornelissen return B_OK; 161*68353368SRudolf Cornelissen } 162*68353368SRudolf Cornelissen 163*68353368SRudolf Cornelissen /* fix a DVI or laptop flatpanel to 60Hz refresh! */ 164*68353368SRudolf Cornelissen /* Note: 165*68353368SRudolf Cornelissen * The pixelclock drives the flatpanel modeline, not the CRTC modeline. */ 166*68353368SRudolf Cornelissen if (si->ps.tmds2_active) 167*68353368SRudolf Cornelissen { 168*68353368SRudolf Cornelissen LOG(4,("DAC2: Fixing DFP refresh to 60Hz!\n")); 169*68353368SRudolf Cornelissen 170*68353368SRudolf Cornelissen /* use the panel's modeline to determine the needed pixelclock */ 171*68353368SRudolf Cornelissen target.timing.pixel_clock = si->ps.p2_timing.pixel_clock; 172*68353368SRudolf Cornelissen } 173*68353368SRudolf Cornelissen 174*68353368SRudolf Cornelissen req_pclk = (target.timing.pixel_clock)/1000.0; 175*68353368SRudolf Cornelissen LOG(4,("DAC2: Setting PIX PLL for pixelclock %f\n", req_pclk)); 176*68353368SRudolf Cornelissen 177*68353368SRudolf Cornelissen /* signal that we actually want to set the mode */ 178*68353368SRudolf Cornelissen result = nv_dac2_pix_pll_find(target,&pix_setting,&m,&n,&p, 1); 179*68353368SRudolf Cornelissen if (result != B_OK) 180*68353368SRudolf Cornelissen { 181*68353368SRudolf Cornelissen return result; 182*68353368SRudolf Cornelissen } 183*68353368SRudolf Cornelissen 184*68353368SRudolf Cornelissen /*reprogram (disable,select,wait for stability,enable)*/ 185*68353368SRudolf Cornelissen // DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0x0F)|0x04); /*disable the PIXPLL*/ 186*68353368SRudolf Cornelissen // DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0x0C)|0x01); /*select the PIXPLL*/ 187*68353368SRudolf Cornelissen 188*68353368SRudolf Cornelissen /* program new frequency */ 189*68353368SRudolf Cornelissen DAC2W(PIXPLLC, ((p << 16) | (n << 8) | m)); 190*68353368SRudolf Cornelissen 191*68353368SRudolf Cornelissen /* program 2nd set N and M scalers if they exist (b31=1 enables them) */ 192*68353368SRudolf Cornelissen if (si->ps.ext_pll) DAC2W(PIXPLLC2, 0x80000401); 193*68353368SRudolf Cornelissen 194*68353368SRudolf Cornelissen /* Wait for the PIXPLL frequency to lock until timeout occurs */ 195*68353368SRudolf Cornelissen //fixme: do NV cards have a LOCK indication bit?? 196*68353368SRudolf Cornelissen /* while((!(DXIR(PIXPLLSTAT)&0x40)) & (time <= 2000)) 197*68353368SRudolf Cornelissen { 198*68353368SRudolf Cornelissen time++; 199*68353368SRudolf Cornelissen snooze(1); 200*68353368SRudolf Cornelissen } 201*68353368SRudolf Cornelissen 202*68353368SRudolf Cornelissen if (time > 2000) 203*68353368SRudolf Cornelissen LOG(2,("DAC: PIX PLL frequency not locked!\n")); 204*68353368SRudolf Cornelissen else 205*68353368SRudolf Cornelissen LOG(2,("DAC: PIX PLL frequency locked\n")); 206*68353368SRudolf Cornelissen DXIW(PIXCLKCTRL,DXIR(PIXCLKCTRL)&0x0B); //enable the PIXPLL 207*68353368SRudolf Cornelissen */ 208*68353368SRudolf Cornelissen 209*68353368SRudolf Cornelissen //for now: 210*68353368SRudolf Cornelissen /* Give the PIXPLL frequency some time to lock... */ 211*68353368SRudolf Cornelissen snooze(1000); 212*68353368SRudolf Cornelissen LOG(2,("DAC2: PIX PLL frequency should be locked now...\n")); 213*68353368SRudolf Cornelissen 214*68353368SRudolf Cornelissen return B_OK; 215*68353368SRudolf Cornelissen } 216*68353368SRudolf Cornelissen 217*68353368SRudolf Cornelissen /* find nearest valid pix pll */ 218*68353368SRudolf Cornelissen status_t nv_dac2_pix_pll_find 219*68353368SRudolf Cornelissen (display_mode target,float * calc_pclk,uint8 * m_result,uint8 * n_result,uint8 * p_result, uint8 test) 220*68353368SRudolf Cornelissen { 221*68353368SRudolf Cornelissen switch (si->ps.card_type) { 222*68353368SRudolf Cornelissen default: return nv10_nv20_dac2_pix_pll_find(target, calc_pclk, m_result, n_result, p_result, test); 223*68353368SRudolf Cornelissen } 224*68353368SRudolf Cornelissen return B_ERROR; 225*68353368SRudolf Cornelissen } 226*68353368SRudolf Cornelissen 227*68353368SRudolf Cornelissen /* find nearest valid pixel PLL setting */ 228*68353368SRudolf Cornelissen static status_t nv10_nv20_dac2_pix_pll_find( 229*68353368SRudolf Cornelissen display_mode target,float * calc_pclk,uint8 * m_result,uint8 * n_result,uint8 * p_result, uint8 test) 230*68353368SRudolf Cornelissen { 231*68353368SRudolf Cornelissen int m = 0, n = 0, p = 0/*, m_max*/; 232*68353368SRudolf Cornelissen float error, error_best = 999999999; 233*68353368SRudolf Cornelissen int best[3]; 234*68353368SRudolf Cornelissen float f_vco, max_pclk; 235*68353368SRudolf Cornelissen float req_pclk = target.timing.pixel_clock/1000.0; 236*68353368SRudolf Cornelissen 237*68353368SRudolf Cornelissen /* determine the max. reference-frequency postscaler setting for the 238*68353368SRudolf Cornelissen * current card (see G100, G200 and G400 specs). */ 239*68353368SRudolf Cornelissen /* switch(si->ps.card_type) 240*68353368SRudolf Cornelissen { 241*68353368SRudolf Cornelissen case G100: 242*68353368SRudolf Cornelissen LOG(4,("DAC: G100 restrictions apply\n")); 243*68353368SRudolf Cornelissen m_max = 7; 244*68353368SRudolf Cornelissen break; 245*68353368SRudolf Cornelissen case G200: 246*68353368SRudolf Cornelissen LOG(4,("DAC: G200 restrictions apply\n")); 247*68353368SRudolf Cornelissen m_max = 7; 248*68353368SRudolf Cornelissen break; 249*68353368SRudolf Cornelissen default: 250*68353368SRudolf Cornelissen LOG(4,("DAC: G400/G400MAX restrictions apply\n")); 251*68353368SRudolf Cornelissen m_max = 32; 252*68353368SRudolf Cornelissen break; 253*68353368SRudolf Cornelissen } 254*68353368SRudolf Cornelissen */ 255*68353368SRudolf Cornelissen LOG(4,("DAC2: NV10/NV20 restrictions apply\n")); 256*68353368SRudolf Cornelissen 257*68353368SRudolf Cornelissen /* determine the max. pixelclock for the current videomode */ 258*68353368SRudolf Cornelissen switch (target.space) 259*68353368SRudolf Cornelissen { 260*68353368SRudolf Cornelissen case B_CMAP8: 261*68353368SRudolf Cornelissen max_pclk = si->ps.max_dac2_clock_8; 262*68353368SRudolf Cornelissen break; 263*68353368SRudolf Cornelissen case B_RGB15_LITTLE: 264*68353368SRudolf Cornelissen case B_RGB16_LITTLE: 265*68353368SRudolf Cornelissen max_pclk = si->ps.max_dac2_clock_16; 266*68353368SRudolf Cornelissen break; 267*68353368SRudolf Cornelissen case B_RGB24_LITTLE: 268*68353368SRudolf Cornelissen max_pclk = si->ps.max_dac2_clock_24; 269*68353368SRudolf Cornelissen break; 270*68353368SRudolf Cornelissen case B_RGB32_LITTLE: 271*68353368SRudolf Cornelissen max_pclk = si->ps.max_dac2_clock_32; 272*68353368SRudolf Cornelissen break; 273*68353368SRudolf Cornelissen default: 274*68353368SRudolf Cornelissen /* use fail-safe value */ 275*68353368SRudolf Cornelissen max_pclk = si->ps.max_dac2_clock_32; 276*68353368SRudolf Cornelissen break; 277*68353368SRudolf Cornelissen } 278*68353368SRudolf Cornelissen /* if some dualhead mode is active, an extra restriction might apply */ 279*68353368SRudolf Cornelissen if ((target.flags & DUALHEAD_BITS) && (target.space == B_RGB32_LITTLE)) 280*68353368SRudolf Cornelissen max_pclk = si->ps.max_dac2_clock_32dh; 281*68353368SRudolf Cornelissen 282*68353368SRudolf Cornelissen /* Make sure the requested pixelclock is within the PLL's operational limits */ 283*68353368SRudolf Cornelissen /* lower limit is min_pixel_vco divided by highest postscaler-factor */ 284*68353368SRudolf Cornelissen if (req_pclk < (si->ps.min_video_vco / 16.0)) 285*68353368SRudolf Cornelissen { 286*68353368SRudolf Cornelissen LOG(4,("DAC2: clamping pixclock: requested %fMHz, set to %fMHz\n", 287*68353368SRudolf Cornelissen req_pclk, (float)(si->ps.min_video_vco / 16.0))); 288*68353368SRudolf Cornelissen req_pclk = (si->ps.min_video_vco / 16.0); 289*68353368SRudolf Cornelissen } 290*68353368SRudolf Cornelissen /* upper limit is given by pins in combination with current active mode */ 291*68353368SRudolf Cornelissen if (req_pclk > max_pclk) 292*68353368SRudolf Cornelissen { 293*68353368SRudolf Cornelissen LOG(4,("DAC2: clamping pixclock: requested %fMHz, set to %fMHz\n", 294*68353368SRudolf Cornelissen req_pclk, (float)max_pclk)); 295*68353368SRudolf Cornelissen req_pclk = max_pclk; 296*68353368SRudolf Cornelissen } 297*68353368SRudolf Cornelissen 298*68353368SRudolf Cornelissen /* iterate through all valid PLL postscaler settings */ 299*68353368SRudolf Cornelissen for (p=0x01; p < 0x20; p = p<<1) 300*68353368SRudolf Cornelissen { 301*68353368SRudolf Cornelissen /* calculate the needed VCO frequency for this postscaler setting */ 302*68353368SRudolf Cornelissen f_vco = req_pclk * p; 303*68353368SRudolf Cornelissen 304*68353368SRudolf Cornelissen /* check if this is within range of the VCO specs */ 305*68353368SRudolf Cornelissen if ((f_vco >= si->ps.min_video_vco) && (f_vco <= si->ps.max_video_vco)) 306*68353368SRudolf Cornelissen { 307*68353368SRudolf Cornelissen /* FX5600 and FX5700 tweak for 2nd set N and M scalers */ 308*68353368SRudolf Cornelissen if (si->ps.ext_pll) f_vco /= 4; 309*68353368SRudolf Cornelissen 310*68353368SRudolf Cornelissen /* iterate trough all valid reference-frequency postscaler settings */ 311*68353368SRudolf Cornelissen for (m = 7; m <= 14; m++) 312*68353368SRudolf Cornelissen { 313*68353368SRudolf Cornelissen /* check if phase-discriminator will be within operational limits */ 314*68353368SRudolf Cornelissen //fixme: PLL calcs will be resetup/splitup/updated... 315*68353368SRudolf Cornelissen if (si->ps.card_type == NV36) 316*68353368SRudolf Cornelissen { 317*68353368SRudolf Cornelissen if (((si->ps.f_ref / m) < 3.2) || ((si->ps.f_ref / m) > 6.4)) continue; 318*68353368SRudolf Cornelissen } 319*68353368SRudolf Cornelissen else 320*68353368SRudolf Cornelissen { 321*68353368SRudolf Cornelissen if (((si->ps.f_ref / m) < 1.0) || ((si->ps.f_ref / m) > 2.0)) continue; 322*68353368SRudolf Cornelissen } 323*68353368SRudolf Cornelissen 324*68353368SRudolf Cornelissen /* calculate VCO postscaler setting for current setup.. */ 325*68353368SRudolf Cornelissen n = (int)(((f_vco * m) / si->ps.f_ref) + 0.5); 326*68353368SRudolf Cornelissen /* ..and check for validity */ 327*68353368SRudolf Cornelissen if ((n < 1) || (n > 255)) continue; 328*68353368SRudolf Cornelissen 329*68353368SRudolf Cornelissen /* find error in frequency this setting gives */ 330*68353368SRudolf Cornelissen if (si->ps.ext_pll) 331*68353368SRudolf Cornelissen { 332*68353368SRudolf Cornelissen /* FX5600 and FX5700 tweak for 2nd set N and M scalers */ 333*68353368SRudolf Cornelissen error = fabs((req_pclk / 4) - (((si->ps.f_ref / m) * n) / p)); 334*68353368SRudolf Cornelissen } 335*68353368SRudolf Cornelissen else 336*68353368SRudolf Cornelissen error = fabs(req_pclk - (((si->ps.f_ref / m) * n) / p)); 337*68353368SRudolf Cornelissen 338*68353368SRudolf Cornelissen /* note the setting if best yet */ 339*68353368SRudolf Cornelissen if (error < error_best) 340*68353368SRudolf Cornelissen { 341*68353368SRudolf Cornelissen error_best = error; 342*68353368SRudolf Cornelissen best[0]=m; 343*68353368SRudolf Cornelissen best[1]=n; 344*68353368SRudolf Cornelissen best[2]=p; 345*68353368SRudolf Cornelissen } 346*68353368SRudolf Cornelissen } 347*68353368SRudolf Cornelissen } 348*68353368SRudolf Cornelissen } 349*68353368SRudolf Cornelissen 350*68353368SRudolf Cornelissen /* setup the scalers programming values for found optimum setting */ 351*68353368SRudolf Cornelissen m = best[0]; 352*68353368SRudolf Cornelissen n = best[1]; 353*68353368SRudolf Cornelissen p = best[2]; 354*68353368SRudolf Cornelissen 355*68353368SRudolf Cornelissen /* log the VCO frequency found */ 356*68353368SRudolf Cornelissen f_vco = ((si->ps.f_ref / m) * n); 357*68353368SRudolf Cornelissen /* FX5600 and FX5700 tweak for 2nd set N and M scalers */ 358*68353368SRudolf Cornelissen if (si->ps.ext_pll) f_vco *= 4; 359*68353368SRudolf Cornelissen 360*68353368SRudolf Cornelissen LOG(2,("DAC2: pix VCO frequency found %fMhz\n", f_vco)); 361*68353368SRudolf Cornelissen 362*68353368SRudolf Cornelissen /* return the results */ 363*68353368SRudolf Cornelissen *calc_pclk = (f_vco / p); 364*68353368SRudolf Cornelissen *m_result = m; 365*68353368SRudolf Cornelissen *n_result = n; 366*68353368SRudolf Cornelissen switch(p) 367*68353368SRudolf Cornelissen { 368*68353368SRudolf Cornelissen case 1: 369*68353368SRudolf Cornelissen p = 0x00; 370*68353368SRudolf Cornelissen break; 371*68353368SRudolf Cornelissen case 2: 372*68353368SRudolf Cornelissen p = 0x01; 373*68353368SRudolf Cornelissen break; 374*68353368SRudolf Cornelissen case 4: 375*68353368SRudolf Cornelissen p = 0x02; 376*68353368SRudolf Cornelissen break; 377*68353368SRudolf Cornelissen case 8: 378*68353368SRudolf Cornelissen p = 0x03; 379*68353368SRudolf Cornelissen break; 380*68353368SRudolf Cornelissen case 16: 381*68353368SRudolf Cornelissen p = 0x04; 382*68353368SRudolf Cornelissen break; 383*68353368SRudolf Cornelissen } 384*68353368SRudolf Cornelissen *p_result = p; 385*68353368SRudolf Cornelissen 386*68353368SRudolf Cornelissen /* display the found pixelclock values */ 387*68353368SRudolf Cornelissen LOG(2,("DAC2: pix PLL check: requested %fMHz got %fMHz, mnp 0x%02x 0x%02x 0x%02x\n", 388*68353368SRudolf Cornelissen req_pclk, *calc_pclk, *m_result, *n_result, *p_result)); 389*68353368SRudolf Cornelissen 390*68353368SRudolf Cornelissen return B_OK; 391*68353368SRudolf Cornelissen } 392