📄 pmic_pwrctrl.cpp
字号:
//------------------------------------------------------------------------------
//
// Copyright (C) 2005, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
/*---------------------------------------------------------------------------
* Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved.
* THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
* AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
*--------------------------------------------------------------------------*/
//
// File: pmic_pwrctrl.cpp
//
// This file contains the PMIC power control and power cut SDK interface that is used by applications
// and other drivers to access registers of the PMIC.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include "socarm_macros.h"
#include "pmic_ioctl.h"
#include "regs.h"
#include "regs_pwrctrl.h"
#include "pmic_pwrctrl.h"
//-----------------------------------------------------------------------------
// External Functions
//-----------------------------------------------------------------------------
// External Variables
//-----------------------------------------------------------------------------
// Defines
//-----------------------------------------------------------------------------
// Types
//-----------------------------------------------------------------------------
// Global Variables
extern HANDLE hPMI;
#ifdef DEBUG
// Debug zone bit positions
#define ZONEID_ERROR 0
#define ZONEID_WARN 1
#define ZONEID_INIT 2
#define ZONEID_FUNC 3
#define ZONEID_INFO 4
// Debug zone masks
#define ZONEMASK_ERROR (1 << ZONEID_ERROR)
#define ZONEMASK_WARN (1 << ZONEID_WARN)
#define ZONEMASK_INIT (1 << ZONEID_INIT)
#define ZONEMASK_FUNC (1 << ZONEID_FUNC)
#define ZONEMASK_INFO (1 << ZONEID_INFO)
// Debug zone args to DEBUGMSG
#define ZONE_ERROR DEBUGZONE(ZONEID_ERROR)
#define ZONE_WARN DEBUGZONE(ZONEID_WARN)
#define ZONE_INIT DEBUGZONE(ZONEID_INIT)
#define ZONE_FUNC DEBUGZONE(ZONEID_FUNC)
#define ZONE_INFO DEBUGZONE(ZONEID_INFO)
extern DBGPARAM dpCurSettings;
#endif // DEBUG
//-----------------------------------------------------------------------------
// Local Variables
//-----------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlSetPowerCutTimer
//
// This function is used to set the power cut timer duration.
//
// Parameters:
// duration [in] The value to set to power cut timer register, it's from 0 to 255.
// The timer will be set to a duration of 0 to 31.875 seconds,
// in 125 ms increments.
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlSetPowerCutTimer (UINT8 duration)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_PWR_CTL1_ADDR;
// check input parameter
if (duration > MC13783_PWRCTRL1_PCT_MAX){
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlSetPowerCutTimer:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
param.data = CSP_BITFVAL(MC13783_PWRCTRL1_PCT, duration);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL1_PCT);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlGetPowerCutTimer
//
// This function is used to get the power cut timer duration.
//
// Parameters:
// duration [out] the duration to set to power cut timer
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlGetPowerCutTimer (UINT8* duration)
{
UINT32 addr, temp;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
// check input parameter
if (duration == NULL){
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlGetPowerCutTimer:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
addr = MC13783_PWR_CTL1_ADDR;
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_READ_REG, &addr, sizeof(addr),
&temp, sizeof(temp), NULL, NULL))
return PMIC_ERROR;
*duration = CSP_BITFEXT(temp, MC13783_PWRCTRL1_PCT);
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlEnablePowerCut
//
// This function is used to enable the power cut.
//
// Parameters:
// none
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlEnablePowerCut (void)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_PWR_CTL0_ADDR;
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_PCEN, MC13783_PWRCTRL0_PCEN_ENABLE);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_PCEN);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlDisablePowerCut
//
// This function is used to disable the power cut.
//
// Parameters:
// none
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlDisablePowerCut (void)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_PWR_CTL0_ADDR;
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_PCEN, MC13783_PWRCTRL0_PCEN_DISABLE);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_PCEN);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlSetPowerCutCounter
//
// This function is used to set the power cut counter.
//
// Parameters:
// counter [in] The counter number value to be set to the register. It's value
// from 0 to 15.
//
// The power cut counter is a 4 bit counter that keeps track of
// the number of rising edges of the UV_TIMER (power cut
// events) that have occurred since the counter was last initialized.
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlSetPowerCutCounter (UINT8 counter)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_PWR_CTL1_ADDR;
// check input parameter
if (counter > MC13783_PWRCTRL1_PCCOUNT_MAX){
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlSetPowerCutCounter:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
param.data = CSP_BITFVAL(MC13783_PWRCTRL1_PCCOUNT, counter);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL1_PCCOUNT);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlGetPowerCutCounter
//
// This function is used to get the power cut counter.
//
// Parameters:
// counter [out] to get the counter number
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlGetPowerCutCounter (UINT8* counter)
{
UINT32 addr, temp;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
// check input parameter
if (counter == NULL){
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlGetPowerCutCounter:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
addr = MC13783_PWR_CTL1_ADDR;
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_READ_REG, &addr, sizeof(addr),
&temp, sizeof(temp), NULL, NULL))
return PMIC_ERROR;
*counter = CSP_BITFEXT(temp, MC13783_PWRCTRL1_PCT);
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlSetPowerCutMaxCounter
//
// This function is used to set the maxium number of power cut counter.
//
// Parameters:
// counter [in] maxium counter number to set. It's value from 0 to 15.
//
// The power cut register provides a method for disabling
// power cuts if this situation manifests itself.
// If PC_COUNT >= PC_MAX_COUNT, then the number of
// resets that have occurred since the power cut counter was
// last initialized exceeds the established limit, and power cuts
// will be disabled.
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlSetPowerCutMaxCounter (UINT8 counter)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_PWR_CTL1_ADDR;
// check input parameter
if (counter > MC13783_PWRCTRL_PCMAXCNT_MAX){
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlSetPowerCutMaxCounter:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
param.data = CSP_BITFVAL(MC13783_PWRCTRL1_PCMAXCNT, counter);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL1_PCMAXCNT);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlgetPowerCutMaxCounter
//
// This function is used to get the setting of maxium power cut counter.
//
// Parameters:
// counter [out] to get the maxium counter number
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlGetPowerCutMaxCounter (UINT8* counter)
{
UINT32 addr, temp;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
// check input parameter
if (counter == NULL){
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlGetPowerCutMaxCounter:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -