📄 pmic_linki2csoc.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_LinkI2CSoc.c
**
** Contain the basic PMIC I2C opertation which will call I2C SOC Static Lib API functions
*****************************************************************************/
#include "Runtime_context.h"
#include "PI2C_SOC.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
return PXA_STATUS_SUCCESS;
}
PXA_STATUS_T PMICLIB_UnLockBus()
{
return PXA_STATUS_SUCCESS;
}
PXA_PI2CREG_T * PMICGetPI2CRegs()
{
static PXA_PI2CREG_T *pPI2CReg = NULL;
if (NULL == pPI2CReg)
{
pPI2CReg = (PXA_PI2CREG_T *)((UINT32)PXA_CTX_GetRegAddr(PXA_PERIPHERAL_REGIDX_SPMU)+ 0xC0);
}
return pPI2CReg;
}
/******************************************************************************
* 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;
PXA_PI2CREG_T *pPI2CReg = NULL;
UINT8 aucBuf[2];
UINT32 ulBytesCount = 0;
BOOL bSendStop = TRUE;
pPI2CReg = PMICGetPI2CRegs();
if (!pPI2CReg)
{
ERRORMSG(1, (TEXT("[PMIC]: PMICLIB_Write Failed in PMICGetI2CRegs().\r\n")));
return PXA_STATUS_FUNCTION_ERROR;
}
aucBuf[0] = ucChipRegAddr;
aucBuf[1] = ucValue;
ulBytesCount = sizeof(aucBuf);
PMICLIB_LockBus();
ulStatus = PXA_PI2CWrite(pPI2CReg, PMIC_PI2C_SLAVE_ADDR,
aucBuf,
ulBytesCount,
bSendStop);
PMICLIB_UnLockBus();
if (PXA_STATUS_SUCCESS != ulStatus)
{
ERRORMSG(1, (TEXT("[PMIC]: PMICLIB_Write Failed in PXA_PI2CWrite (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;
PXA_PI2CREG_T *pPI2CReg = NULL;
BOOL bSendStop = TRUE;
pPI2CReg = PMICGetPI2CRegs();
if (!pPI2CReg)
{
ERRORMSG(1, (TEXT("[PMIC]: PMICLIB_Read Failed in PMICGetI2CRegs().\r\n")));
return PXA_STATUS_FUNCTION_ERROR;
}
PMICLIB_LockBus();
ulStatus = PXA_PI2CWrite(pPI2CReg, PMIC_PI2C_SLAVE_ADDR,
&ucChipRegAddr,
sizeof(UINT8),
bSendStop);
PMICLIB_UnLockBus();
if (PXA_STATUS_SUCCESS != ulStatus)
{
ERRORMSG(1, (TEXT("[PMIC]: PMICLIB_Read Failed in PXA_PI2CWrite (ulStatus = %d).\r\n"), ulStatus));
return ulStatus;
}
PMICLIB_LockBus();
ulStatus = PXA_PI2CRead(pPI2CReg, PMIC_PI2C_SLAVE_ADDR,
pucValue,
sizeof(UINT8),
bSendStop);
PMICLIB_UnLockBus();
if (PXA_STATUS_SUCCESS != ulStatus)
{
ERRORMSG(1, (TEXT("[PMIC]: PMICLIB_Read Failed in PXA_PI2CRead (ulStatus = %d).\r\n"), ulStatus));
return ulStatus;
}
return PXA_STATUS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -