kernels/linux-2.4.0/drivers/video/riva/riva_hw.c
/*
 * Calculate the Video Clock parameters for the PLL.
 */
Calculate the Video Clock parameters for the PLL.
Calculate the Video Clock parameters for the PLL .
static int CalcVClock
(
    int           clockIn,
    int          *clockOut,
    int          *mOut,
    int          *nOut,
    int          *pOut,
    RIVA_HW_INST *chip
)
{
    unsigned lowM, highM, highP;
    unsigned DeltaNew, DeltaOld;
    unsigned VClk, Freq;
    unsigned M, N, P;
    DeltaOld = 0xFFFFFFFF;
    VClk     = (unsigned)clockIn;
    if (chip->CrystalFreqKHz == 14318)
    {
        lowM  = 8;
        highM = 14 - (chip->Architecture == 3);
    }
    else
    {
        lowM  = 7;
        highM = 13 - (chip->Architecture == 3);
    }                      
    highP = 4 - (chip->Architecture == 3);
    for (P = 0; P <= highP; P ++)
    {
        Freq = VClk << P;
        if ((Freq >= 128000) && (Freq <= chip->MaxVClockFreqKHz))
        {
            for (M = lowM; M <= highM; M++)
            {
                N    = (VClk * M / chip->CrystalFreqKHz) << P;
                Freq = (chip->CrystalFreqKHz * N / M) >> P;
                if (Freq > VClk)
                    DeltaNew = Freq - VClk;
                else
                    DeltaNew = VClk - Freq;
                if (DeltaNew < DeltaOld)
                {
                    *mOut     = M;
                    *nOut     = N;
                    *pOut     = P;
                    *clockOut = Freq;
                    DeltaOld  = DeltaNew;
                }
            }
        }
    }
    return (DeltaOld != 0xFFFFFFFF);
}
static int CalcVClock ( int clockIn , int * clockOut , int * mOut , int * nOut , int * pOut , RIVA_HW_INST * chip ) { unsigned lowM , highM , highP ; unsigned DeltaNew , DeltaOld ; unsigned VClk , Freq ; unsigned M , N , P ; DeltaOld = 0xFFFFFFFF ; VClk = ( unsigned ) clockIn ; if ( chip -> CrystalFreqKHz == 14318 ) { lowM = 8 ; highM = 14 - ( chip -> Architecture == 3 ) ; } else { lowM = 7 ; highM = 13 - ( chip -> Architecture == 3 ) ; } highP = 4 - ( chip -> Architecture == 3 ) ; for ( P = 0 ; P <= highP ; P ++ ) { Freq = VClk << P ; if ( ( Freq >= 128000 ) && ( Freq <= chip -> MaxVClockFreqKHz ) ) { for ( M = lowM ; M <= highM ; M ++ ) { N = ( VClk * M / chip -> CrystalFreqKHz ) << P ; Freq = ( chip -> CrystalFreqKHz * N / M ) >> P ; if ( Freq > VClk ) DeltaNew = Freq - VClk ; else DeltaNew = VClk - Freq ; if ( DeltaNew < DeltaOld ) { * mOut = M ; * nOut = N ; * pOut = P ; * clockOut = Freq ; DeltaOld = DeltaNew ; } } } } return ( DeltaOld != 0xFFFFFFFF ) ; }
Calculate the Video Clock parameters for the PLL.
Calculate the Video Clock parameters for the PLL .