📄 wm97audio.c
字号:
/*-----------------------------------------------------------------------------
* Copyright (c) Wolfson Microelectronics plc. All rights reserved.
*
* This software as well as any related documentation is furnished under
* license and may only be used or copied in accordance with the terms of the
* license. The information in this file is furnished for informational use
* only, is subject to change without notice, and should not be construed as
* a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
* assumes no responsibility or liability for any errors or inaccuracies that
* may appear in this document or any software that may be provided in
* association with this document.
*
* Except as permitted by such license, no part of this document may be
* reproduced, stored in a retrieval system, or transmitted in any form or by
* any means without the express written consent of Wolfson Microelectronics plc.
*
* $Id: WM97Audio.c 2326 2005-10-20 08:40:38Z ib $
*
* This file contains platform-independent routines for controlling the audio
* operation on Wolfson AC97 codecs.
*
* Warning:
* This driver is specifically written for Wolfson Codecs. It is not a
* general CODEC device driver.
*
* -----------------------------------------------------------------------------*/
/*
* Include files
*/
#include "WMCommon.h"
#include "WMDevice.h"
#include "WMControlLink.h"
#include "WMPower.h"
#include "WM9713Audio.h"
#include "WM97Audio.h"
/*
* Only build this if we're doing Audio support.
*/
#if WM_AUDIO && WM_AC97
/*
* Global definitions
*/
/*
* Private data
*/
/*
* Function prototypes
*/
/*-----------------------------------------------------------------------------
* Function: WM97SetSampleRate
*
* Called to Set the sample Rate in the audio-specific sections of the chip.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* stream The stream for which to set the sample rate
* sampleRate The requested sample rate.
*
* Returns: WMSTATUS
* See WMStatus.h.
*---------------------------------------------------------------------------*/
WMSTATUS WM97SetSampleRate( WM_DEVICE_HANDLE hDevice,
WM_STREAM_ID stream,
WM_SAMPLE_RATE sampleRate
)
{
WMSTATUS status;
WM_REGTYPE reg = 0;
WM_POWERFLAG powerState = 0;
#if WM_VOICE
if ( WM_IS_VOICE_SUPPORTED( hDevice ) &&
( ( stream == WM_STREAM_VOICE_IN ) || ( stream == WM_STREAM_VOICE_OUT ) )
)
{
/*
* Set the Voice sample rate.
*/
status = WM9713VoiceSetRate( hDevice, sampleRate );
}
else
#endif /* WM_VOICE */
{
/* Check which sample rate we need to set */
switch (stream)
{
case WM_STREAM_HIFI_IN:
reg = WM97_ADC_RATE;
break;
case WM_STREAM_HIFI_OUT:
reg = WM97_DAC_RATE;
break;
case WM_STREAM_MONO_OUT:
if ( WM_HAS_MONO_DAC( hDevice ) )
{
reg = WM97_AUXDAC_RATE;
}
else
{
status = WMS_UNSUPPORTED;
goto finish;
}
break;
default :
status = WMS_UNSUPPORTED;
goto finish;
}
/* Check sample rate */
switch ( sampleRate )
{
case WM_SAMPLE_RATE_8K:
case WM_SAMPLE_RATE_11K025:
case WM_SAMPLE_RATE_16K:
case WM_SAMPLE_RATE_22K05:
case WM_SAMPLE_RATE_32K:
case WM_SAMPLE_RATE_44K1:
case WM_SAMPLE_RATE_48K:
{
break;
}
case WM_SAMPLE_RATE_12K:
case WM_SAMPLE_RATE_24K:
{
if ( !WM_HAS_EXTENDED_SAMPLE_RATES( hDevice ) )
{
status = WMS_INVALID_PARAMETER;
goto finish;
}
break;
}
default:
{
status = WMS_INVALID_PARAMETER;
goto finish;
}
}
/* Set the VRA bit */
status = WMSetField( hDevice,
WM97_AUDIO_CONTROL,
WM97_VRA_ENABLED,
WM97_VRA_ENABLED
);
if ( WM_ERROR( status ) )
{
goto finish;
}
if ( stream == WM_STREAM_HIFI_IN )
{
/*
* On the WM97XX we need to power up the ADC
* at this point because if we try to write the sample rate
* with the ADC powered down the value in the register will
* change but it will not be latched in to the device.
*/
/*
* Check the current power state of the ADC so that we can restore it
* once we have finished.
*/
powerState = WMGetCurrentPowerState( hDevice );
if( ! ( WM_POWER_AUDIO_HIFI_ADC & powerState ) )
{
status = WMPowerUp( hDevice, WM_DRIVER_INTERNAL, WM_POWER_AUDIO_HIFI_ADC );
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice, (
"WM97SetSampleRate : WMAudioPowerUp failed: %s",
WMStatusText( status )
));
goto finish;
}
}
}
/*
* Write the sample rate.
*/
status = WMWrite( hDevice, reg, sampleRate );
if ( stream == WM_STREAM_HIFI_IN )
{
/*
* Now that the ADC sample rate has been changed we can power the
* ADC back down if it was powered down when we entered this function.
*/
if( ! ( WM_POWER_AUDIO_HIFI_ADC & powerState ) )
{
/*
* Power down the ADC.
*/
status = WMPowerDown( hDevice, WM_DRIVER_INTERNAL, WM_POWER_AUDIO_HIFI_ADC );
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice, (
"WM97SetSampleRate : WMAudioPowerUp failed: %s",
WMStatusText( status )
));
goto finish;
}
}
}
}
finish:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WM97GetSampleRate
*
* Returns the sample rate in the audio-specific sections of the chip.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* stream The stream for which to get the sample rate
* pSampleRate Variable to receive the sample rate
*
* Returns: WMSTATUS
* See WMStatus.h.
*---------------------------------------------------------------------------*/
WMSTATUS WM97GetSampleRate( WM_DEVICE_HANDLE hDevice,
WM_STREAM_ID stream,
WM_SAMPLE_RATE *pSampleRate
)
{
WMSTATUS status;
WM_REGTYPE reg;
WM_REGVAL sampleRate;
/* Check which sample rate we need to query */
switch ( stream )
{
case WM_STREAM_HIFI_IN:
reg = WM97_ADC_RATE;
break;
case WM_STREAM_HIFI_OUT:
reg = WM97_DAC_RATE;
break;
case WM_STREAM_MONO_OUT:
if ( WM_HAS_MONO_DAC( hDevice ) )
{
reg = WM97_AUXDAC_RATE;
}
else
{
status = WMS_UNSUPPORTED;
goto finish;
}
break;
default :
status = WMS_UNSUPPORTED;
goto finish;
}
/*
* Read the sample rate.
*/
status = WMRead( hDevice, reg, &sampleRate );
if ( WM_SUCCESS( status ) )
{
*pSampleRate = (WM_SAMPLE_RATE) sampleRate;
}
/*
* And we're done.
*/
finish:
return status;
}
#endif /* WM_AUDIO && WM_AC97 */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -