📄 wm8731power.c
字号:
*
* - newPowered holds what should still be powered up at the
* end of the function.
* - powerDown holds what needs to be powered down.
* - pDeviceContext->v_pWMData->WmPower holds what is currently powered up.
*/
newPowered = private_CalcPowered( hDevice, driverId, 0, powerSections, ¤tPower );
/* Power down the bits currently powered up which shouldn't be */
powerDown = currentPower & ~newPowered;
/*
* If there's nothing to do, get out now.
*/
if ( 0 == powerDown )
{
goto done;
}
/*
* Disable audio. All or nothing for now.
* Recommended power-down sequence is
*/
if ( powerDown & WM_POWER_AUDIO )
{
/*
* Power down the outputs first to minimise pops - see WAN0111.
*/
if ( powerDown & WM_POWER_OUTPUTS )
{
status = WMSetBits( hDevice, WM8731_POWERDOWN_CONTROL, WM8731_POWERDOWN_OUTPUTS );
if ( WM_ERROR( status ) )
{
goto error;
}
}
/*
* Now work out what else to power down.
*/
if ( powerDown & WM_POWER_AUDIO_DAC )
{
powerVal |= WM8731_POWERDOWN_DAC;
}
if ( powerDown & WM_POWER_AUDIO_ADC )
{
powerVal |= WM8731_POWERDOWN_ADC;
}
if ( powerDown & WM_POWER_INPUTS )
{
powerVal |= WM8731_POWERDOWN_INPUTS;
}
if ( powerDown & WM_POWER_CLOCK )
{
powerVal |= WM8731_POWERDOWN_OSCILLATOR |
WM8731_POWERDOWN_CLKOUT;
WMPlatformDisableAmplifiers( hDevice );
}
if ( powerDown & WM_POWER_VREF )
{
powerVal |= WM8731_POWERDOWN_POWEROFF;
WMPlatformDisableAmplifiers( hDevice );
}
status = WMSetBits( hDevice, WM8731_POWERDOWN_CONTROL, powerVal );
if ( WM_ERROR( status ) )
{
goto error;
}
}
/*
* Remember what we've got powered up.
*/
#if WM_CACHE_POWER_STATE
if ( pDeviceContext->v_pWMData )
{
pDeviceContext->v_pWMData->WmPower = newPowered;
}
#endif /* WM_CACHE_POWER_STATE */
/*
* We're done.
*/
done:
return WMS_SUCCESS;
/*
* Error cleanup.
*/
error:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WM8731GetCurrentPower
*
* 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 WM8731GetCurrentPower( WM_DEVICE_HANDLE hDevice )
{
WM_POWERFLAG currentPower = 0;
WM_REGTYPE powerVal;
WMSTATUS status;
/*
* Get the current power status of the device.
*/
status = WMRead( hDevice, WM8731_POWERDOWN_CONTROL, &powerVal );
if ( WM_ERROR( status ) )
{
goto done;
}
/*
* Convert from register values to power flags.
* Note the register values are "powered off".
*/
currentPower |= WM_POWER_LINK;
if ( !(powerVal & WM8731_POWERDOWN_POWEROFF) )
{
currentPower |= WM_POWER_VREF;
}
if ( !(powerVal & WM8731_POWERDOWN_CLKOUT) )
{
currentPower |= WM_POWER_CLOCK;
}
if ( !(powerVal & WM8731_POWERDOWN_INPUTS) )
{
currentPower |= WM_POWER_INPUTS;
}
if ( !(powerVal & WM8731_POWERDOWN_ADC) )
{
currentPower |= WM_POWER_AUDIO_ADC;
}
if ( !(powerVal & WM8731_POWERDOWN_DAC) )
{
currentPower |= WM_POWER_AUDIO_DAC;
}
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 = WM8731GetCurrentPower( 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_DAC
| WM_POWER_AUDIO_ADC
| WM_POWER_OUTPUTS
| WM_POWER_INPUTS )
)
{
newPowered |= WM_POWER_CLOCK | WM_POWER_VREF;
}
done:
return newPowered;
}
#endif /* WM8731_FAMILY */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -