📄 pmic_regulator.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_regulator.cpp
//
// This file contains the PMIC regulator 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_regulator.h"
#include "pmic_regulator.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: PmicSwitchModeRegulatorOn
//
// This function is used to turn on the switch mode regulator.
//
// Parameters:
// regulator [in] which switch mode regulator to turn on
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicSwitchModeRegulatorOn (PMIC_REGULATOR_SREG regulator)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
switch (regulator)
{
// SW1X, SW2X will be turn on with different mode.
// use PmicSwitchModeRegulatorSetMode() function to turn on/off.
case SW1A:
case SW2A:
case SW1B:
case SW2B:
DEBUGMSG(ZONE_ERROR, (_T("PmicSwitchModeRegulatorOn:SW1x and SW2x don't turn on/off here\r\n")));
DEBUGMSG(ZONE_ERROR, (_T("PmicSwitchModeRegulatorOn:use PmicSwitchModeRegulatorSetMode() \r\n")));
return PMIC_PARAMETER_ERROR;
case SW3:
param.addr = MC13783_SW5_ADDR;
param.data = CSP_BITFVAL(MC13783_SW5_SW3EN, MC13783_SW5_SW3EN_ENABLE);
param.mask = CSP_BITFMASK(MC13783_SW5_SW3EN);
break;
default:
return PMIC_PARAMETER_ERROR;
}
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: PmicSwitchModeRegulatorOff
//
// This function is used to turn off the switch regulator
//
// Parameters:
// regulator [in]
// which switch mode regulator to turn off
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicSwitchModeRegulatorOff (PMIC_REGULATOR_SREG regulator)
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
switch (regulator)
{
// SW1X, SW2X will be turn on with different mode.
// use PmicSwitchModeRegulatorSetMode() function to turn on/off.
case SW1A:
case SW2A:
case SW1B:
case SW2B:
DEBUGMSG(ZONE_ERROR, (_T("PmicSwitchModeRegulatorOn:SW1x and SW2x don't turn on/off here\r\n")));
DEBUGMSG(ZONE_ERROR, (_T("PmicSwitchModeRegulatorOn:use PmicSwitchModeRegulatorSetMode() \r\n")));
return PMIC_PARAMETER_ERROR;
case SW3:
param.addr = MC13783_SW5_ADDR;
param.data = CSP_BITFVAL(MC13783_SW5_SW3EN, MC13783_SW5_SW3EN_DISABLE);
param.mask = CSP_BITFMASK(MC13783_SW5_SW3EN);
break;
default:
return PMIC_PARAMETER_ERROR;
}
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: PmicSwitchModeRegulatorSetVoltageLevel
//
// This function is to set the voltage level for the regulator.
//
// Parameters:
// regulator [in] which switch mode regulator to be set
//
// voltageType [in]
// SW_VOLTAGE_NORMAL/SW_VOLTAGE_DVS/SW_VOLTAGE_STBY
//
// SWxy offers support for Dynamic Voltage-Frequency scaling. If this feature is
// activated, then assertion of the STANDBY input will automatically configure
// SWxy to output the voltage defined by the 6-bit field SWxy_STBY.
// If STANDBY=LOW, then assertion of the DVS input will automatically configure
// SWxy to output the voltage defined by the 6-bit field SWxy_DVS. These
// alternative bit fields would normally be programmed to a voltage lower than
// that encoded in the SWxy bit field. When STANDBY and DVS are both
// de-asserted, the output voltage will revert the that encoded by the SWxy field.
//
// voltage [in] voltage to be set to the regulator.
// 0-0x3F (0.900v-2.200v)
//
// Returns:
// status
// PMIC_SUCCESS for success and PMIC_ERROR for failure
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicSwitchModeRegulatorSetVoltageLevel (
PMIC_REGULATOR_SREG regulator,
PMIC_REGULATOR_SREG_VOLTAGE_TYPE voltageType,
PMIC_REGULATOR_SREG_VOLTAGE voltage )
{
PMIC_PARAM_LLA_WRITE_REG param;
DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
// check input parameter
if (voltage > MC13783_SW_MAX){
DEBUGMSG(ZONE_ERROR, (_T("PmicSwitchModeRegulatorSetVoltageLevel:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
switch (regulator)
{
case SW1A:
param.addr = MC13783_SW0_ADDR;
switch (voltageType)
{
case SW_VOLTAGE_NORMAL:
param.data = CSP_BITFVAL(MC13783_SW0_SW1A, voltage);
param.mask = CSP_BITFMASK(MC13783_SW0_SW1A);
break;
case SW_VOLTAGE_DVS:
param.data = CSP_BITFVAL(MC13783_SW0_SW1ADVS, voltage);
param.mask = CSP_BITFMASK(MC13783_SW0_SW1ADVS);
break;
case SW_VOLTAGE_STBY:
param.data = CSP_BITFVAL(MC13783_SW0_SW1ASTBY, voltage);
param.mask = CSP_BITFMASK(MC13783_SW0_SW1ASTBY);
break;
}
break;
case SW1B:
param.addr = MC13783_SW1_ADDR;
switch (voltageType)
{
case SW_VOLTAGE_NORMAL:
param.data = CSP_BITFVAL(MC13783_SW1_SW1B, voltage);
param.mask = CSP_BITFMASK(MC13783_SW1_SW1B);
break;
case SW_VOLTAGE_DVS:
param.data = CSP_BITFVAL(MC13783_SW1_SW1BDVS, voltage);
param.mask = CSP_BITFMASK(MC13783_SW1_SW1BDVS);
break;
case SW_VOLTAGE_STBY:
param.data = CSP_BITFVAL(MC13783_SW1_SW1BSTBY, voltage);
param.mask = CSP_BITFMASK(MC13783_SW1_SW1BSTBY);
break;
}
break;
case SW2A:
param.addr = MC13783_SW3_ADDR;
switch (voltageType)
{
case SW_VOLTAGE_NORMAL:
param.data = CSP_BITFVAL(MC13783_SW2_SW2A, voltage);
param.mask = CSP_BITFMASK(MC13783_SW2_SW2A);
break;
case SW_VOLTAGE_DVS:
param.data = CSP_BITFVAL(MC13783_SW2_SW2ADVS, voltage);
param.mask = CSP_BITFMASK(MC13783_SW2_SW2ADVS);
break;
case SW_VOLTAGE_STBY:
param.data = CSP_BITFVAL(MC13783_SW2_SW2ASTBY, voltage);
param.mask = CSP_BITFMASK(MC13783_SW2_SW2ASTBY);
break;
}
break;
case SW2B:
param.addr = MC13783_SW4_ADDR;
switch (voltageType)
{
case SW_VOLTAGE_NORMAL:
param.data = CSP_BITFVAL(MC13783_SW3_SW2B, voltage);
param.mask = CSP_BITFMASK(MC13783_SW3_SW2B);
break;
case SW_VOLTAGE_DVS:
param.data = CSP_BITFVAL(MC13783_SW3_SW2BDVS, voltage);
param.mask = CSP_BITFMASK(MC13783_SW3_SW2BDVS);
break;
case SW_VOLTAGE_STBY:
param.data = CSP_BITFVAL(MC13783_SW3_SW2BSTBY, voltage);
param.mask = CSP_BITFMASK(MC13783_SW3_SW2BSTBY);
break;
}
break;
case SW3:
// check input parameter
if (voltage > MC13783_SW3_MAX){
DEBUGMSG(ZONE_ERROR, (_T("PmicSwitchModeRegulatorSetVoltageLevel:Invalid Parameter\r\n")));
return PMIC_PARAMETER_ERROR;
}
param.addr = MC13783_SW5_ADDR;
param.data = CSP_BITFVAL(MC13783_SW5_SW3, voltage);
param.mask = CSP_BITFMASK(MC13783_SW5_SW3);
break;
default:
return PMIC_PARAMETER_ERROR;
}
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: PmicSwitchModeRegulatorGetVoltageLevel
//
// This function is to get the voltage settings.
// Parameters:
// regulator [in] which regulator to get the voltage value
//
// voltageType [in]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -