📄 wm8753power.c
字号:
}
else
#endif /* WM_CACHE_POWER_STATE */
{
/*
* Get the current power status of the device.
*/
for ( powerLoop = 0; powerLoop < WM8753_MAX_POWER_REGS; powerLoop++ )
{
status = WMRead( hDevice, powerReg++, &powerVal[powerLoop] );
if ( WM_ERROR( status ) )
{
goto error;
}
}
#if WM_CACHE_POWER_STATE
if ( pDeviceContext->v_pWMData )
{
pDeviceContext->v_pWMData->flags |= WM_POWERREG_VALID;
}
#endif /* WM_CACHE_POWER_STATE */
}
/*
* Disable audio. All or nothing for now.
* Recommended power-down sequence is
*/
if ( powerDown & WM_POWER_AUDIO )
{
if ( powerDown & WM_POWER_OUTPUTS )
{
powerVal[PWR_REG_3] &= ~WM8753_PWR3_OUTPUT;
}
if ( powerDown & WM_POWER_AUDIO_HIFI_DAC )
{
powerVal[PWR_REG_1] &= ~WM8753_PWR1_HIFIDAC;
}
if ( powerDown & WM_POWER_AUDIO_VOICE_DAC )
{
powerVal[PWR_REG_1] &= ~WM8753_PWR1_VXDAC;
}
if ( powerDown & WM_POWER_AUDIO_HIFI_ADC )
{
powerVal[PWR_REG_2] &= ~WM8753_PWR2_ADC;
}
if ( powerDown & WM_POWER_MIXERS )
{
powerVal[PWR_REG_2] &= ~WM8753_PWR2_MIX;
powerVal[PWR_REG_4] &= ~WM8753_PWR4_MIX;
}
if ( powerDown & WM_POWER_INPUTS )
{
powerVal[PWR_REG_2] &= ~WM8753_PWR2_MICAMPEN;
}
if ( powerDown & WM_POWER_CLOCK )
{
powerVal[PWR_REG_1] |= WM8753_PWR1_DIGENB;
}
/*
* Set to 500kOhm divider for low-power standby and
* disable VREF.
*/
if ( powerDown & WM_POWER_VREF )
{
powerVal[PWR_REG_1] |= ( WM8753_PWR1_VMIDSEL_500KOHM &
WM8753_PWR1_VMIDSEL_MASK );
powerVal[PWR_REG_1] &= ~ WM8753_PWR1_VREF;
}
if ( (powerDown & (WM_POWER_VREF | WM_POWER_MIXERS))
&& 0 == (newPowered & (WM_POWER_VREF | WM_POWER_MIXERS))
)
{
WMPlatformDisableAmplifiers( hDevice );
}
/* Set up powerReg so that it starts with the first power register. */
powerReg = WM8753_PWR_MGMT_1;
for ( powerLoop = 0; powerLoop < WM8753_MAX_POWER_REGS; powerLoop++ )
{
status = WMWrite( hDevice, powerReg++, powerVal[powerLoop] );
if ( WM_ERROR( status ) )
{
goto error;
}
}
/*
* If we've been told to power down everything, make sure really
* everything is powered down (even things we didn't power up
* ourselves).
*/
if ( WM_POWER_ALL == powerSections )
{
powerVal[PWR_REG_1] = WM8753_PWR1_VMIDSEL_500KOHM | WM8753_PWR1_DIGENB;
powerVal[PWR_REG_2] = 0;
powerVal[PWR_REG_3] = 0;
powerVal[PWR_REG_4] = 0;
/* Set up powerReg so that it starts with the first power register. */
powerReg = WM8753_PWR_MGMT_1;
for ( powerLoop = 0; powerLoop < WM8753_MAX_POWER_REGS; powerLoop++ )
{
status = WMWrite( hDevice, powerReg++, powerVal[powerLoop] );
if ( WM_ERROR( status ) )
{
goto error;
}
}
}
}
/*
* Remember what we've got powered up.
*/
#if WM_CACHE_POWER_STATE
if ( pDeviceContext->v_pWMData )
{
for ( powerLoop = 0; powerLoop < WM8753_MAX_POWER_REGS; powerLoop++ )
{
pDeviceContext->v_pWMData->powerReg[powerLoop] = powerVal[powerLoop];
}
pDeviceContext->v_pWMData->WmPower = newPowered;
}
#endif /* WM_CACHE_POWER_STATE */
/*
* We're done.
*/
done:
return WMS_SUCCESS;
/*
* Error cleanup.
*/
error:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WM8753GetCurrentPower
*
* Returns the current power state by looking at the register.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_POWERFLAG
* The current power state.
*---------------------------------------------------------------------------*/
WM_POWERFLAG WM8753GetCurrentPower( WM_DEVICE_HANDLE hDevice )
{
WM_POWERFLAG currentPower = 0;
WM_REGTYPE powerVal[WM8753_MAX_POWER_REGS];
WM_REGTYPE powerReg = WM8753_PWR_MGMT_1;
int powerLoop;
WMSTATUS status;
/*
* Get the current power status of the device.
*/
for ( powerLoop = 0; powerLoop < WM8753_MAX_POWER_REGS; powerLoop++ )
{
status = WMRead( hDevice, powerReg++, &powerVal[powerLoop] );
if ( WM_ERROR( status ) )
{
goto done;
}
}
/*
* Convert from register values to power flags.
* Note the register values are "powered on".
*/
currentPower |= WM_POWER_LINK;
if ( !( powerVal[PWR_REG_1] & WM8753_PWR1_DIGENB ) )
{
currentPower |= WM_POWER_CLOCK;
}
if ( powerVal[PWR_REG_2] & WM8753_PWR2_ADC )
{
currentPower |= WM_POWER_AUDIO_HIFI_ADC;
}
if ( powerVal[PWR_REG_1] & WM8753_PWR1_HIFIDAC )
{
currentPower |= WM_POWER_AUDIO_HIFI_DAC;
}
if ( powerVal[PWR_REG_1] & WM8753_PWR1_VXDAC )
{
currentPower |= WM_POWER_AUDIO_VOICE_DAC;
}
if ( ( powerVal[PWR_REG_2] & WM8753_PWR2_MIX ) ||
( powerVal[PWR_REG_4] & WM8753_PWR4_MIX ) )
{
currentPower |= WM_POWER_MIXERS;
}
if ( powerVal[PWR_REG_1] & WM8753_PWR1_VREF )
{
currentPower |= WM_POWER_VREF;
}
if ( powerVal[PWR_REG_3] & WM8753_PWR3_OUTPUT )
{
currentPower |= WM_POWER_OUTPUTS;
}
done:
return currentPower;
}
/*-----------------------------------------------------------------------------
* Function: private_CalcPowered
*
* Works out what should currently be powered up, based on what all the drivers
* are requesting and the various dependencies.
*
* NB This function only makes sense if we have global data pointer.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* driverId The device ID (e.g. WM_DRIVER_TOUCH)
* powerUp The sections to power up.
* powerDown The sections to power down.
* pCurrentPower A pointer to receive the current power state.
*
* Returns: WM_POWERFLAG
* The bitmask describing the sections which should be powered up.
*---------------------------------------------------------------------------*/
static WM_POWERFLAG private_CalcPowered( WM_DEVICE_HANDLE hDevice,
WM_DRIVER_ID driverId,
WM_POWERFLAG powerUp,
WM_POWERFLAG powerDown,
WM_POWERFLAG *pCurrentPower
)
{
WM_DEVICE_CONTEXT *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
WM_POWERFLAG newPowered = 0;
#if WM_CACHE_POWER_STATE
unsigned int driver = DRIVER_TO_INDEX( driverId );
WM_ASSERT( hDevice, driver < WM_MAX_DRIVERS );
#endif /* WM_CACHE_POWER_STATE */
/*
* Work out what's currently on.
*/
*pCurrentPower = WM8753GetCurrentPower( hDevice );
/*
* If we're entering sleep, we want everything powered off.
*/
if ( pDeviceContext->v_pWMData->powerStateFlags & WM_ENTERING_SLEEP )
{
newPowered = 0;
goto done;
}
/*
* Check whether we've got our globals.
*/
#if WM_CACHE_POWER_STATE
if ( pDeviceContext->v_pWMData )
{
int drv;
/*
* Update our driver settings.
*/
pDeviceContext->v_pWMData->powerRequirements[driver] |= powerUp;
pDeviceContext->v_pWMData->powerRequirements[driver] &= ~powerDown;
/*
* Check what all the drivers are asking for.
*/
for ( drv = 0; drv < WM_MAX_DRIVERS; drv++ )
{
newPowered |= pDeviceContext->v_pWMData->powerRequirements[drv];
}
}
else
#endif /* WM_CACHE_POWER_STATE */
{
newPowered = ( *pCurrentPower | powerUp ) & ~powerDown;
}
/*
* Now work out dependencies.
*/
/* Anything audio needs audio stuff powered up */
if ( newPowered & ( WM_POWER_AUDIO_DACS
| WM_POWER_OUTPUTS
| WM_POWER_INPUTS )
)
{
newPowered |= WM_POWER_MIXERS | WM_POWER_VREF;
}
/* The ADC just needs the references */
if ( newPowered & WM_POWER_AUDIO_ADCS )
{
newPowered |= WM_POWER_VREF;
}
/* DAC and ADC need the clock */
if ( newPowered & ( WM_POWER_AUDIO_DACS | WM_POWER_AUDIO_ADCS ) )
{
newPowered |= WM_POWER_CLOCK;
}
done:
return newPowered;
}
#endif /* WM8753_FAMILY */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -