📄 pmic_pwrctrl.cpp
字号:
return PMIC_ERROR;
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlSetVBKUPRegulator
//
// This function is used to set the VBKUP regulator
//
// Parameters:
// reg [in] the backup regulator to set
// mode [in] the mode to set to backup regulator
//
// VBKUP_MODE1 - VBKUPxEN = 0, VBKUPxAUTO = 0
// Backup Regulator Off in Non Power Cut Modes and Off in Power Cut Modes
//
// VBKUP_MODE2 - VBKUPxEN = 0, VBKUPxAUTO = 1
// Backup Regulator Off in Non Power Cut Modes and On in Power Cut Modes
//
// VBKUP_MODE3 - VBKUPxEN = 1, VBKUPxAUTO = 0
// Backup Regulator On in Non Power Cut Modes and Off in Power Cut Modes
//
// VBKUP_MODE4 - VBKUPxEN = 1, VBKUPxAUTO = 1
// Backup Regulator On in Non Power Cut Modes and On in Power Cut Modes
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlSetVBKUPRegulator (MC13783_PWRCTRL_REG_VBKUP reg, MC13783_PWRCTRL_VBKUP_MODE mode)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_PWR_CTL0_ADDR;
if (reg == VBKUP1){
switch (mode){
case VBKUP_MODE1:
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP1EN, VBKUP_MODE1);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1EN)
| CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1AUTO);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
break;
case VBKUP_MODE2:
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP1EN, VBKUP_MODE2);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1EN)
| CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1AUTO);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
break;
case VBKUP_MODE3:
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP1EN, VBKUP_MODE3);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1EN)
| CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1AUTO);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
break;
case VBKUP_MODE4:
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP1EN, VBKUP_MODE4);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1EN)
| CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1AUTO);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
break;
default:
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlSetVBKUPRegulator:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
}
else if (reg == VBKUP2){
switch (mode){
case VBKUP_MODE1:
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP2EN, VBKUP_MODE1);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2EN)
| CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2AUTO);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
break;
case VBKUP_MODE2:
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP2EN, VBKUP_MODE2);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2EN)
| CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2AUTO);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
break;
case VBKUP_MODE3:
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP2EN, VBKUP_MODE3);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2EN)
| CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2AUTO);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
break;
case VBKUP_MODE4:
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP2EN, VBKUP_MODE4);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2EN)
| CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2AUTO);
if(!DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, ¶m,
sizeof(param), NULL, 0, NULL, NULL))
return PMIC_ERROR;
break;
default:
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlSetVBKUPRegulator:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
}
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
//------------------------------------------------------------------------------
//
// Function: PmicPwrctrlSetVBKUPRegulatorVoltage
//
// This function is used to set the VBKUP regulator voltage
//
// Parameters:
// reg [in] the backup regulator to set
// volt [in] the voltage to set to backup regulator
// 0 - 1.0v
// 1 - 1.2v
// 2 - 1.5v
// 3 - 1.8v
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlSetVBKUPRegulatorVoltage (MC13783_PWRCTRL_REG_VBKUP reg, UINT8 volt)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_PWR_CTL0_ADDR;
// check input parameter
if (volt > MC13783_PWRCTRL0_VBKUP_MAX){
DEBUGMSG(ZONE_ERROR, (_T("PmicPwrctrlSetVBKUPRegulatorVoltage:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
if (reg == VBKUP1){
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP1, volt);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP1);
}
else if (reg == VBKUP2){
param.data = CSP_BITFVAL(MC13783_PWRCTRL0_VBKUP2, volt);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_VBKUP2);
}
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: PmicPwrctrlEnableWarmStart
//
// This function is used to set the phone to transit from the ON state to the User Off state
// when either the USER_OFF pin is pulled high or the USER_OFF_SPI bit is set (after an 8ms
// delay in the Memwait state).
//
// Parameters:
// none
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlEnableWarmStart (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_WARMEN, MC13783_PWRCTRL0_WARMEN_ENABLE);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_WARMEN);
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: PmicPwrctrlDisableWarmStart
//
// This function is used to disable the warm start and set the phone to transit from the
// ON state to the MEMHOLD ONLY state when either the USER_OFF pin is pulled high or
// the USER_OFF_SPI bit is set (after an 8ms delay in the Memwait state).
//
// Parameters:
// none
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlDisableWarmStart (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_WARMEN, MC13783_PWRCTRL0_WARMEN_DISABLE);
param.mask = CSP_BITFMASK(MC13783_PWRCTRL0_WARMEN);
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: PmicPwrctrlEnableRegenAssig
//
// This function enables the REGEN pin of slected voltage regulator. The
// REGEN function can be used in two ways. It can be used as a regulator enable pin like with SIMEN
// where the SPI programming is static and the REGEN pin is dynamic. It can also be used in a static
// fashion where REGEN is maintained high while the regulators get enabled and disabled dynamically
// via SPI. In that case REGEN functions as a master enable..
//
// Parameters:
// t_regulator regu
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlEnableRegenAssig (t_regulator regu)
{
PMIC_PARAM_LLA_WRITE_REG param;
unsigned int Enable=1;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_REG_ASS_ADDR;
param.data = ((Enable) << (REGULATOR_REGEN_BIT[regu]));
param.mask = (((1U << (1)) - 1) << (REGULATOR_REGEN_BIT[regu]));
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: PmicPwrctrlDisableRegenAssig
//
// This function Disbale the REGEN pin of slected voltage regulator.
//
// Parameters:
// t_regulator regu
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlDisableRegenAssig (t_regulator regu)
{
PMIC_PARAM_LLA_WRITE_REG param;
unsigned int Enable=0;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param.addr = MC13783_REG_ASS_ADDR;
param.data = ((Enable) << (REGULATOR_REGEN_BIT[regu]));
param.mask = (((1U << (1)) - 1) << (REGULATOR_REGEN_BIT[regu]));
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: PmicPwrctrlGetRegenAssin
//
// This function reads the REGEN pin value for said voltage regulator.
//
// Parameters:
// t_regulator regu , value
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicPwrctrlGetRegenAssig (t_regulator regu , UINT8* value)
{
UINT32 param, temp;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
param = MC13783_REG_ASS_ADDR;
if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_READ_REG, ¶m, sizeof(param),
&temp, sizeof(temp), NULL, NULL))
return PMIC_ERROR;
*value =((temp & (((1U << (1)) - 1) << (REGULATOR_REGEN_BIT[regu]))) >> (REGULATOR_REGEN_BIT[regu]));
DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
return PMIC_SUCCESS;
}
// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -