vpllinit.c 2.14 KB
#include <os.h>
#include <bbint.h>
#include <bcp.h>
#include <os_internal_reg.h>

void __osBbVideoPllInit(s32 tvType)
{
    u32 avctrl;
    u32 mask;

    mask = __osDisableInt();

    /* Stop the VI and AI - in case we are running */
    IO_WRITE(VI_CONTROL_REG, 0x0);
    IO_WRITE(AI_CONTROL_REG, 0x0);
    __osBbDelay(50);

    /* Reset the VI and AI, but leave PLL running */
    avctrl = IO_READ(MI_AVCTRL_REG);
    avctrl &= ~MI_AVCTRL_AV_RESET;

    IO_WRITE(MI_AVCTRL_REG, avctrl);
    __osBbDelay(50);

    /* Put the PLL in standby mode -- it should already be if we are powering up */
    IO_WRITE(MI_AVCTRL_REG, avctrl | MI_AVCTRL_VPLL_STANDBY);
    __osBbDelay(50);

    /* Initialize the AVPLL */
    if (tvType == OS_TV_PAL) {
        avctrl = MI_AVCTRL_DAC_POWER |
            (1<<MI_AVCTRL_VPLL_PDIV_SHIFT) |
            (27<<MI_AVCTRL_VPLL_NDIV_SHIFT) |
            (4<<MI_AVCTRL_VPLL_MDIV_SHIFT) |
            (1<<MI_AVCTRL_VPLL_FRANGE_SHIFT);
    } else if (tvType == OS_TV_MPAL) {
        avctrl = MI_AVCTRL_VENC_VMPAL |
            MI_AVCTRL_DAC_POWER |
            (1<<MI_AVCTRL_VPLL_PDIV_SHIFT) |
            (33<<MI_AVCTRL_VPLL_NDIV_SHIFT) |
            (4<<MI_AVCTRL_VPLL_MDIV_SHIFT) |
            (1<<MI_AVCTRL_VPLL_FRANGE_SHIFT);

    } else { /* assume that it's NTSC */
        avctrl = MI_AVCTRL_VENC_VNTPL | 
            MI_AVCTRL_DAC_POWER |
            (1<<MI_AVCTRL_VPLL_PDIV_SHIFT) |
            (33<<MI_AVCTRL_VPLL_NDIV_SHIFT) |
            (4<<MI_AVCTRL_VPLL_MDIV_SHIFT) |
            (1<<MI_AVCTRL_VPLL_FRANGE_SHIFT);
    }

    IO_WRITE(MI_AVCTRL_REG, avctrl |
             MI_AVCTRL_VENC_TEST |
             MI_AVCTRL_VPLL_STANDBY);
    IO_READ(MI_AVCTRL_REG);
    /* Wait 1 uSec -- according to PLL spec, wait longer to be sure */
    __osBbDelay(2);

    /* Take PLL out of standby */
    IO_WRITE(MI_AVCTRL_REG, avctrl);
    IO_READ(MI_AVCTRL_REG);
            
    /* Wait 500 uSec for PLL output to be stable, wait longer to be sure */
    __osBbDelay(1000);
            
    /* Take the AI/VI out of reset */
    IO_WRITE(MI_AVCTRL_REG, avctrl |
             MI_AVCTRL_AV_RESET);
    IO_READ(MI_AVCTRL_REG);
           
    __osRestoreInt(mask);
}