⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmxscaledevicecontext.c

📁 WM9713 audio codec driver for WinCE 5.0
💻 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: WMXScaleDeviceContext.c 2924 2006-04-12 12:50:25Z fb $
 *
 * This file contains XScale functionality for managing device contexts and
 * platform-specific memory.
 *
 * Warning:
 *  This driver is specifically written for Wolfson Codecs. It is not a 
 *  general CODEC device driver.
 *
 *  This platform file is specifically designed to work with the Cotulla AC'97
 *  controller and the Lubbock and Mainstone XScale platforms from Intel.  There
 *  is no guarantee of correct operation with other platforms/controllers.
 *
 * -----------------------------------------------------------------------------*/

/*
 * Include files
 */
#include "WMCommon.h"
#include "WMPlatform_OS.h"
#include "WMGlobals.h"
#include "WMPlatformDeviceContext.h"
#include "WMDMAContext.h"
#include "WM2WireLink.h"
#ifdef PALM_DBPXA250
#   include "HALStaticMem.h"
#endif

/*
 * Global definitions
 */

/*
 * Public data.
 */
#if WM_AC97
WM_XSCALE_DEVICE_CONTEXT     g_WM97PrimaryDeviceContext = {0};
WM_XSCALE_DEVICE_CONTEXT     g_WM97SecondaryDeviceContext = {0};
#endif 
#if WM_I2S
WM_XSCALE_DEVICE_CONTEXT     g_WMI2SPrimaryDeviceContext = {0};
WM_XSCALE_DEVICE_CONTEXT     g_WMI2SSecondaryDeviceContext = {0};
#endif

/*
 * Private data
 */

/*
 * Function prototypes
 */

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformAllocateDeviceContext
 *
 * Returns a pointer to a device context for passing to the Raw functions.
 *
 * Parameters:
 *      devID       The device ID (e.g. WM_DEV_AC97_PRIMARY)
 *      ppContext   a variable to receive the pointer to the context structure.
 *
 * Returns:     WMSTATUS
 *        See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMPlatformAllocateDeviceContext( WM_DEVICE_ID      devID,
                                          WM_DEVICE_CONTEXT **ppContext
                                        )
{
    WMSTATUS                    status;
    WM_XSCALE_DEVICE_CONTEXT    *pDeviceContext;

    /*
     * Select our codec addresses as appropriate.
     */
    switch ( devID )
    {
#if WM_AC97
    case WM_DEV_AC97_PRIMARY:
        pDeviceContext = &g_WM97PrimaryDeviceContext;
        break;
        
    case WM_DEV_AC97_SECONDARY:
        pDeviceContext = &g_WM97SecondaryDeviceContext;
        break;
#endif /* WM_AC97 */

#if WM_I2S
    case WM_DEV_I2S_PRIMARY:
        pDeviceContext = &g_WMI2SPrimaryDeviceContext;
        break;

    case WM_DEV_I2S_SECONDARY:
        pDeviceContext = &g_WMI2SSecondaryDeviceContext;
        break;
#endif /* WM_I2S */
                
    default:
        status = WMS_NO_SUPPORTED_DEVICE;
        goto error0;
    }
    
    /*
     * And return our context pointer.
     */
    *ppContext = (WM_DEVICE_CONTEXT *) pDeviceContext;
    return WMS_SUCCESS;

    /*
     * Error handling.
     */
error0:
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformFreeDeviceContext
 *
 * Frees the device context.
 *
 * Parameters:
 *      hDevice             handle to the device
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
void WMPlatformFreeDeviceContext( WM_DEVICE_HANDLE hDevice )
{
    /*
     * Global static variables - nothing to do.
     */
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformAllocatePlatformMemory
 *
 * Allocates and maps platform-specific memory (e.g. controller registers).
 *
 * This must do the following:
 * 
 *  - do any platform-specific allocation or mapping to allow access to
 *    (e.g.) controller registers, DMA, etc.
 * 
 * Note this function may get called multiple times for a given device
 * context, as different drivers load.  It should check whether each
 * allocation has already been done.
 * 
 * Parameters:
 *      hDevice     handle to the device
 *      driverID    The driver ID (e.g. WM_DRIVER_AUDIO)
 *
 * Returns:     WMSTATUS
 *        See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMPlatformAllocatePlatformMemory( WM_DEVICE_HANDLE  hDevice,
                                           WM_DRIVER_ID      driverID
                                         )
{
    WMSTATUS                    status;
    WM_XSCALE_DEVICE_CONTEXT    *pDeviceContext =
                                (WM_XSCALE_DEVICE_CONTEXT*) hDevice;
    WM_DEVICE_ID                devID = pDeviceContext->deviceID;
    int                         regSize;

    /*
     * Registers for I2S devices.
     */
    if ( WM_IS_I2S_DEVICE_ID( devID ) )
    {
        /*
         * Map the I2C registers into our address space.
         */
        if ( !pDeviceContext->v_pI2CRegs )
        {
            pDeviceContext->v_pI2CRegs = MAP_MEMORY( hDevice,
                                                     VOLATILE_I2C_T,
                                                     I2C_REGS_PHYSICAL,
                                                     sizeof( VOLATILE_I2C_T ),
                                                      TEXT("WMInitDeviceContext: I2C_REG_VIRTUAL")
                                                   );
        }
        
        /*
         * Map the I2S registers into our address space.
         */
        if ( !pDeviceContext->v_pI2SRegs )
        {
            pDeviceContext->v_pI2SRegs = MAP_MEMORY( hDevice,
                                                     VOLATILE_I2S_T,
                                                     I2S_REGS_PHYSICAL,
                                                     sizeof( VOLATILE_I2S_T ),
                                                      TEXT("WMInitDeviceContext: I2S_REG_VIRTUAL")
                                                   );
        }
    }
	else if ( WM_IS_AC97_DEVICE_ID( devID ) )
	{
        /*
         * Registers for AC'97 devices.
         */
        if ( !pDeviceContext->v_pAC97Regs )
        {
            /*
             * Map the AC97 registers into our address space.
             */
            regSize = sizeof( XLLP_AC97_T );
#if WM_BOARD_LUBBOCK
            /* AC97_REGS doesn't include the secondary and modem register spaces */
            regSize += 3*64*sizeof( unsigned long );
#endif
            pDeviceContext->v_pAC97Regs = MAP_MEMORY( hDevice,
                                                      VOLATILE_AC97_T,
                                                      AC97_REGS_PHYSICAL,
                                                      regSize,
                                                      TEXT("WMInitDeviceContext: AC97_REG_VIRTUAL")
                                                     );
        }
    }

    /*
     * Map the GPIO registers.
     */
    if ( !pDeviceContext->v_pGPIORegs )
    {
        pDeviceContext->v_pGPIORegs = MAP_MEMORY( hDevice,
                                                  VOLATILE_GPIO_T,
                                                  GPIO_REGS_PHYSICAL,
                                                  sizeof( VOLATILE_GPIO_T ),
                                                  TEXT("WMInitDeviceContext: GPIO_REG_VIRTUAL")
                                                 );
    }

    /*
     * Map the OS timer registers.
     */
    if ( !pDeviceContext->v_pOSTimerRegs )
    {
        pDeviceContext->v_pOSTimerRegs = MAP_MEMORY( hDevice,
                                                     VOLATILE_OST_T,
                                                     OST_REGS_PHYSICAL,
                                                     sizeof( VOLATILE_OST_T ),
                                                     TEXT("WMInitDeviceContext: OST_REG_VIRTUAL")
                                                   );
    }

    /*
     * Map the interrupt registers.
     */
    if ( !pDeviceContext->v_pIntRegs )
    {
        pDeviceContext->v_pIntRegs = MAP_MEMORY( hDevice,
                                                 VOLATILE_INTC_T,
                                                 INTC_REGS_PHYSICAL,
                                                 sizeof( VOLATILE_INTC_T ),
                                                 TEXT("WMInitDeviceContext: INTC_REG_VIRTUAL")
                                               );
    }

    /*
     * Map the Clock registers.
     */
    if ( !pDeviceContext->v_pClkRegs )
    {
        pDeviceContext->v_pClkRegs = MAP_MEMORY( hDevice,
                                                 VOLATILE_CLKMGR_T,
                                                 CLKMGR_REGS_PHYSICAL,
                                                 sizeof( VOLATILE_CLKMGR_T ),
                                                 TEXT("WMInitDeviceContext: CLK_REG_VIRTUAL")
                                               );
    }

    /*
     * Map the Board Level registers.
     */
    if ( !pDeviceContext->v_pBLRegs )
    {
        pDeviceContext->v_pBLRegs = MAP_MEMORY( hDevice,
                                                VOLATILE_BCR_T,
                                                FPGA_REGS_PHYSICAL,
                                                sizeof( VOLATILE_BCR_T ),
                                                TEXT("WMInitDeviceContext: FPGA_REGS_VIRTUAL")
                                              );
    }

#if WM_VOICE
    /* Only the Audio driver uses SSP, for audio transfer. */
    if ( WM_DRIVER_AUDIO == driverID )
    {
        /*
         * Map the SSP Serial Port 2 registers.
         */
        if ( !pDeviceContext->v_pSSP2Regs )
        {
            pDeviceContext->v_pSSP2Regs = MAP_MEMORY( hDevice,
                                                      VOLATILE_SSP_T,
                                                      SSP2_REGS_PHYSICAL,
                                                      sizeof( VOLATILE_SSP_T ),
                                                      TEXT("WMInitDeviceContext: SSP2_REGS_VIRTUAL")
                                                    );
        }
    }
#endif	/* WM_VOICE */

#if WM_AUDIO_STREAM
    /*
     * Map our DMA context and registers,
     */

    /* Only the Audio driver uses DMA, for audio transfer. */
    if ( WM_DRIVER_AUDIO == driverID )
    {
        if ( !pDeviceContext->v_pDmaReg )
        {
    	    /*
    	     * Map the DMA Controller registers.
    	     */
    	    pDeviceContext->v_pDmaReg = MAP_MEMORY( hDevice,
    	                                            VOLATILE_DMAC_T,
    	                                            DMA_REGS_PHYSICAL,
    	                                            sizeof( VOLATILE_DMAC_T ),
    	                                            TEXT("WMInitDeviceContext: DMA_REG_VIRTUAL")
    	                                          );

    	    /*
    	     * Initialise our DMA context.
    	     */
    	    status = WMInitDMAContext( hDevice, &pDeviceContext->pDMAContext );
    	    if ( WM_ERROR( status ) )
    	    {
    	        goto error0;
    	    }
        }
    }
#endif  /* WM_AUDIO_STREAM */

    /*
     * And we're done.
     */
    return WMS_SUCCESS;
    
    /*
     * Error handling.
     */
#if WM_AUDIO_STREAM
error0:
#endif  /* WM_AUDIO_STREAM */
    return status;
}

/*-----------------------------------------------------------------------------
 * Function:    WMPlatformFreePlatformMemory
 *
 * Frees and unmaps platform-specific memory (e.g. controller registers).
 *
 * Parameters:
 *      hDevice             handle to the device
 *
 * Returns:     void
 *---------------------------------------------------------------------------*/
void WMPlatformFreePlatformMemory( WM_DEVICE_HANDLE hDevice )
{
    /*
     * TBD: Undo any mapping done above.
     */
}

/*------------------------------ END OF FILE ---------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -