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

📄 wmaclink.c

📁 pxa270平台 windows mobile 5.2 wm9713 触摸屏+音频驱动
💻 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: WMACLink.c 2326 2005-10-20 08:40:38Z ib $
 *
 * This file encapsulates the ACLink operations required by drivers for Wolfson 
 * WM97xx chips.  It assumes the interface in WM97PlatformACLink.h 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.
 *
 * -----------------------------------------------------------------------------*/

/*
 * IMPORTANT
 *
 * The functions in this file must obey two rules:
 *
 * 1. They do not use any memory other than stack space and parameters passed in.
 * 2. They do not make system calls, unless WMSystemCallsAllowed returns TRUE.
 *
 * All functions take a context parameter, which passes in pointers to the virtual
 * addresses of memory-mapped registers, and stores what type of device is being
 * accessed.
 * 
 * Some client functions provide shared memory via the v_pWMData member of the
 * context structure.  This cannot be relied on.
 */
 
/*
 * Include files
 */
#include "WMCommon.h"
#include "WMDevice.h"	
#include "WMGlobals.h"
#include "WMControlLink.h"
#include "WMDeviceContext.h"
#include "WMACLink.h"
#include "WMPlatformACLink.h"

#if WM_TESTING
#   include "Test/WMTestCommon.h"
#   include "Test/WMLinkTests.h"
#   include "Test/WMGPIOTests.h"
#endif

#if WM_AC97

/*
 * Global definitions
 */


/*
 * Touch panel masks.
 */
#define TOUCH_MASK_WM9705       (WM97_TOUCHSETUP_PRP_PDW_3|WM9705_TOUCHCTRL2_PDEN)
#define TOUCH_MASK_WM9712_13    (WM97_TOUCHSETUP_PRP_PDW_3|WM9712_13_TOUCHCTRL2_PDEN)

/*
 * Private data
 */

/*
 * Function prototypes
 */
#if WM9705_FAMILY
static WM_CHIPREV private_WM9705GetRevision( WM_DEVICE_HANDLE hDevice );
#endif
#if WM9712_FAMILY
static WM_CHIPREV private_WM9712GetRevision( WM_DEVICE_HANDLE hDevice );
#endif
#if WM9713_FAMILY
static WM_CHIPREV private_WM9713GetRevision( WM_DEVICE_HANDLE hDevice );
#endif

/*-----------------------------------------------------------------------------
 * Function:    WMACLinkInitDeviceId
 *
 * Initialises the chip type and revision.
 * Note: this assumes the hardware will not be changing on the fly.
 *
 * Parameters:
 *      hDevice     handle to the device (from WMOpenDevice)
 *
 * Returns:     WMSTATUS
 *      See WMStatus.h
 *---------------------------------------------------------------------------*/
WMSTATUS WMACLinkInitDeviceId( WM_DEVICE_HANDLE hDevice )
{
    WM_DEVICE_CONTEXT   *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
    WMSTATUS            status;
    WM_REGVAL           vendor1, vendor2;

    /*
     * Check the vendor ID.
     */
    status = WMRead( hDevice, WM97_VENDOR_ID1, &vendor1 );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }
    if ( WOLFSON_MICRO != vendor1 )
    {
        WM_TRACE( hDevice,
                  ( "WMACLinkInitDeviceId: Not a Wolfson codec (0x%04X)", vendor1 )
                );
        status = WMS_NO_SUPPORTED_DEVICE;
        goto error;
    }

    /*
     * Check the chip type.
     */
    status = WMRead( hDevice, WM97_VENDOR_ID2, &vendor2 );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    pDeviceContext->deviceType = (WM_CHIPTYPE) vendor2;

    /*
     * Is it a chip type we've built for?
     */
    switch ( pDeviceContext->deviceType )
    {
#if WM9705_FAMILY
    case WM_CHIP_WM9705:
        /*
         * Now work out the revision number.
         */
        pDeviceContext->revision = private_WM9705GetRevision( hDevice );
        WM_TRACE( hDevice, 
                 ( "WMACLinkInitDeviceId: Using WM9705/10 revision %c", pDeviceContext->revision )
                );
        break;
#endif
#if WM9707_FAMILY
    case WM_CHIP_WM9707:
        WM_TRACE( hDevice, ( "WMACLinkInitDeviceId: Using WM9703/7/8" ) );
        break;
#endif
#if WM9712_FAMILY
    case WM_CHIP_WM9712:
        pDeviceContext->revision = private_WM9712GetRevision( hDevice );
        WM_TRACE( hDevice, 
                 ( "WMACLinkInitDeviceId: Using WM9711/12 revision %c", pDeviceContext->revision )
                );
        break;
#endif
#if WM9713_FAMILY
    case WM_CHIP_WM9713:
        pDeviceContext->revision = private_WM9713GetRevision( hDevice );
        WM_TRACE( hDevice, 
                 ( "WMACLinkInitDeviceId: Using WM9713/14 revision %c", pDeviceContext->revision )
                );
        break;
#endif
    default:
        /* Unsupported chip */
        status = WMS_NO_SUPPORTED_DEVICE;
        goto error;
    }
    
    /*
     * We've checked the device type.
     */
    pDeviceContext->flags &= ~DEVICE_TYPE_NEEDS_CHECKING;

    return WMS_SUCCESS;

error:

    return status;
}

#if WM9705_FAMILY
/*-----------------------------------------------------------------------------
 * Function:    WM9705GetRevision
 *
 * Works out which revision of the WM9705 we're dealing with.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_CHIPREV
 *       WM_REV_XXX
 *---------------------------------------------------------------------------*/
static WM_CHIPREV private_WM9705GetRevision( WM_DEVICE_HANDLE hDevice )
{
    WM_REGVAL           regVal;
    WM_REGVAL           revision;
    WMSTATUS            status;

    /* read revision bits in register 5Ah */
    status = WMRead( hDevice, WM9705_MIXER_PATH_MUTE, &regVal );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    revision = regVal & WM9705_REVISION_MASK;
    switch ( revision )
    {
    case WM9705_REV_A_OR_B:         /* rev A or rev B - assume no rev As about any more */
        revision = WM_REV_B;
        break;

    case WM9705_REV_C:    /* rev C */
        revision = WM_REV_C;
        break;
        
    default:
        goto error;
    }

    return revision;

error:
    return WM_REV_UNKNOWN;
}
#endif  /* WM9705_FAMILY */

#if WM9712_FAMILY
/*-----------------------------------------------------------------------------
 * Function:    WM9712GetRevision
 *
 * Works out which revision of the WM9712 we're dealing with.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_CHIPREV
 *       WM_REV_XXX
 *---------------------------------------------------------------------------*/
static WM_CHIPREV private_WM9712GetRevision( WM_DEVICE_HANDLE hDevice )
{
    WM_REGVAL   regVal;
    WM_REGVAL   revision;
    WMSTATUS    status;

    /* Read revision bits in register 58h */
    status = WMRead( hDevice, WM97_ADD_FUN, &regVal );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    revision = regVal & WM9712_REVISION_MASK;
    switch ( revision )
    {
    case WM9712_REV_A:     /* 00 */
        revision = WM_REV_A;
        break;

    case WM9712_REV_B:   /* 01 */
        revision = WM_REV_B;
        break;

    case WM9712_REV_C_OR_D:   /* 10 */
        /* Rev C was never released */
        revision = WM_REV_D;
        break;

    case WM9712_REV_E:   /* 11 */
        revision = WM_REV_E;
        break;

    default:
        goto error;
    }

    return revision;

error:
    return WM_REV_UNKNOWN;
}
#endif  /* WM9712_FAMILY */

#if WM9713_FAMILY
/*-----------------------------------------------------------------------------
 * Function:    WM9713GetRevision
 *
 * Works out which revision of the WM9713 we're dealing with.
 *
 * Parameters:
 *      hDevice             handle to the device (from WMOpenDevice)
 *
 * Returns:     WM_CHIPREV
 *       WM_REV_XXX
 *---------------------------------------------------------------------------*/
static WM_CHIPREV private_WM9713GetRevision( WM_DEVICE_HANDLE hDevice )
{
    WM_REGVAL   regVal;
    WM_REGVAL   revision;
    WMSTATUS    status;

    /* Read revision bits in register 5Ah */
    status = WMRead( hDevice, WM9713_ADD_FUN1, &regVal );
    if ( WM_ERROR( status ) )
    {
        goto error;
    }

    revision = regVal & WM9713_REVISION_MASK;
    switch ( revision )
    {
    case WM9713_REV_A:     /* 00 */
        revision = WM_REV_A;
        break;

    case WM9713_REV_B:     /* 01 */
        revision = WM_REV_B;
        break;

    case WM9713_REV_C:     /* 10 */
        revision = WM_REV_C;
        break;

    default:
        goto error;
    }

    return revision;

error:
    return WM_REV_UNKNOWN;
}
#endif  /* WM9713_FAMILY */

#endif /* WM_AC97 */

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

⌨️ 快捷键说明

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