📄 tuner.cpp
字号:
default:
// XuGuang JS-2S/126 tuner is compatible with Philips
pTunerDataExt->wTunerBandCtrlFM = kPhilipsBandCtrlFM; // 0xCEA4
pTunerDataExt->wTunerBandCtrlLow = kPhilipsBandCtrlLow; // 0xCEA0
pTunerDataExt->wTunerBandCtrlMid = kPhilipsBandCtrlMid; // 0xCE90
pTunerDataExt->wTunerBandCtrlHigh = kPhilipsBandCtrlHigh; // 0xCE30
break;
}
break;
// TunerBrand registry value = 3
case TUNER_BRAND_ALPS:
pTunerDataExt->wTunerBandCtrlLow = kAlpsBandCtrlLow; // 0xC214
pTunerDataExt->wTunerBandCtrlMid = kAlpsBandCtrlMid; // 0xC212
pTunerDataExt->wTunerBandCtrlHigh = kAlpsBandCtrlHigh; // 0xC211
break;
// TunerBrand registry value = 4
case TUNER_BRAND_PHILIPS_1236D:
// special case:
// set different control bytes for analog NTSC-M or digital ATSC on
// different inputs
TunerSetPhilips1236DCntrlBytes( pTunerDataExt );
break;
// TunerBrand registry value = 7
case TUNER_BRAND_THOMSON:
pTunerDataExt->wTunerBandCtrlLow = kThomson761xInBandCtrlLow; // 0x8E11
pTunerDataExt->wTunerBandCtrlMid = kThomson761xInBandCtrlMid; // 0x8E12
pTunerDataExt->wTunerBandCtrlHigh = kThomson761xInBandCtrlHigh;// 0x8E14
pTunerDataExt->wTunerBandCtrlFM = kThomson761xBandCtrlFM; // 0x8811
break;
// TunerBrand registry value = 8
case TUNER_BRAND_TCL2002MI3:
// TCL2002 MI-3 tuner is compatible with Philips 1236
pTunerDataExt->wTunerBandCtrlLow = kTCL2002MI3InBandCtrlLow; // 0xCE01
pTunerDataExt->wTunerBandCtrlMid = kTCL2002MI3InBandCtrlMid; // 0xCE02
pTunerDataExt->wTunerBandCtrlHigh = kTCL2002MI3InBandCtrlHigh; // 0xCE08
break;
default:
pTunerDataExt->wTunerBandCtrlLow = kTemicBandCtrlLow; // 0x8E02
pTunerDataExt->wTunerBandCtrlMid = kTemicBandCtrlMid; // 0x8E04
pTunerDataExt->wTunerBandCtrlHigh = kTemicBandCtrlHigh; // 0x8E01
break;
}
}
/*++ ********************************************************************\
*
* Function:
*
* void TunerInitialize( PHW_STREAM_REQUEST_BLOCK pSrb )
*
* Purpose:
*
* Initial tuner setup
*
* Return:
* none
*
* History:
*
*
\******************************************************************** --*/
void TunerInitialize( PHW_STREAM_REQUEST_BLOCK pSrb )
{
BOOL bStatus;
PPORT_CONFIGURATION_INFORMATION pConfigInfo = pSrb->CommandData.ConfigInfo;
PTUNER_DATA_EXTENSION pTunerDataExt = (PTUNER_DATA_EXTENSION)pConfigInfo->HwDeviceExtension;
NTSTATUS ntStatus = STATUS_ADAPTER_HARDWARE_ERROR;
// lets assume ntStatus = STATUS_ADAPTER_HARDWARE_ERROR, until
// everything is completely initialized correctly
pTunerDataExt->pPDO = pConfigInfo->PhysicalDeviceObject; // used for IoCallDriver
pTunerDataExt->realPDO = pConfigInfo->RealPhysicalDeviceObject; // used for registry access
pTunerDataExt->bNxtWaveSetup = FALSE; // set NxtWave demod to not initialized
pTunerDataExt->bDemodIsInSerialMode = TRUE; // set NxtWave demod mpeg mode to serial
pTunerDataExt->bTrackingThreadIsRunning = FALSE; // set tracking thread running flag to false
pTunerDataExt->pHDALL_Device = NULL;
pTunerDataExt->pHDALL_File = NULL;
pTunerDataExt->bAttemptedToOpenHDALL = FALSE;
pTunerDataExt->power_up_thread_object = NULL;
do
{
if( pConfigInfo->NumberOfAccessRanges != 0 )
{
DbgLogError(("[critical error]\n"));
DbgLogError(("No access ranges found.\n"));
DbgLogError(("Memory mapped registers not available.\n"));
DbgLogError(("Failing tuner driver load!\n"));
ntStatus = STATUS_NO_SUCH_DEVICE; // the only exception
break;
}
pTunerDataExt->i2c_interface.initialize(pTunerDataExt->pPDO);
TunerReadRegistryValues( pSrb );
if( !TunerSetCapabilities( pSrb ) || ( !pTunerDataExt->ulNumberOfPins ) )
{
break;
}
// initialize tuner pin and power state
pTunerDataExt->pTVTunerPinsMediumInfo = NULL;
pTunerDataExt->pTVTunerPinsDirectionInfo = NULL;
pTunerDataExt->ulPowerState = PowerDeviceD0;
pTunerDataExt->pTVTunerPinsMediumInfo = (PKSPIN_MEDIUM)ExAllocatePool( NonPagedPool, sizeof(KSPIN_MEDIUM) * pTunerDataExt->ulNumberOfPins );
if( pTunerDataExt->pTVTunerPinsMediumInfo == NULL )
{
DbgLogError(("pTVTunerPinsMediumInfo: ExAllocatePoolWithTag failed\n"));
break;
}
pTunerDataExt->pTVTunerPinsDirectionInfo = (PBOOL)ExAllocatePool( NonPagedPool, sizeof(BOOL) * pTunerDataExt->ulNumberOfPins );
if( pTunerDataExt->pTVTunerPinsDirectionInfo == NULL )
{
DbgLogError(("pTVTunerPinsDirectionInfo: ExAllocatePoolWithTag failed\n"));
break;
}
pTunerDataExt->CSNxtComm = (PFAST_MUTEX)ExAllocatePool(NonPagedPool, sizeof(FAST_MUTEX));
if ( pTunerDataExt->CSNxtComm == NULL )
{
DbgLogError(("CSNxtComm: ExAllocatePoolWithTag failed!!!\n"));
break;
}
pTunerDataExt->CSNxtTrack = (PFAST_MUTEX)ExAllocatePool(NonPagedPool, sizeof(FAST_MUTEX));
if ( pTunerDataExt->CSNxtTrack == NULL )
{
DbgLogError(("CSNxtTrack: ExAllocatePoolWithTag failed!!!\n"));
break;
}
//initialize mutex
KeInitializeMutex(&pTunerDataExt->_mutex, 0);
TunerSetTopology( pSrb );
pTunerDataExt->ulCurrentFrequency = 0L;
TunerSetFreqBands( pSrb );
setOpenDemodI2CChannel( pTunerDataExt );
pConfigInfo->StreamDescriptorSize = sizeof(HW_STREAM_HEADER);
ntStatus = STATUS_SUCCESS; // initialization completed correctly
} while( FALSE );
pSrb->Status = ntStatus;
return;
}
/*++ ********************************************************************\
*
* Function:
*
* void TunerCompleteInitialization( PHW_STREAM_REQUEST_BLOCK pSrb )
*
* Purpose:
*
* Get register the tuner filter and initialize the NxtWave
* demod. chip if tuner mode is ATSC and the board is a DStream.
*
* Return:
*
* none
*
* History:
*
*
\******************************************************************** --*/
void TunerCompleteInitialization( PHW_STREAM_REQUEST_BLOCK pSrb )
{
NTSTATUS ntStatus;
PTUNER_DATA_EXTENSION pTunerDataExt = (PTUNER_DATA_EXTENSION)pSrb->HwDeviceExtension;
ULONG board_id = 0;
BTTUNERINTERFACE tuner_interface;
tuner_interface.ulCommand = BTUNER_COMMAND_GET_BOARD_ID;
if(SendCommand(&tuner_interface, pTunerDataExt->pPDO))
{
board_id = tuner_interface.board_id;
}
TVTunerMediums[0].Id = board_id; //Video pin medium
TVTunerMediums[1].Id = board_id; //Audio pin medium
// Uses realPDO because this function accesses the registry.
// Win XP driver verifier requires this. NULL will also work.
ntStatus = StreamClassRegisterFilterWithNoKSPins( \
pTunerDataExt->realPDO,
&KSCATEGORY_TVTUNER,
SIZEOF_ARRAY(TVTunerMediums),
TVTunerPinDirection,
TVTunerMediums,
NULL );
if( !NT_SUCCESS( ntStatus ) )
{
DbgLogError(("TunerCompleteInitialization failed\n"));
pSrb->Status = STATUS_UNSUCCESSFUL;
}
else
{
pSrb->Status = STATUS_SUCCESS;
}
// if the tuner is a Philips 1236D, setup the NxtWave chip
if ( pTunerDataExt->ulTunerBrand == TUNER_BRAND_PHILIPS_1236D )
{
DemodNxtWaveSetup( pTunerDataExt );
}
}
/*++ ********************************************************************\
*
* Function:
*
* BOOL TunerUnInitialize( PHW_STREAM_REQUEST_BLOCK pSrb )
*
* Purpose:
*
* Free memory allocated for tuner pin info.
*
* Return:
*
* TRUE
*
* History:
*
*
\******************************************************************** --*/
BOOL TunerUnInitialize( PHW_STREAM_REQUEST_BLOCK pSrb )
{
PTUNER_DATA_EXTENSION pTunerDataExt = (PTUNER_DATA_EXTENSION)pSrb->HwDeviceExtension;
// just deallocate the any memory was allocated at run-time
if( pTunerDataExt->pTVTunerPinsMediumInfo != NULL )
{
ExFreePool( pTunerDataExt->pTVTunerPinsMediumInfo );
pTunerDataExt->pTVTunerPinsMediumInfo = NULL;
}
if( pTunerDataExt->pTVTunerPinsDirectionInfo != NULL )
{
ExFreePool( pTunerDataExt->pTVTunerPinsDirectionInfo );
pTunerDataExt->pTVTunerPinsDirectionInfo = NULL;
}
if ( pTunerDataExt->CSNxtComm != NULL )
{
ExFreePool( pTunerDataExt->CSNxtComm );
pTunerDataExt->CSNxtComm = NULL;
}
if ( pTunerDataExt->CSNxtTrack != NULL )
{
ExFreePool( pTunerDataExt->CSNxtTrack );
pTunerDataExt->CSNxtTrack = NULL;
}
// stop tracking and do NxtWave driver cleanup
if ( pTunerDataExt->bNxtWaveSetup )
{
DemodNxtWaveExit( pTunerDataExt );
NxtExitDriver( (void *)pTunerDataExt );
}
//Close the HDALL's file object if it was open.
if(pTunerDataExt->pHDALL_File)
ObDereferenceObject(pTunerDataExt->pHDALL_File);
//If the channel change thread is running (unlikely),
// wait for it to exit.
//
while(pTunerDataExt->channel_change_thread_object)
{
LARGE_INTEGER wait_time;
wait_time.QuadPart = -(_int64)300*10000; //300 millisecond
KeDelayExecutionThread(KernelMode,
FALSE,
&wait_time);
}
pSrb->Status = STATUS_SUCCESS;
return ( TRUE );
}
/*++ ********************************************************************\
*
* Function:
*
* BOOL TunerGetStreamInfo( PHW_STREAM_REQUEST_BLOCK pSrb )
*
* Purpose:
*
* Get tuner stream information
*
* Return:
*
* TRUE
*
* History:
*
*
\******************************************************************** --*/
BOOL TunerGetStreamInfo( PHW_STREAM_REQUEST_BLOCK pSrb )
{
PHW_STREAM_HEADER pStreamHeader = (PHW_STREAM_HEADER)&( pSrb->CommandData.StreamBuffer->StreamHeader );
PTUNER_DATA_EXTENSION pTunerDataExt = (PTUNER_DATA_EXTENSION)pSrb->HwDeviceExtension;
// no streams are supported
DEBUG_ASSERT( pSrb->NumberOfBytesToTransfer >= sizeof(HW_STREAM_HEADER) );
pTunerDataExt->wdmTunerStreamHeader.NumberOfStreams = 0;
pTunerDataExt->wdmTunerStreamHeader.SizeOfHwStreamInformation = sizeof(HW_STREAM_INFORMATION);
pTunerDataExt->wdmTunerStreamHeader.NumDevPropArrayEntries = NUMBER_OF_ADAPTER_PROPERTY_SETS;
pTunerDataExt->wdmTunerStreamHeader.DevicePropertiesArray = (PKSPROPERTY_SET) TunerPropertySet;
pTunerDataExt->wdmTunerStreamHeader.NumDevEventArrayEntries = 0;
pTunerDataExt->wdmTunerStreamHeader.DeviceEventsArray = NULL;
pTunerDataExt->wdmTunerStreamHeader.Topology = &pTunerDataExt->wdmTunerTopology;
*pStreamHeader = pTunerDataExt->wdmTunerStreamHeader;
pSrb->Status = STATUS_SUCCESS;
return ( TRUE );
}
/*++ ********************************************************************\
*
* Function:
*
* BOOL TunerQueryUnload( PHW_STREAM_REQUEST_BLOCK pSrb )
*
* Purpose:
*
* Return SRB status as success
*
* Return:
*
* TRUE
*
* History:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -