📄 device.cpp
字号:
if(rev_id >=POLARIS_REVID_A0)
{
if((pcb_config->type == USB_BUS_POWER) && (getPowerMode() != POLARIS_AVMODE_ENXTERNAL_AV))
{
setPowerMode(POLARIS_AVMODE_ENXTERNAL_AV); //tuner
}
}
_p_decoder->setVideoInput(pin_input_type, input_mux); //need check
break;
}
case AUDIO_INPUT_TUNER:
{
//This setting is only valid if we have a tuner.
DWORD current_mode = KSPROPERTY_TUNER_MODE_TV;
if (_p_tuner_properties)
current_mode = _p_tuner_properties->get_mode();
if( current_mode == KSPROPERTY_TUNER_MODE_FM_RADIO )
{
_p_audio->setAudioInput(Merlin::AUDIO_INPUT_TUNER_FM);
}
else
{
_p_audio->setAudioInput(Merlin::AUDIO_INPUT_TUNER_TV);
}
break;
}
case AUDIO_INPUT_LINE:
{
//TODO, ask Alsor about Line in register setting
_p_flatrion->setAudioInput(Flatrion::AUDIO_INPUT_LINE);
_p_audio->setAudioInput(Merlin::AUDIO_INPUT_LINE);
break;
}
case AUDIO_INPUT_MUTE:
{
_p_audio->setAudioInput(Merlin::AUDIO_INPUT_MUTE);
break;
}
default:
break;
}
PostCrossbarChange();
}
/////////////////////////////////////////////////////////////////////////////////////////
//Switch the tuner between TV and FM
VOID Device::setMode(ULONG mode)
{
Merlin::AUDIO_INPUT current_input = _p_audio->getAudioInput();
if((current_input != Merlin::AUDIO_INPUT_TUNER_TV) &&
(current_input != Merlin::AUDIO_INPUT_TUNER_FM))
{
//Do nothing if we are not on tuner audio input
return;
}
Merlin::AUDIO_INPUT new_audio_input = Merlin::AUDIO_INPUT_TUNER_TV;
if(mode == KSPROPERTY_TUNER_MODE_FM_RADIO)
{
new_audio_input = Merlin::AUDIO_INPUT_TUNER_FM;
}
//Do nothing if we are already in the correct mode
if(new_audio_input == current_input)
{
return;
}
if(mode == KSPROPERTY_TUNER_MODE_FM_RADIO)
{
_p_audio->setAudioInput(Merlin::AUDIO_INPUT_TUNER_FM);
}
else
{
_p_audio->setAudioInput(Merlin::AUDIO_INPUT_TUNER_TV);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
VOID Device::notifyPreChannelChange()
{
if(_p_audio)
{
//_p_audio->notifyPreChannelChange();
}
if(_p_decoder)
{
//_p_decoder->notifyPreChannelChange();
}
}
/////////////////////////////////////////////////////////////////////////////////////////
VOID Device::notifyPostChannelChange()
{
if(_p_decoder)
{
_p_decoder->notifyPostChannelChange();
}
if(_p_audio)
{
_p_audio->notifyPostChannelChange();
}
}
//////////////////////////////////////////////////////
//Enable or disable Pnp interface
NTSTATUS Device::EnablePnpInterface(BOOLEAN bEnable)
{
//return STATUS_SUCCESS;
NTSTATUS status=STATUS_UNSUCCESSFUL;
status=IoSetDeviceInterfaceState(&_dev_pnp_interface_name,bEnable);
if(NT_SUCCESS(status) && !bEnable)
{
RtlFreeUnicodeString(&_dev_pnp_interface_name);
}
if(!NT_SUCCESS(status))
{
DbgLogError(("Failed to EnablePnpInterface(bEnable=%d)\n",bEnable));
}
return status;
}
///////////////////////////////////////////
//To register Pnp interface
NTSTATUS Device::RegisterPnpInterface()
{
//return STATUS_SUCCESS;
NTSTATUS status=STATUS_UNSUCCESSFUL;
// Register device interfaces
status = IoRegisterDeviceInterface(getPdo(),
&GUID_CLASS_EVKDVT_CXPOLARIS,
NULL,
&_dev_pnp_interface_name);
if(!NT_SUCCESS(status))
{
DbgLogError(("Failed to register device interface for Pnp events! \n"));
}
return status;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Polaris Sidewinder SawFilter Alair
// POLARIS_BOARD_DVT: 56M 56M Temex 56M
//
// POLARIS_BOARD_EVK: 48M 48M Sawtek 56M
/////////////////////////////////////////////////////////////////////////////////////////
NTSTATUS Device::init(CM_RESOURCE_LIST* p_resource_list)
{
// DbgBreakPoint();
#if DBG
//For debug builds, dump the driver registry key to the debugger.
WCHAR driver_key[100];
DWORD key_length;
if(NT_SUCCESS(IoGetDeviceProperty(
getPdo(),
DevicePropertyDriverKeyName,
sizeof(driver_key),
driver_key,
&key_length)))
{
driver_key[key_length] = '\0';
DbgLog(("Driver key = %S\n", driver_key));
}
#endif
DbgLogInfo(("Device::init : initializing all objects\n"));
RegistryAccess registry( _p_ks_dev->PhysicalDeviceObject );
//Initialize that no pins have acquired resources
for(DWORD i = 0; i < PIN_TYPE_MAX_NUM; i++)
{
_p_pins_with_resources[i] = NULL;
}
//We do not need any hardware resources on this board, since all hardware
//access is done by sending IRPs to the USB bus driver.
// By PnP, it's possible to receive multiple starts without an
// intervening stop (to reevaluate resources, for example).
// Hardware drivers with resources should evaluate resources
// and make changes on 2nd start.
if( _inited )
unInit();
NTSTATUS status = STATUS_SUCCESS;
//Initialize USB interface and EZ-USB firmware objects.
_p_usb = new CUsbInterface(_p_ks_dev->PhysicalDeviceObject);
if(_p_usb)
{
status = _p_usb->InitDevice();
}
else
{
status = STATUS_INSUFFICIENT_RESOURCES;
}
if(!NT_SUCCESS(status) || !_p_usb)
{
unInit();
return status;
}
DbgLogInfo(("Device::init : initializing USB successful\n"));
// read Enable Soft encoder
DWORD enable_soft_encoder = 0;
registry.readDword("Enable_SW_Encoder", &enable_soft_encoder);
enable_soft_encoder? _enable_soft_encoder = TRUE: _enable_soft_encoder = FALSE;
//get string descriptor
DWORD actSize = 0;
WCHAR wzSerialNumber[32];
POLARIS_REV_ID rev_id = (POLARIS_REV_ID)_p_usb->getRevID();
RtlZeroMemory(wzSerialNumber, 32);
if(rev_id >=POLARIS_REVID_A0)
{
status = _p_usb->getUsbSerialNumber(wzSerialNumber,32, &actSize);
if(!NT_SUCCESS(status))
{
DbgLogError(("Failed to get string descriptor\n"));
}
}
_p_usb_firmware = new PolarisUsbInterface(_p_usb);
if(_p_usb_firmware)
{
DWORD i2c_speed;
registry.readDword("I2CSpeed", &i2c_speed);
status = _p_usb_firmware->InitDevice();
if(( I2C_SPEED_5M == i2c_speed)&&(POLARIS_REVID_T0 == rev_id))
{
DbgLog(("Polaris T0 donot support I2C speed as 5Mb/s , change to 1Mb/s\n"));
i2c_speed = I2C_SPEED_1M;
}
setI2CSpeedMode((BYTE)i2c_speed);
}
else
{
status = STATUS_INSUFFICIENT_RESOURCES;
}
if( (!NT_SUCCESS(status)) || !_p_usb_firmware )
{
unInit();
return status;
}
DbgLogInfo(("Device::init : initializing polaris firmware successful\n"));
//There is a strange case where the driver loads twice, the first time
// with no available endpoints. If that is the case, we should fail
// as soon as possible so the driver can reload with the correct settings.
if(_p_usb->getNumberOfPipes(0) == 0)
{
status = STATUS_DEVICE_NOT_READY;
}
if(!NT_SUCCESS(status))
{
unInit();
return status;
}
/////////////////////////////////////////////////////////////////////////
GetBoardAndChipType();
_p_current_config = new PcbConfig(_p_ks_dev->PhysicalDeviceObject,_p_usb,_p_usb_firmware);
if(_p_current_config)
{
if(rev_id == POLARIS_REVID_T0)
{
DbgLog(("the revision is T0\n"));
status = _p_current_config->initialize_T0();
}
else if(rev_id >=POLARIS_REVID_A0)
{
DbgLog(("the revision is A0\n"));
_current_config_num = 0;
status = _p_current_config->initialize_A0();
}
else
{
status = STATUS_UNSUCCESSFUL;
DbgLog(("Invalid revision ID\n"));
}
}
else
{
status = STATUS_INSUFFICIENT_RESOURCES;
}
if( !NT_SUCCESS(status) || !_p_current_config )
{
unInit();
return status;
}
_usb_speed = _p_current_config->getUsbSpeed();
if(rev_id >=POLARIS_REVID_A0)
{
if(getUSBType()==USB_BUS_POWER)
{
status = prePowerControl();
if(!NT_SUCCESS(status))
{
unInit();
return status;
}
}
}
//////////////////////////////////////////////////////////////////////////
// allocate objects
status = initObjects();
if(!NT_SUCCESS(status))
{
unInit();
return status;
}
_bda_demod_tuner_type = TUNER_DEMOD_TYPE_ALTAIR_SIDEWINDER;
registry.readDword("BDA_Demod_Tuner_Type", &_bda_demod_tuner_type);
//Create the filter factories
status = createFilterFactories();
if(!NT_SUCCESS(status))
{
unInit();
return status;
}
// once the tuner filter is created, we will generate a Serial number
// based on USB serial number
if(rev_id >=POLARIS_REVID_A0)
{
status = RegisterTuner(wzSerialNumber);
if(!NT_SUCCESS(status))
{
DbgLogError(("Failed to register tuner\n"));
unInit();
return status;
}
}
DWORD tuner_type = TUNER_TYPE_NOT_DEFINED;
registry.readDword( "TunerType", &tuner_type );
PPCB_CONFIG pcb_config = NULL;
pcb_config = _p_current_config->getCurrentPcb();
if(pcb_config==NULL)
{
unInit();
return STATUS_UNSUCCESSFUL;
}
_usb_type=pcb_config->type;
//Allocate the BDA tuner/demod. Note that the tuner/demod will sometimes
// require a special I2C interface that goes through the demod.
I2cIF* p_tuner_i2c = NULL;
if((pcb_config->mode & (MOD_ANALOG | MOD_DIF |MOD_EXTERNAL)))
{
// Create Analog Tuner
if(!_p_AnalogI2C || !createAnalogTunerProperties(tuner_type, _p_AnalogI2C))
{
unInit();
return STATUS_INSUFFICIENT_RESOURCES;
}
}
else
{
DbgLogInfo(("Warning: Analog tuner will not be available!\n"));
}
if(pcb_config->mode & MOD_DIGITAL)
{
p_tuner_i2c = createBdaTuner(_bda_demod_tuner_type);
if(!_p_bda_tuner || !p_tuner_i2c)
{
unInit();
return STATUS_INSUFFICIENT_RESOURCES;
}
}
else
{
DbgLogInfo(("Warning: This scenario will not support digital BDA graph!\n"));
}
// AGC mux for Demod/Analog
// 0 - Demod, 1 - Analog
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -