📄 hwctxt.cpp
字号:
}
#endif
}
void HardwareContext::InitCodec(void)
{
static DWORD VendorId=0;
unsigned short int VidTemp=0;
unsigned short int Ac97RegisterData=0;
unsigned short int FeatureCrs1Data=0;
DEBUGMSG(ZONE_INIT, (TEXT("HardwareContext::InitCodec\r\n")));
//Get vendor ID
if(VendorId == 0)
{
SafeReadCodec(VENDOR_ID1, &VidTemp, DEV_AUDIO);
VendorId= (VidTemp <<16); //ffffffffssssssss // f=first ascii s = second ascii
SafeReadCodec(VENDOR_ID2, &VidTemp, DEV_AUDIO);
VendorId |=VidTemp; //ttttttttrrrrrrrr //t = third ascii, r=rev #
VendorId &= 0xfffffff0;//trim of version number
}
//
//compliant codecs such as Crystal require the PCM volume
//if it's a ucb1400 then don't write the PCM volume (although it shouldn't hurt)
//
//vendor specific
switch (VendorId)
{
case 0x50534300: //philips UCB1400
SafeWriteCodec(FEATURE_CSR2, PWR_SMART_CODEC, DEV_AUDIO);
//
//CAREFULL, writing the FEATURE_CSR1 could mess up the touch screen
//
SafeReadCodec(FEATURE_CSR1,&Ac97RegisterData, DEV_AUDIO);
Ac97RegisterData = Ac97RegisterData & EQ_MASK; //get just EQ data
SafeReadCodec(FEATURE_CSR1,&FeatureCrs1Data, DEV_AUDIO);
//mask off eq data
FeatureCrs1Data = FeatureCrs1Data & 0x8000; // lob off reserved bit (must be 0)
FeatureCrs1Data = FeatureCrs1Data & ~EQ_MASK; // lob off eq data
FeatureCrs1Data = FeatureCrs1Data | Ac97RegisterData; // stored EQ data with actual Feature data
//comment out headphone enable to save power, use an app to turn it on instead
//HACK: If the capabiliters reads 0x2a0 it's rev 2a, if its 0x2a then its rev 1b.
// SafeReadCodec(0, (UINT16 *)&m_ResetCaps, DEV_TOUCH);
if (m_ResetCaps==REV_2A)
{
FeatureCrs1Data = FeatureCrs1Data | (unsigned short) HPEN_MASK; //turn on head phone
m_CodecType=UCB14002A;
DEBUGMSG(ZONE_VERBOSE, (TEXT( "-- UCB14002A \r\n") ) );
}
else
{
m_CodecType=UCB14001B;
DEBUGMSG(ZONE_VERBOSE, (TEXT( "-- UCB14001b \r\n") ) );
}
SafeWriteCodec(FEATURE_CSR1, FeatureCrs1Data, DEV_AUDIO);
break;
case 0x10ec1000: //ALC5610
case 0x10ec2000: //ALC5620
case 0x10ec2100: //ALC5621
case 0x10ec2200: //ALC5622
case 0x10ec2300: //ALC5623
m_RTCodec->ChangeCodecPowerStatus(POWER_STATE_D1);
OSTDelayMilliSecTime(20);
m_RTCodec->InitRTCodecReg();
break;
default: //vanilla AC97
SafeWriteCodec(PCM_OUT_VOL, 0x1f1f, DEV_AUDIO);
DEBUGMSG(ZONE_VERBOSE, (TEXT( "-- vanilla AC97 \r\n") ) );
break;
}
return;
}
void HardwareContext::DeInitCodec(void)
{
DEBUGMSG(ZONE_INIT, (TEXT("HardwareContext::DeInitCodec\r\n")));
// Power down Codec
// SafeWriteCodec(XLLP_AC97_CR_POWERDOWN_CTRL_STAT, 0x1000, DEV_AUDIO);
return;
}
void HardwareContext::PowerDown()
{
m_Sleeping=TRUE;
m_RTCodec->ChangeCodecPowerStatus(POWER_STATE_D3);
m_OutputDMARunning=FALSE;
m_InputDMARunning=FALSE;
DEBUGMSG(ZONE_FUNCTION | ZONE_VERBOSE, (TEXT("WaveDev2: PowerDown\r\n")));
#if USE_I2S_INTERFACE
//Power down IIs link
UnConfigureI2SControl();
#else
// Power down AC97 link
UnConfigureAC97Control();
#endif
} // PowerDown()
void HardwareContext::PowerUp()
{
//Basic Outline:
// configue the GPIO registers
// Set hardcoded values like variable rate audio
// Set the BCR values (for sandgate)
// set volume
// set record select
// set EQ values (bass, treble, and mode
// Clear Audio Mute (output & input)
//m_vpBLReg->misc_wr2 &= ~(0x1 << 2); // switch on the amplifier
#if USE_I2S_INTERFACE
// Initialize GPIO and enable IIS link
ConfigureI2SControl();
#else
// Initialize GPIO and power up AC97 link
ConfigureAC97Control();
#endif
// Clear DMA status
ClearDmac(m_RecordingChannel);
ClearDmac(m_PlaybackChannel);
InterruptDone(m_SysIntrAudioDMA);
if (TRUE == m_InPowerHandler)
{
m_Sleeping=FALSE;
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("Wavedev:HardwareContext::PowerUp: Done\r\n")));
}
// Control the hardware speaker enable
void HardwareContext::SetSpeakerEnable(BOOL bEnable)
{
// Code to turn speaker on/off here
return;
}
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// RecalcSpeakerEnable decides whether to enable the speaker or not.
// For now, it only looks at the m_bForceSpeaker variable, but it could
// also look at whether the headset is plugged in
// and/or whether we're in a voice call. Some mechanism would
// need to be implemented to inform the wave driver of changes in the state of
// these variables however.
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
void HardwareContext::RecalcSpeakerEnable()
{
SetSpeakerEnable(m_NumForcedSpeaker);
}
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// SetForceSpeaker is called from the device context to update the state of the
// m_bForceSpeaker variable.
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
DWORD HardwareContext::ForceSpeaker( BOOL bForceSpeaker )
{
// If m_NumForcedSpeaker is non-zero, audio should be routed to an
// external speaker (if hw permits).
if (bForceSpeaker)
{
m_NumForcedSpeaker++;
if (m_NumForcedSpeaker==1)
{
RecalcSpeakerEnable();
}
}
else
{
m_NumForcedSpeaker--;
if (m_NumForcedSpeaker==0)
{
RecalcSpeakerEnable();
}
}
return MMSYSERR_NOERROR;
}
short int HardwareContext::MsgWriteCodec(DWORD dwParam1,DWORD dwParam2)
{
DEBUGMSG(ZONE_VERBOSE, (TEXT( "write %x %x \r\n" ),dwParam1,dwParam2));
SafeWriteCodec((BYTE)dwParam1,(unsigned short int)dwParam2, DEV_AUDIO );
return (MMSYSERR_NOERROR);
}
short int HardwareContext::MsgReadCodec(DWORD dwParam1,DWORD dwParam2)
{
unsigned short int MyData=0;
DEBUGMSG(ZONE_VERBOSE, (TEXT( "read %x %x \r\n" ),dwParam1,MyData ));
SafeReadCodec((BYTE)dwParam1, &MyData, DEV_AUDIO);
if (dwParam2 != (unsigned short int) NULL)
* (unsigned short int *) dwParam2 = MyData;
return (MMSYSERR_NOERROR);
}
/*
#define RIL_AUDIO_NONE (0x00000000) // @constdefine No audio devices
#define RIL_AUDIO_HANDSET (0x00000001) // @constdefine Handset
#define RIL_AUDIO_SPEAKERPHONE (0x00000002) // @constdefine Speakerphone
#define RIL_AUDIO_HEADSET (0x00000003) // @constdefine Headset
#define RIL_AUDIO_CARKIT (0x00000004) // @constdefine Carkit
*/
BOOL HardwareContext::SetCfgHeadSet()
{
return TRUE;
}
BOOL HardwareContext::SetCfgHandSet()
{
return TRUE;
}
BOOL HardwareContext::SetCfgSpeakerPhone()
{
return TRUE;
}
BOOL HardwareContext::SetCfgCarKit()
{
return TRUE;
}
BOOL HardwareContext::SetCfgNone()
{
return TRUE;
}
//------------------------------------------------------------------------------------------------------------
// Function: MapDMADescriptors
//
// Purpose: Map the physical DMA Descriptors into virtual space
//
// Returns: TRUE indicates success. FALSE indicates failure
//
//-------------------------------------------------------------------------------------------------------------
BOOL HardwareContext::MapDMADescriptors(void)
{
DMA_ADAPTER_OBJECT Adapter;
PHYSICAL_ADDRESS PA;
Adapter.ObjectSize = sizeof(DMA_ADAPTER_OBJECT);
Adapter.InterfaceType = Internal;
Adapter.BusNumber = 0;
m_vpAudioRcvA = (DMADescriptorChannelType *) HalAllocateCommonBuffer(&Adapter, 0x20, &PA, FALSE);
if (m_vpAudioRcvA)
{
m_vpAudioRcvA_Physical = (DMADescriptorChannelType *) PA.LowPart;
}
m_vpAudioRcvB = (DMADescriptorChannelType *) HalAllocateCommonBuffer(&Adapter, 0x20, &PA, FALSE);
if (m_vpAudioRcvB)
{
m_vpAudioRcvB_Physical = (DMADescriptorChannelType *) PA.LowPart;
}
m_vpAudioXmitA = (DMADescriptorChannelType *) HalAllocateCommonBuffer(&Adapter, 0x20, &PA, FALSE);
if (m_vpAudioXmitA)
{
m_vpAudioXmitA_Physical = (DMADescriptorChannelType *) PA.LowPart;
}
m_vpAudioXmitB = (DMADescriptorChannelType *) HalAllocateCommonBuffer(&Adapter, 0x20, &PA, FALSE);
if (m_vpAudioXmitB)
{
m_vpAudioXmitB_Physical = (DMADescriptorChannelType *) PA.LowPart;
}
if (!m_vpAudioRcvA || !m_vpAudioRcvB ||
!m_vpAudioXmitA || !m_vpAudioXmitB)
{
DEBUGMSG(ZONE_ERROR, (TEXT("ERROR: MapDMADescriptors: failed to allocate DMA descriptor buffer(s).\r\n")));
return(FALSE);
}
return (TRUE);
}
//------------------------------------------------------------------------------------------------------------
// Function: MapDeviceRegisters
//
// Purpose: Map the On-chip Device registers required for the audio driver.
//
// Returns: TRUE indicates success. FALSE indicates failure
//
//-------------------------------------------------------------------------------------------------------------
BOOL HardwareContext::MapDeviceRegisters(void)
{
PHYSICAL_ADDRESS PA;
PA.QuadPart = BULVERDE_BASE_REG_PA_DMAC;
m_pDMARegisters = (volatile BULVERDE_DMA_REG *) MmMapIoSpace(PA, sizeof(BULVERDE_DMA_REG), FALSE);
#if USE_I2S_INTERFACE
PA.QuadPart = BULVERDE_BASE_REG_PA_I2S;
m_pI2SRegs = (volatile XLLP_I2S_T *) MmMapIoSpace(PA, sizeof(XLLP_I2S_T), FALSE);
#else
PA.QuadPart = BULVERDE_BASE_REG_PA_AC97;
m_pAc97regs = (volatile XLLP_AC97_T *) MmMapIoSpace(PA, sizeof(XLLP_AC97_T), FALSE);
#endif
PA.QuadPart = BULVERDE_BASE_REG_PA_GPIO;
m_pGPIORegisters = (volatile XLLP_GPIO_T *) MmMapIoSpace(PA, sizeof(XLLP_GPIO_T), FALSE);
PA.QuadPart = BULVERDE_BASE_REG_PA_OST;
m_pOSTimer = (volatile XLLP_OST_T *) MmMapIoSpace(PA, sizeof(XLLP_OST_T), FALSE);
PA.QuadPart = BULVERDE_BASE_REG_PA_CLKMGR;
m_pClockRegs = (volatile XLLP_CLKMGR_T *) MmMapIoSpace(PA, sizeof(XLLP_CLKMGR_T), FALSE);
PA.QuadPart = MAINSTONEII_BASE_REG_PA_FPGA;
m_vpBLReg = (volatile MAINSTONEII_BLR_REGS *) MmMapIoSpace(PA, sizeof(MAINSTONEII_BLR_REGS), FALSE);
#if USE_I2S_INTERFACE
if (!m_pDMARegisters || !m_pI2SRegs || !m_pGPIORegisters || !m_pOSTimer || !m_pClockRegs || !m_vpBLReg)
#else
if (!m_pDMARegisters || !m_pAc97regs || !m_pGPIORegisters || !m_pOSTimer || !m_pClockRegs || !m_vpBLReg)
#endif
{
DEBUGMSG(ZONE_ERROR, (TEXT("ERROR: MapDeviceRegisters: failed to map device register(s).\r\n")));
return(FALSE);
}
return (TRUE);
}
BOOL HardwareContext::InitAudioDMA()
{
_TCHAR EventName[20];
DWORD dwDMAIrq = IRQ_DMAC;
// Covert the hardwre DMA controller interrupt IRQ into a logical SYSINTR value
if(m_SysIntrAudioDMA == SYSINTR_UNDEFINED)
{
if(!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwDMAIrq, sizeof(DWORD), &m_SysIntrAudioDMA, sizeof(DWORD), NULL))
{
DEBUGMSG(ZONE_ERROR, (TEXT("Error obtaining DMA interrupt SYSINTR value!\n")));
return (FALSE);
}
}
// Install the DMA ISR handler
if(m_hDMAIsrHandler == NULL)
{
GIISR_INFO Info;
HANDLE hBusAccessHandle;
PVOID PhysAddr;
DWORD inIoSpace = 0; // io space
PHYSICAL_ADDRESS DmaRegisterAddress = {DMA_INTERRUPT_REGISTER, 0};
m_hDMAIsrHandler = LoadIntChainHandler(g_wszDmaIsrDll,
g_wszDmaIsrHandler,
(BYTE)dwDMAIrq);
if(m_hDMAIsrHandler == NULL)
{
DEBUGMSG(ZONE_ERROR, (TEXT("LoadIntChainHandler (%s, %s, %d) failed!\r\n"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -