📄 pmic_linki2cdrv.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
// (C) Copyright 2006 Marvell International Ltd.
// All Rights Reserved
//
/** FILENAME: PMIC_LinkPI2CDrv.c
**
** Contain the basic PMIC PI2C opertation which will call PI2C Drv DLL API functions
******************************************************************************/
#include "PI2C_DRV.h"
#include "PMIC_PLATFORM.h"
volatile UINT32 * g_pPMER = NULL;
volatile UINT32 * g_pPVCR = NULL;
PXA_STATUS_T PMICLIB_LockBus()
{
//Performing the sequence described in Vol 1, chapter 6.8.5
if (!g_pPMER)
{
PHYSICAL_ADDRESS PA;
PA.QuadPart = 0x40f50088; //PMER
g_pPMER = (volatile UINT32 *)MmMapIoSpace(PA, sizeof(UINT32), FALSE);
PA.QuadPart = 0x40f50100; //PVCR
g_pPVCR = (volatile UINT32 *)MmMapIoSpace(PA, sizeof(UINT32), FALSE);
}
while (*g_pPMER);
*g_pPMER = 0xf;
while (*g_pPMER != 0xf);
PXA_OST_DelayMilliSeconds(1);
while (*g_pPVCR & (1<<14)); //Reading PVCR[VSCA]
return PXA_STATUS_SUCCESS;
}
PXA_STATUS_T PMICLIB_UnLockBus()
{
if (!g_pPMER)
{
PHYSICAL_ADDRESS PA;
PA.QuadPart = 0x40f50088;
g_pPMER = (volatile UINT32 *)MmMapIoSpace(PA, sizeof(UINT32), FALSE);
PA.QuadPart = 0x40f50100;
g_pPVCR = (volatile UINT32 *)MmMapIoSpace(PA, sizeof(UINT32), FALSE);
}
*g_pPMER = 0x0;
return PXA_STATUS_SUCCESS;
}
/******************************************************************************
* Function: PMICLIB_Write
*
* Description:
* Input Parameters:
*
* Returns:
*
* Global effects:
*
* Assumptions:
*
* Calls:
*
* Called by:
*
******************************************************************************/
PXA_STATUS_T PMICLIB_Write(UINT8 ucChipRegAddr, UINT8 ucValue)
{
PXA_STATUS_T ulStatus = PXA_STATUS_SUCCESS;
UINT8 aucBuf[2];
UINT32 ulBytesCount = 0;
BOOL bSendStop = TRUE;
aucBuf[0] = ucChipRegAddr;
aucBuf[1] = ucValue;
ulBytesCount = sizeof(aucBuf);
PMICLIB_LockBus();
ulStatus = PWR_WriteData(PMIC_PI2C_SLAVE_ADDR, aucBuf, ulBytesCount, bSendStop, PXA_PI2C_NORMAL_LEVEL);
PMICLIB_UnLockBus();
if (PXA_STATUS_SUCCESS != ulStatus)
{
ERRORMSG(1, (TEXT("[PMIC]: PMICLIB_Write Failed in PWR_WriteData (ulStatus = %d).\r\n"), ulStatus));
return ulStatus;
}
return PXA_STATUS_SUCCESS;
}
/******************************************************************************
* Function: PMICLIB_Read
*
* Description:
* Input Parameters:
*
* Returns:
*
* Global effects:
*
* Assumptions:
*
* Calls:
*
* Called by:
*
******************************************************************************/
PXA_STATUS_T PMICLIB_Read(UINT8 ucChipRegAddr, UINT8 *pucValue)
{
PXA_STATUS_T ulStatus = PXA_STATUS_SUCCESS;
BOOL bSendStop = TRUE;
PMICLIB_LockBus();
ulStatus = PWR_WriteData(PMIC_PI2C_SLAVE_ADDR, &ucChipRegAddr, sizeof(UINT8), bSendStop, PXA_PI2C_NORMAL_LEVEL);
PMICLIB_UnLockBus();
if (PXA_STATUS_SUCCESS != ulStatus)
{
ERRORMSG(1, (TEXT("[PMIC]: PMICLIB_Read Failed in PWR_WriteData (ulStatus = %d).\r\n"), ulStatus));
return ulStatus;
}
PMICLIB_LockBus();
ulStatus = PWR_ReadData(PMIC_PI2C_SLAVE_ADDR, pucValue, sizeof(UINT8), bSendStop, PXA_PI2C_NORMAL_LEVEL);
PMICLIB_UnLockBus();
if (PXA_STATUS_SUCCESS != ulStatus)
{
ERRORMSG(1, (TEXT("[PMIC]: PMICLIB_Read Failed in PWR_ReadData (ulStatus = %d).\r\n"), ulStatus));
return ulStatus;
}
return PXA_STATUS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -