AVL_DVBSx_ErrorCode AVL_DVBSx_IBlindScanAPI_Start(struct AVL_DVBSx_Chip * pAVLChip, struct AVL_Tuner * pTuner, struct AVL_DVBSx_BlindScanAPI_Setting * pBSsetting)
{
	AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK;
	struct AVL_DVBSx_BlindScanPara * pbsPara = &pBSsetting->bsPara;

	r |= AVL_DVBSx_IBase_SetFunctionalMode(pAVLChip, AVL_DVBSx_FunctMode_BlindScan);
	r |= AVL_DVBSx_IBase_SetSpectrumPolarity(pBSsetting->m_eSpectrumMode,pAVLChip); 

	if(pBSsetting->BS_Mode)
	{
		pTuner->m_uiFrequency_100kHz = 10*pBSsetting->m_uiScan_Start_Freq_MHz + pBSsetting->m_uiTuner_MaxLPF_100kHz + (pBSsetting->m_uiScan_Bind_No) * pBSsetting->m_uiScan_Center_Freq_Step_100KHz;
		pbsPara->m_uiStartFreq_100kHz = pTuner->m_uiFrequency_100kHz - pBSsetting->m_uiTuner_MaxLPF_100kHz;
		pbsPara->m_uiStopFreq_100kHz =  pTuner->m_uiFrequency_100kHz + pBSsetting->m_uiTuner_MaxLPF_100kHz;
	}
	else
	{
		pbsPara->m_uiStartFreq_100kHz = pBSsetting->m_uiScan_Next_Freq_100KHz;
		pbsPara->m_uiStopFreq_100kHz = pBSsetting->m_uiScan_Next_Freq_100KHz + pBSsetting->m_uiTuner_MaxLPF_100kHz*2;
		pTuner->m_uiFrequency_100kHz = (pbsPara->m_uiStartFreq_100kHz + pbsPara->m_uiStopFreq_100kHz)/2;
	}

	pTuner->m_uiLPF_100kHz =  pBSsetting->m_uiTuner_MaxLPF_100kHz;
	
	r |= pTuner->m_pLockFunc(pTuner);	//Lock the tuner. 
	
	AVL_DVBSx_IBSP_Delay(50);		//wait a while for tuner to lock in certain frequency.
	
	r |= pTuner->m_pGetLockStatusFunc(pTuner);	 //Check the lock status of the tuner.
	if (AVL_DVBSx_EC_OK != r)		 
	{
		return r;
	}
			
	pbsPara->m_uiMaxSymRate_kHz = 1000*pBSsetting->m_uiScan_Max_Symbolrate_MHz;
	pbsPara->m_uiMinSymRate_kHz = 1000*pBSsetting->m_uiScan_Min_Symbolrate_MHz;
	
	r |= AVL_DVBSx_IBlindScan_Reset(pAVLChip);
	r |= AVL_DVBSx_IBlindScan_Scan(pbsPara,pBSsetting->m_uiTuner_MaxLPF_100kHz, pAVLChip);
	pBSsetting->m_uiScaning = 1;
	
	return r;
}
static int AVL6211_Blindscan_Scan(struct dvb_frontend* fe, struct dvbsx_blindscanpara *pbspara)
{
		AVL_DVBSx_IBSP_WaitSemaphore(&blindscanSem);
		blindstart=1;
		AVL_DVBSx_IBSP_ReleaseSemaphore(&blindscanSem);
		printk("[%s]\n",__FUNCTION__);
		AVL_DVBSx_ErrorCode r = AVL_DVBSx_EC_OK;
		struct AVL_DVBSx_BlindScanPara  pbsParaZ ;
		r |= AVL_DVBSx_IBase_SetFunctionalMode(pAVLChip_all, AVL_DVBSx_FunctMode_BlindScan);
		r |= AVL_DVBSx_IBase_SetSpectrumPolarity(0,pAVLChip_all); 
		avl6211pTuner->m_uiLPF_100kHz =  pbspara->m_uitunerlpf_100khz;
		avl6211pTuner->m_uiFrequency_100kHz = pbspara->m_uifrequency_100khz;
		r |= avl6211pTuner->m_pLockFunc(avl6211pTuner);	//Lock the tuner. 
		
		msleep(50);		//wait a while for tuner to lock in certain frequency.
		
		r |= avl6211pTuner->m_pGetLockStatusFunc(avl6211pTuner);	 //Check the lock status of the tuner.
		if (AVL_DVBSx_EC_OK != r)		 
		{
			return r;
		}

		r |= AVL_DVBSx_IBlindScan_Reset(pAVLChip_all);
		
	//	printf("m_uistartfreq_100khz is %d,m_uistartfreq_100khz is %d,m_uiminsymrate_khz is %d,,m_uimaxsymrate_khz is %d,m_uitunerlpf_100khz is %d\n",pbspara->m_uistartfreq_100khz,pbspara->m_uistopfreq_100khz,pbspara->m_uiminsymrate_khz,pbspara->m_uimaxsymrate_khz,pbspara->m_uitunerlpf_100khz);
		pbsParaZ.m_uiStartFreq_100kHz = pbspara->m_uifrequency_100khz-320;//pbspara->m_uistartfreq_100khz;//pbspara->m_uifrequency_100khz-320
		pbsParaZ.m_uiStopFreq_100kHz = pbspara->m_uifrequency_100khz+320;//pbspara->m_uistopfreq_100khz;//pbspara->m_uifrequency_100khz+320
		pbsParaZ.m_uiMinSymRate_kHz =2*1000;// pbspara->m_uiminsymrate_khz;
		pbsParaZ.m_uiMaxSymRate_kHz =45*1000;// pbspara->m_uimaxsymrate_khz;

		r |=AVL_DVBSx_IBlindScan_Scan(&pbsParaZ,340, pAVLChip_all);
		if(r== AVL_DVBSx_EC_OK)
		{
			pr_dbg("AVL_DVBSx_IBlindScan_Scan,OK\n");
		}
		return r;
}
Exemple #3
0
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);
}