AVL_DVBSx_ErrorCode AVL6211_Initialize(struct AVL_DVBSx_Chip * pAVLChip,struct AVL_Tuner * pTuner) { struct AVL_DVBSx_Diseqc_Para sDiseqcPara; struct AVL_DVBSx_MpegInfo sMpegMode; AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK; struct AVL_Demod_Tuner_Configuration_t *pDemodTunerConfig = &g_DemodTuner_Config[g_nDemodTunerArrayIndex]; struct AVL_DVBSx_VerInfo VerInfo; //AVL_uint32 uiTemp; AVL_uint32 uiDeviceID=0; #if 0 //This function should be implemented by customer. //This function should be called before all other functions to prepare everything for a BSP operation. r = AVL_DVBSx_IBSP_Initialize(); if( AVL_DVBSx_EC_OK != r ) { printf("BSP Initialization failed !\n"); return (r); } #endif pAVLChip->m_uiBusId=pDemodTunerConfig->m_ChannelId; // This function should be called after bsp initialized to initialize the chip object. r = Init_AVL_DVBSx_ChipObject(pAVLChip, pDemodTunerConfig->m_uiDemodAddress); if( AVL_DVBSx_EC_OK != r ) { printf("Chip Object Initialization failed !\n"); return (r); } //Judge the chip ID of current chip. //r = AVL_DVBSx_II2C_Read32(pAVLChip, rom_ver_addr, &uiTemp); r= AVL_DVBSx_IRx_GetDeviceID( pAVLChip, &uiDeviceID); printk("r is %x,uiDeviceID is %x\n",r,uiDeviceID); if (AVL_DVBSx_EC_OK != r) { printf("Get Chip ID failed !\n"); return (r); } //if ( uiTemp != Chip_ID ) if(uiDeviceID != Chip_ID ) { printf("Chip ID isn't correct !\n"); return AVL_DVBSx_EC_GeneralFail; } //This function should be called after chip object initialized to initialize the IBase,using reference clock as 10M. Make sure you pickup the right pll_conf since it may be modified in BSP. r = AVL_DVBSx_IBase_Initialize(&(pll_conf[pDemodTunerConfig->m_DemodReferenceClk]), ucPatchData, pAVLChip); if( AVL_DVBSx_EC_OK != r ) { printf("IBase Initialization failed !\n"); return (r); } AVL_DVBSx_IBSP_Delay(100); //Wait 100 ms to assure that the AVL_DVBSx chip boots up.This function should be implemented by customer. //This function should be called to verify the AVL_DVBSx chip has completed its initialization procedure. r = AVL_DVBSx_IBase_GetStatus(pAVLChip); if( AVL_DVBSx_EC_OK != r ) { printf("Booted failed !\n"); return (r); } printf("Booted !\n"); //Get Chip ID, Patch version and SDK version. AVL_DVBSx_IBase_GetVersion( &VerInfo, pAVLChip); printf("Chip Ver:{%d}.{%d}.{%d} API Ver:{%d}.{%d}.{%d} Patch Ver:{%d}.{%d}.{%d} \n", VerInfo.m_Chip.m_Major, VerInfo.m_Chip.m_Minor, VerInfo.m_Chip.m_Build, VerInfo.m_API.m_Major, VerInfo.m_API.m_Minor, VerInfo.m_API.m_Build, VerInfo.m_Patch.m_Major, VerInfo.m_Patch.m_Minor, VerInfo.m_Patch.m_Build); //This function should be called after IBase initialized to initialize the demod. r = AVL_DVBSx_IRx_Initialize(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Demod Initialization failed !\n"); return (r); } //This function should be called after demod initialized to set RF AGC polar. //User does not need to setup this for Sharp tuner since it is the default value. But for other tuners, user may need to do it here. r |= AVL_DVBSx_IRx_SetRFAGCPola(pDemodTunerConfig->m_TunerRFAGC, pAVLChip); r |= AVL_DVBSx_IRx_DriveRFAGC(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Set RF AGC Polar failed !\n"); return (r); } //This function should be called after demod initialized to set spectrum polar. r = AVL_DVBSx_IBase_SetSpectrumPolarity(pDemodTunerConfig->m_Tuner_IQ_SpectrumMode, pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Set Spectrum Polar failed !\n"); return (r); } //Setup MPEG mode parameters. sMpegMode.m_MpegFormat = pDemodTunerConfig->m_TSFormat; sMpegMode.m_MpegMode = pDemodTunerConfig->m_TSOutPutMode; sMpegMode.m_MpegClockPolarity = pDemodTunerConfig->m_TSClockPolarity; //This function should be called after demod initialized to set MPEG mode.(These parameters will be valid after call lock channel function) r = AVL_DVBSx_IRx_SetMpegMode(&sMpegMode,pAVLChip ); if(sMpegMode.m_MpegMode == AVL_DVBSx_MPM_Serial) { AVL_DVBSx_IRx_SetMpegSerialPin(pAVLChip,pDemodTunerConfig->m_SerDataPin); } if(AVL_DVBSx_EC_OK != r) { printf("Set MPEG output mode failed !\n"); return (r); } // Enable the MPEG output (this function call has no effect for the AVL_DVBSxLG and AVL_DVBSxLGa devices) r = AVL_DVBSx_IRx_DriveMpegOutput(pAVLChip); //Setup tuner parameters for tuner initialization. pTuner->m_uiSlaveAddress = pDemodTunerConfig->m_uiTunerAddress; pTuner->m_uiI2CBusClock_kHz = pDemodTunerConfig->m_uiTuner_I2Cbus_clock; pTuner->m_pParameters = 0; pTuner->m_pAVLChip = pAVLChip; pTuner->m_pInitializeFunc = pDemodTunerConfig->m_pInitializeFunc; pTuner->m_pLockFunc = pDemodTunerConfig->m_pLockFunc; pTuner->m_pGetLockStatusFunc = pDemodTunerConfig->m_pGetLockStatusFunc; //This function should be called after IBase initialized to initialize the tuner. r = pTuner->m_pInitializeFunc(pTuner); if(AVL_DVBSx_EC_OK != r) { printf("Tuner Initialization failed !\n"); return (r); } //Setup DiSEqC parameters for DiSEqC initialization. sDiseqcPara.m_RxTimeout = AVL_DVBSx_DRT_150ms; sDiseqcPara.m_RxWaveForm = AVL_DVBSx_DWM_Normal; sDiseqcPara.m_ToneFrequency_kHz = Diseqc_Tone_Frequency; sDiseqcPara.m_TXGap = AVL_DVBSx_DTXG_15ms; sDiseqcPara.m_TxWaveForm = AVL_DVBSx_DWM_Normal; //The DiSEqC should be initialized if AVL_DVBSx need to supply power to LNB. This function should be called after IBase initialized to initialize the DiSEqC. r = AVL_DVBSx_IDiseqc_Initialize(&sDiseqcPara, pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("DiSEqC Initialization failed !\n"); } return (r); }
AVL_DVBSx_ErrorCode Initialize(struct AVL_DVBSx_Chip * pAVLChip) { struct AVL_DVBSx_Diseqc_Para sDiseqcPara; AVL_DVBSx_ErrorCode r=AVL_DVBSx_EC_OK; struct AVL_DVBSx_VerInfo VerInfo; //AVL_uint32 uiTemp; AVL_uint32 uiDeviceID=0; /* //This function should be implemented by customer. //This function should be called before all other functions to prepare everything for a BSP operation. r = AVL_DVBSx_IBSP_Initialize(); if( AVL_DVBSx_EC_OK !=r ) { printf("BSP Initialization failed !\n"); return (r); } */ // This function should be called after bsp initialized to initialize the chip object. r = Init_AVL_DVBSx_ChipObject(pAVLChip, AVL_DVBSx_SA_0); if( AVL_DVBSx_EC_OK !=r ) { printf("Chip Object Initialization failed !\n"); return (r); } //Judge the chip ID of current chip. r= AVL_DVBSx_IRx_GetDeviceID( pAVLChip, &uiDeviceID); //r = AVL_DVBSx_II2C_Read32(pAVLChip, rom_ver_addr, &uiTemp); if (AVL_DVBSx_EC_OK != r) { printf("Get Chip ID failed !\n"); return (r); } //if ( uiTemp != Chip_ID ) if(uiDeviceID != Chip_ID ) { printf("uiDeviceID:0x%x,Chip ID isn't correct!\n",uiDeviceID); return AVL_DVBSx_EC_GeneralFail; } //This function should be called after chip object initialized to initialize the IBase,using reference clock as 10M. Make sure you pickup the right pll_conf since it may be modified in BSP. r = AVL_DVBSx_IBase_Initialize(const_cast<AVL_DVBSx_PllConf *>(pll_conf+2), ucPatchData, pAVLChip); if( AVL_DVBSx_EC_OK !=r ) { printf("IBase Initialization failed !\n"); return (r); } AVL_DVBSx_IBSP_Delay(100); //Wait 100 ms to assure that the AVLDVBSx chip boots up.This function should be implemented by customer. //This function should be called to verify the AVLDVBSx chip has completed its initialization procedure. r = AVL_DVBSx_IBase_GetStatus(pAVLChip); if( AVL_DVBSx_EC_OK != r ) { printf("Booted failed !\n"); return (r); } printf("Booted !\n"); //Get Chip ID, Patch version and SDK version. AVL_DVBSx_IBase_GetVersion( &VerInfo, pAVLChip); printf("Chip Ver:{%d}.{%d}.{%d} API Ver:{%d}.{%d}.{%d} Patch Ver:{%d}.{%d}.{%d} \n", VerInfo.m_Chip.m_Major, VerInfo.m_Chip.m_Minor, VerInfo.m_Chip.m_Build, VerInfo.m_API.m_Major, VerInfo.m_API.m_Minor, VerInfo.m_API.m_Build, VerInfo.m_Patch.m_Major, VerInfo.m_Patch.m_Minor, VerInfo.m_Patch.m_Build); //This function should be called after IBase initialized to initialize the demod. r = AVL_DVBSx_IRx_Initialize(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Demod Initialization failed !\n"); return (r); } //This function should be called after demod initialized to set RF AGC polar. //User does not need to setup this for Sharp tuner since it is the default value. But for other tuners, user may need to do it here. r |= AVL_DVBSx_IRx_SetRFAGCPola(AVL_DVBSx_RA_Invert, pAVLChip); r |= AVL_DVBSx_IRx_DriveRFAGC(pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Set RF AGC Polar failed !\n"); return (r); } //This function should be called after demod initialized to set spectrum polar. r = AVL_DVBSx_IBase_SetSpectrumPolarity(AVL_DVBSx_Spectrum_Normal, pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("Set Spectrum Polar failed !\n"); return (r); } //Setup DiSEqC parameters for DiSEqC initialization. sDiseqcPara.m_RxTimeout = AVL_DVBSx_DRT_150ms; sDiseqcPara.m_RxWaveForm = AVL_DVBSx_DWM_Normal; sDiseqcPara.m_ToneFrequency_kHz = DiSEqC_Tone_Frequency; sDiseqcPara.m_TXGap = AVL_DVBSx_DTXG_15ms; sDiseqcPara.m_TxWaveForm = AVL_DVBSx_DWM_Normal; //This function should be called after IBase initialized to initialize the DiSEqC. r = AVL_DVBSx_IDiseqc_Initialize(&sDiseqcPara, pAVLChip); if(AVL_DVBSx_EC_OK != r) { printf("DiSEqC Initialization failed !\n"); } return (r); }