📄 wmchipdefs.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: WMChipDefs.c 2727 2006-02-09 17:38:21Z ian $
*
* This file encapsulates the operations required by drivers for Wolfson
* codec. It assumes an interface is provided for the specific platform/operating
* system.
*
* Warning:
* This driver is specifically written for Wolfson Codecs. It is not a
* general CODEC device driver.
*
* -----------------------------------------------------------------------------*/
/*
* Include files
*/
#include "WMCommon.h"
/*
* Global definitions
*/
#if WMI2S_GENERIC_FAMILY
extern void InitChipdefWMI2SGeneric7Bit( WM_CHIPDEF *pChipDef );
#define WMI2S_GENERIC_CHIPDEF_COUNT 1
#else
#define WMI2S_GENERIC_CHIPDEF_COUNT 0
#endif
#if WM8731_FAMILY
extern void InitChipdefWM8731( WM_CHIPDEF *pChipDef );
#define WM8731_CHIPDEF_COUNT 1
#else
#define WM8731_CHIPDEF_COUNT 0
#endif
#if WM8753_FAMILY
extern void InitChipdefWM8753( WM_CHIPDEF *pChipDef );
#define WM8753_CHIPDEF_COUNT 1
#else
#define WM8753_CHIPDEF_COUNT 0
#endif
#if WM9705_FAMILY
extern void InitChipdefWM9705( WM_CHIPDEF *pChipDef );
#define WM9705_CHIPDEF_COUNT 1
#else
#define WM9705_CHIPDEF_COUNT 0
#endif
#if WM9707_FAMILY
extern void InitChipdefWM9707( WM_CHIPDEF *pChipDef );
#define WM9707_CHIPDEF_COUNT 1
#else
#define WM9707_CHIPDEF_COUNT 0
#endif
#if WM9712_FAMILY
extern void InitChipdefWM9712( WM_CHIPDEF *pChipDef );
#define WM9712_CHIPDEF_COUNT 1
#else
#define WM9712_CHIPDEF_COUNT 0
#endif
#if WM9713_FAMILY
extern void InitChipdefWM9713( WM_CHIPDEF *pChipDef );
#define WM9713_CHIPDEF_COUNT 1
#else
#define WM9713_CHIPDEF_COUNT 0
#endif
#define WM_CHIPDEF_COUNT ( WMI2S_GENERIC_CHIPDEF_COUNT + \
WM8731_CHIPDEF_COUNT + \
WM8753_CHIPDEF_COUNT + \
WM9705_CHIPDEF_COUNT + \
WM9707_CHIPDEF_COUNT + \
WM9712_CHIPDEF_COUNT + \
WM9713_CHIPDEF_COUNT )
/* The table of chip definitions */
WM_CHIPDEF s_ChipDefs[WM_CHIPDEF_COUNT] = {0};
unsigned int s_nChipDefs = 0;
/*
* Function prototypes
*/
static void private_InitChipDefs( WM_DEVICE_HANDLE hDevice );
#if DEBUG
static void private_CheckChipDef( WM_DEVICE_HANDLE hDevice,
const WM_CHIPDEF *pChipDef );
#define CHECK_CHIPDEF( _hDevice, _pChipDef ) \
private_CheckChipDef( (_hDevice), (_pChipDef ) )
#else
#define CHECK_CHIPDEF( hDevice, _pChipDef )
#endif
/*-----------------------------------------------------------------------------
* Function: WMGetChipDef
*
* Returns a pointer to the chipdef for the given device, or NULL if not
* supported. Also updates the device context with the appropriate chipdef.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: WM_CHIPDEF
* A pointer to the chipdef for the given device, or NULL if not
* supported.
*---------------------------------------------------------------------------*/
const WM_CHIPDEF *WMGetChipDef( WM_DEVICE_HANDLE hDevice )
{
WM_DEVICE_CONTEXT *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
unsigned int nChipDef;
/* Make sure the chipdefs are initialised */
if ( 0 == s_nChipDefs )
private_InitChipDefs( hDevice );
/* Now run through looking for the right chipdef */
for ( nChipDef = 0; s_nChipDefs > nChipDef; nChipDef++ )
{
if ( s_ChipDefs[nChipDef].deviceType == pDeviceContext->deviceType )
{
pDeviceContext->pChipDef = &s_ChipDefs[nChipDef];
break;
}
}
return pDeviceContext->pChipDef;
}
/*-----------------------------------------------------------------------------
* Function: private_InitChipdefs
*
* Initialises the chipdef table.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
*
* Returns: void
*---------------------------------------------------------------------------*/
static void private_InitChipDefs( WM_DEVICE_HANDLE hDevice )
{
/* Fill in each chipdef */
#if WMI2S_GENERIC_FAMILY
/* Init the generic I2S and move on to the next entry in the array */
InitChipdefWMI2SGeneric7Bit( &s_ChipDefs[s_nChipDefs] );
CHECK_CHIPDEF( hDevice, &s_ChipDefs[s_nChipDefs] );
s_nChipDefs++;
#endif
#if WM8731_FAMILY
/* Init the WM8731 and move on to the next entry in the array */
InitChipdefWM8731( &s_ChipDefs[s_nChipDefs] );
CHECK_CHIPDEF( hDevice, &s_ChipDefs[s_nChipDefs] );
s_nChipDefs++;
#endif
#if WM8753_FAMILY
/* Init the WM8753 and move on to the next entry in the array */
InitChipdefWM8753( &s_ChipDefs[s_nChipDefs] );
CHECK_CHIPDEF( hDevice, &s_ChipDefs[s_nChipDefs] );
s_nChipDefs++;
#endif
#if WM9705_FAMILY
/* Init the WM9705 and move on to the next entry in the array */
InitChipdefWM9705( &s_ChipDefs[s_nChipDefs] );
CHECK_CHIPDEF( hDevice, &s_ChipDefs[s_nChipDefs] );
s_nChipDefs++;
#endif
#if WM9707_FAMILY
/* Init the WM9707 and move on to the next entry in the array */
InitChipdefWM9707( &s_ChipDefs[s_nChipDefs] );
CHECK_CHIPDEF( hDevice, &s_ChipDefs[s_nChipDefs] );
s_nChipDefs++;
#endif
#if WM9712_FAMILY
/* Init the WM9712 and move on to the next entry in the array */
InitChipdefWM9712( &s_ChipDefs[s_nChipDefs] );
CHECK_CHIPDEF( hDevice, &s_ChipDefs[s_nChipDefs] );
s_nChipDefs++;
#endif
#if WM9713_FAMILY
/* Init the WM9713 and move on to the next entry in the array */
InitChipdefWM9713( &s_ChipDefs[s_nChipDefs] );
CHECK_CHIPDEF( hDevice, &s_ChipDefs[s_nChipDefs] );
s_nChipDefs++;
#endif
/* Now check we haven't run off the end */
WM_ASSERT( hDevice, s_nChipDefs <= WM_CHIPDEF_COUNT );
}
#if DEBUG
/*-----------------------------------------------------------------------------
* Function: private_CheckChipDef
*
* Checks the chipdef table for consistency and required fields.
*
* Parameters:
* pChipDef Pointer to chipdef to check
*
* Returns: nothing
* TRUE if it worked.
*---------------------------------------------------------------------------*/
static void private_CheckChipDef( WM_DEVICE_HANDLE hDevice,
const WM_CHIPDEF *pChipDef )
{
#if WM_AUDIO
unsigned int nSignal;
#endif /* WM_AUDIO */
WM_TRACE( hDevice, ( "Checking chipdef for %s (%X)",
pChipDef->deviceName,
pChipDef->deviceType
));
/*
* Register management.
*/
WM_ASSERT( hDevice, 0 != pChipDef->regOffset );
#if WM_I2S
if ( WM_IS_I2S_DEVICE_ID( pChipDef->deviceType ) )
{
WM_ASSERT( hDevice, 0 != pChipDef->regAddrShift );
WM_ASSERT( hDevice, pChipDef->regAddrShift < sizeof( short ) * 8 );
WM_ASSERT( hDevice, 0 == (pChipDef->regDataMask & (1 << pChipDef->regAddrShift ) ) );
WM_ASSERT( hDevice, 0 != (pChipDef->regAddrMask & (1 << pChipDef->regAddrShift ) ) );
}
#endif /* WM_I2S */
#if WM_AUDIO
/*
* Check through the signal table.
*/
for ( nSignal = 0; nSignal < pChipDef->signalCount; nSignal++ )
{
const WM_SIGNAL_DETAILS *pSignalDetails = &pChipDef->pSignalDetails[nSignal];
WM_TRACE( hDevice, ( " - signal %s (0x%X)",
WMSignalName( pSignalDetails->signal ),
pSignalDetails->signal
));
WM_ASSERT( hDevice, WM_SIGNAL_IS_VALID( pSignalDetails->signal ) );
/*
* Check the flags.
*/
WM_ASSERT( hDevice, pSignalDetails->flags & (WM_CHANNEL_STEREO|WM_CHANNEL_MONO) );
WM_ASSERT( hDevice, !( (pSignalDetails->flags & WM_CHANNEL_STEREO) &&
(pSignalDetails->flags & WM_CHANNEL_MONO)
)
);
if ( pSignalDetails->flags & (WM_SIG_HAS_UPDATE|WM_SIG_HAS_BOTH) )
{
WM_ASSERT( hDevice, WM_SIG_NO_SPECIAL != pSignalDetails->special );
}
else
{
WM_ASSERT( hDevice, WM_SIG_NO_SPECIAL == pSignalDetails->special );
}
/*
* Check the volume control values.
*/
if ( WM_REG_INVALID != pSignalDetails->reg )
{
WM_REGVAL minval = pSignalDetails->minval;
WM_REGVAL maxval = pSignalDetails->maxval;
signed short step = pSignalDetails->step;
WM_REGVAL shift = pSignalDetails->shift;
WM_REGVAL mask = pSignalDetails->mask;
WM_REGVAL shiftedMask = mask >> shift;
WM_ASSERT( hDevice, minval <= maxval );
WM_ASSERT( hDevice, 0 != step );
WM_ASSERT( hDevice, shift < sizeof( WM_REGTYPE ) * 8 );
WM_ASSERT( hDevice, 0 != shiftedMask );
WM_ASSERT( hDevice, minval == (minval & shiftedMask) );
WM_ASSERT( hDevice, 0 == (minval & ~shiftedMask) );
WM_ASSERT( hDevice, maxval == (maxval & shiftedMask) );
WM_ASSERT( hDevice, 0 == (maxval & ~shiftedMask) );
}
/*
* Check the mute values.
*/
if ( WM_REG_INVALID != pSignalDetails->muteReg )
{
WM_ASSERT( hDevice, 0 != pSignalDetails->muteMask );
/* Mutes are assumed active-high at present */
WM_ASSERT( hDevice, pSignalDetails->flags & WM_SIG_VOLUME_MUTE ||
(0 != pSignalDetails->mute)
);
}
}
#endif /* WM_AUDIO */
return;
}
#endif /* DEBUG */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -