📄 dvfc.c
字号:
//------------------------------------------------------------------------------
//
// 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: dvfc.cpp
//
// Provides BSP-specific configuration routines for the DVFS/DPTC driver.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <ceddk.h>
#include "bsp.h"
#include "regs.h"
#include "regs_regulator.h"
#include "pmic_lla.h"
#include "pmic_regulator.h"
#include "dvfc.h"
//-----------------------------------------------------------------------------
// External Functions
//-----------------------------------------------------------------------------
// External Variables
extern PCSP_PLLCRC_REGS g_pPLLCRC;
extern UINT32 g_DvfcIntrMask;
extern HANDLE g_hDvfcIntrEvent;
#ifdef DEBUG
extern DBGPARAM dpCurSettings;
#endif
//-----------------------------------------------------------------------------
// Defines
#define DVFC_VERBOSE FALSE
#define DVFC_VOLT_LEVELS 17
#define DVFC_FREQ_LEVELS 1
#define DPTC_REF_CIRCUITS 4
//#define NEW_TABLE_VALUES // To be uncommented when New values are there
// Using DPTC reference circuits
#define DPTC_REF_CIRCUIT_MASK CSP_BITFMASK(SYSCTRL_PMCR_DRCE1) | \
CSP_BITFMASK(SYSCTRL_PMCR_DRCE3)
#define DVFC_LOCK() WaitForSingleObject(g_hDvfcMutex, INFINITE)
#define DVFC_UNLOCK() ReleaseMutex(g_hDvfcMutex)
//-----------------------------------------------------------------------------
// Types
typedef enum
{
DVFC_SPEED_HIGH = 0,
DVFC_SPEED_LOW = 1,
DVFC_NUM_SPEEDS = 2
} DVFC_SPEED;
typedef enum
{
DVFC_FREQ_266MHz = 0
} DVFC_FREQ;
typedef enum
{
DVFC_VOLT_CODE_1_675V = 0x1F,
DVFC_VOLT_CODE_1_650V = 0x1E,
DVFC_VOLT_CODE_1_625V = 0x1D,
DVFC_VOLT_CODE_1_600V = 0x1C,
DVFC_VOLT_CODE_1_575V = 0x1B,
DVFC_VOLT_CODE_1_550V = 0x1A,
DVFC_VOLT_CODE_1_525V = 0x19,
DVFC_VOLT_CODE_1_500V = 0x18,
DVFC_VOLT_CODE_1_475V = 0x17,
DVFC_VOLT_CODE_1_450V = 0x16,
DVFC_VOLT_CODE_1_425V = 0x15,
DVFC_VOLT_CODE_1_400V = 0x14,
DVFC_VOLT_CODE_1_375V = 0x13,
DVFC_VOLT_CODE_1_350V = 0x12,
DVFC_VOLT_CODE_1_325V = 0x11,
DVFC_VOLT_CODE_1_300V = 0x10,
DVFC_VOLT_CODE_1_275V = 0xF,
DVFC_VOLT_CODE_1_250V = 0xE,
DVFC_VOLT_CODE_1_225V = 0xD,
DVFC_VOLT_CODE_1_200V = 0xC,
DVFC_VOLT_CODE_1_175V = 0xB,
DVFC_VOLT_CODE_1_150V = 0xA,
DVFC_VOLT_CODE_1_125V = 0x9,
DVFC_VOLT_CODE_1_100V = 0x8,
DVFC_VOLT_CODE_1_075V = 0x7,
DVFC_VOLT_CODE_1_050V = 0x6,
DVFC_VOLT_CODE_1_025V = 0x5,
DVFC_VOLT_CODE_1_000V = 0x4,
DVFC_VOLT_CODE_0_975V = 0x3,
DVFC_VOLT_CODE_0_950V = 0x2,
DVFC_VOLT_CODE_0_925V = 0x1,
DVFC_VOLT_CODE_0_900V = 0x0
} DVFC_VOLT_CODE;
//-----------------------------------------------------------------------------
// Global Variables
typedef struct
{
DVFC_FREQ freqIndex;
UINT32 voltIndex;
UINT32 mcuPodf;
PMIC_REGULATOR_SREG sw;
PMIC_REGULATOR_SREG_VOLTAGE_TYPE swVolt;
UINT32 dvs;
BOOL dpten;
} DVFC_SETPOINT, *PDVFC_SETPOINT;
//-----------------------------------------------------------------------------
// Local Variables
static TCHAR *gEventNamePri = TEXT("EVENT_DP");
static PCSP_SYSCTRL_REGS g_pSYSCTRL;
static HANDLE g_hDvfcMutex;
static DVFC_SPEED g_CurSpeed;
static DVFC_SETPOINT g_SetPoint[1] =
{
// freqIndex, voltIndex, mcuPodf, sw, swVolt, dvs, dpten
DVFC_FREQ_266MHz, 0, 0, SW1A, SW_VOLTAGE_NORMAL, 0x0, TRUE
};
static PCSP_PBC_REGS g_pPBC;
static PMIC_REGULATOR_SREG_VOLTAGE g_MC13783SwitcherVoltTable[DVFC_VOLT_LEVELS] =
{
DVFC_VOLT_CODE_1_600V,
DVFC_VOLT_CODE_1_575V,
DVFC_VOLT_CODE_1_550V,
DVFC_VOLT_CODE_1_525V,
DVFC_VOLT_CODE_1_500V,
DVFC_VOLT_CODE_1_475V,
DVFC_VOLT_CODE_1_450V,
DVFC_VOLT_CODE_1_425V,
DVFC_VOLT_CODE_1_400V,
DVFC_VOLT_CODE_1_375V,
DVFC_VOLT_CODE_1_350V,
DVFC_VOLT_CODE_1_325V,
DVFC_VOLT_CODE_1_300V,
DVFC_VOLT_CODE_1_275V,
DVFC_VOLT_CODE_1_250V,
DVFC_VOLT_CODE_1_225V,
DVFC_VOLT_CODE_1_200V
};
static UINT32 g_DptcDcvrTable[DVFC_FREQ_LEVELS][DVFC_VOLT_LEVELS][DPTC_REF_CIRCUITS] =
{
//---------------------------- 266 MHz -----------------------------
//DCVR0 DCVR1 DCVR2 DCVR3
//------------------------------------------------------------------
0xffe00000, 0x18e2e85b, 0xffe00000, 0x25c4688a,
0xffe00000, 0x18e2e85b, 0xffe00000, 0x25c4688a,
0xffe00000, 0x1902e85b, 0xffe00000, 0x25e4688a,
0xffe00000, 0x1922e85b, 0xffe00000, 0x25e4688a,
0xffe00000, 0x1942ec5b, 0xffe00000, 0x2604688a,
0xffe00000, 0x1942ec5b, 0xffe00000, 0x26646c8a,
0xffe00000, 0x1962ec5b, 0xffe00000, 0x26c4708b,
0xffe00000, 0x1962ec5b, 0xffe00000, 0x26e4708b,
0xffe00000, 0x1982f05c, 0xffe00000, 0x2704748b,
0xffe00000, 0x19c2f05c, 0xffe00000, 0x2744748b,
0xffe00000, 0x1a02f45c, 0xffe00000, 0x2784788b,
0xffe00000, 0x1a42f45c, 0xffe00000, 0x27c47c8b,
0xffe00000, 0x1a82f85c, 0xffe00000, 0x2824808c,
0xffe00000, 0x1aa2f85c, 0xffe00000, 0x2884848c,
0xffe00000, 0x1ac2fc5c, 0xffe00000, 0x28e4888c,
0xffe00000, 0x1ae2fc5c, 0xffe00000, 0x2924888c,
0xffe00000, 0x1b23005d, 0xffe00000, 0x29648c8c
};
//-----------------------------------------------------------------------------
//
// Function: BSPGetVoltage
//
// This function gets the current volatge
//
// Parameters:
// None
//
// Returns:
// The set Voltage
//
//-----------------------------------------------------------------------------
UINT8 BSPGetVoltage()
{
UINT8 Voltage;
PmicSwitchModeRegulatorGetVoltageLevel(SW1A,SW_VOLTAGE_NORMAL,&Voltage);
// DEBUGMSG(1, (TEXT("Set Voltage Over")));
return Voltage;
}
//-----------------------------------------------------------------------------
//
// Function: BSPDvfcPowerSet
//
// This function responds to a IOCTL_POWER_SET request to prepare the
// DVFC driver for suspend/resume.
//
// Parameters:
// dx
// [in] Requested device state.
//
// Returns:
// Returns TRUE
//
//-----------------------------------------------------------------------------
BOOL BSPDvfcPowerSet(CEDEVICE_POWER_STATE dx)
{
static UINT32 dvfen, dpten;
UINT32 pmcr;
PDVFC_SETPOINT pSP = &g_SetPoint[DVFC_SPEED_HIGH];
DVFC_LOCK();
pmcr = INREG32(&g_pSYSCTRL->PMCR);
// If we are turning off
if (dx == D4)
{
// Force DPTC logic to return to highest setpoint. This will
// provide a safe setpoint for resuming the system
pSP->voltIndex = 0;
//Disable DPTC
CSP_BITFINS(pmcr, SYSCTRL_PMCR_DPTEN, SYSCTRL_PMCR_DPTEN_DPTC_DISABLE);
// Update the power management control register
OUTREG32(&g_pSYSCTRL->PMCR, pmcr);
// Request for transition to new voltage
PmicSwitchModeRegulatorSetVoltageLevel(pSP->sw, pSP->swVolt,
g_MC13783SwitcherVoltTable[pSP->voltIndex]);
// Update the DPTC threshold registers
OUTREG32(&g_pSYSCTRL->DCVR[0], g_DptcDcvrTable[pSP->freqIndex][pSP->voltIndex][0]);
OUTREG32(&g_pSYSCTRL->DCVR[1], g_DptcDcvrTable[pSP->freqIndex][pSP->voltIndex][1]);
OUTREG32(&g_pSYSCTRL->DCVR[2], g_DptcDcvrTable[pSP->freqIndex][pSP->voltIndex][2]);
OUTREG32(&g_pSYSCTRL->DCVR[3], g_DptcDcvrTable[pSP->freqIndex][pSP->voltIndex][3]);
}
// We are powering on
else
{
if (dpten == SYSCTRL_PMCR_DPTEN_DPTC_ENABLE)
{
CSP_BITFINS(pmcr, SYSCTRL_PMCR_DPTEN, SYSCTRL_PMCR_DPTEN_DPTC_ENABLE);
}
// Update the power management control register
OUTREG32(&g_pSYSCTRL->PMCR, pmcr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -