⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pmicpdk.c

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 C
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
//
//  Copyright (C) 2004-2005, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
//  Copyright (C) 2006-2007, 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:  pmicpdk.cpp
//
//  This file contains the PMIC platform-specific functions that provide control
//  over the Power Management IC.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <nkintr.h>
#include <ceddk.h>
#include "bsp.h"
#include "pmic_lla.h"
#include "regs.h"
#include "regs_regulator.h"


//-----------------------------------------------------------------------------
// External Functions
extern BOOL PMICIoctlIntEnable(UINT32 IntID, BOOL EnableFlag);
extern VOID GetRegister(UINT32 addr, UINT32* content);

//-----------------------------------------------------------------------------
// External Variables


//-----------------------------------------------------------------------------
// Defines

//-----------------------------------------------------------------------------
// Types


//-----------------------------------------------------------------------------
// Global Variables
// Set g_bPmicUseCspiPolling TRUE to prevent interrupt-driven PMIC CSPI
// transfers, or set FALSE to allow interrupt-driven communication.
BOOL g_bPmicUseCspiPolling = FALSE;

//-----------------------------------------------------------------------------
// Local Variables
static volatile BOOL g_bSuspended = FALSE;
static HANDLE g_hPmicButtonEvent[3];
static HANDLE g_hPmicButtonServThread;
static PCSP_CSPI_REGS g_pCSPI;
static DDK_CLOCK_GATE_INDEX g_CGI;



//-----------------------------------------------------------------------------
// Local Functions
static DWORD WINAPI PmicButtonServThread (LPVOID lpParam);


//-----------------------------------------------------------------------------
//
// Function: BSPPmicGetSpiPort
//
// Provides the platform-specific SPI port used for PMIC module communication.
//
// Parameters:
//      None.
//
// Returns:
//      SPI port.
//
//-----------------------------------------------------------------------------
int BSPPmicGetSpiPort()
{
    return BSP_PMIC_CSPI_PORT;
}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicGetSpiFreqOut
//
// Provides the platform-specific SPI clock frequency used to determine the 
// data transmission clock rate.
//
// Parameters:
//      None.
//
// Returns:
//      SPI output frequency in Hz.
//
//-----------------------------------------------------------------------------
UINT32 BSPPmicGetSpiFreqOut()
{
    return BSP_PMIC_CSPI_FREQ;
}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicGetSpiFreqIn
//
// Provides the platform-specific SPI clock frequency used to determine the 
// input clock to the SPI.
//
// Parameters:
//      None.
//
// Returns:
//      SPI input frequency in Hz.
//
//-----------------------------------------------------------------------------
UINT32 BSPPmicGetSpiFreqIn()
{
    UINT32 freq;
    
    DDKClockGetFreq(DDK_CLOCK_SIGNAL_PERDIV2, &freq);

    return freq;
}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicGetIrq
//
// Provides the platform-specific IRQ line used for PMIC module 
// communication.
//
// Parameters:
//      None.
//
// Returns:
//      IRQ line.
//
//-----------------------------------------------------------------------------
DWORD BSPPmicGetIrq()
{
    return BSP_PMIC_IRQ;
}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicSetSpiClockGating
//
// Provides the platform-specific SPI clock gating control to enable/disable 
// module clocks.
//
// Parameters:
//      bEnable
//          [in] Set to TRUE to enable CSPI clocks, set to FALSE to disable
//          CSPI clocks.
//
// Returns:
//      TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicSetSpiClockGating(BOOL bEnable)
{
    DDK_CLOCK_GATE_MODE mode = bEnable ? 
        DDK_CLOCK_GATE_MODE_ENABLE : DDK_CLOCK_GATE_MODE_DISABLE;
#if (BSP_PMIC_CSPI_PORT == 1)
    return DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_CSPI1, mode);
#elif (BSP_PMIC_CSPI_PORT == 2)
    return DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_CSPI2, mode);
#else
    #error "Invalid PMIC CSPI port"
#endif

}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicInit
//
// Initializes the platform-specific configuration for the PMIC module.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicInit(HANDLE *phIntrHdlr)
{
    BOOL rc = FALSE;
    	
	DDK_GPIO_CFG ioctl;

    // Configure PMIC bindings to IOMUX/GPIO
    
	DDK_GPIO_SET_CONFIG (ioctl, INTR_PMIC);
    DDKGpioEnable (&ioctl); 
	
	// Create events for processing ON button presses
    g_hPmicButtonEvent[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
    
    // Check if CreateEvent failed
    if (g_hPmicButtonEvent[0] == NULL)
    {
        ERRORMSG(TRUE, (TEXT("%s(): CreateEvent failed!\r\n"),
            __WFUNCTION__));
        goto cleanUp;
    }

    g_hPmicButtonEvent[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
    
    // Check if CreateEvent failed
    if (g_hPmicButtonEvent[1] == NULL)
    {
        ERRORMSG(TRUE, (TEXT("%s(): CreateEvent failed!\r\n"),
            __WFUNCTION__));
        goto cleanUp;
    }

    g_hPmicButtonEvent[2] = CreateEvent(NULL, FALSE, FALSE, NULL);
    
    // Check if CreateEvent failed
    if (g_hPmicButtonEvent[2] == NULL)
    {
        ERRORMSG(TRUE, (TEXT("%s(): CreateEvent failed!\r\n"),
            __WFUNCTION__));
        goto cleanUp;
    }

    // Create IST for PMIC ON buttons
    g_hPmicButtonServThread = CreateThread(NULL, 0, PmicButtonServThread, NULL, 0, NULL);      
    if (!g_hPmicButtonServThread) 
    {
        ERRORMSG(TRUE, 
            (TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        goto cleanUp;
    }

    // Update PMIC table of events for each ON button
    phIntrHdlr[PMIC_MC13783_INT_ONOFD1I] = g_hPmicButtonEvent[0];
    phIntrHdlr[PMIC_MC13783_INT_ONOFD2I] = g_hPmicButtonEvent[1];
    phIntrHdlr[PMIC_MC13783_INT_ONOFD3I] = g_hPmicButtonEvent[2];
    
    PMICIoctlIntEnable(PMIC_MC13783_INT_ONOFD1I, TRUE);
    PMICIoctlIntEnable(PMIC_MC13783_INT_ONOFD2I, TRUE);
    PMICIoctlIntEnable(PMIC_MC13783_INT_ONOFD3I, TRUE);
    
    rc = TRUE;

cleanUp:

    return rc;

}

//-----------------------------------------------------------------------------
//
// Function: BSPPmicDeinit
//
// Deinitializes the platform-specific configuration for the PMIC module.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicDeinit()
{
   
 	DDK_GPIO_CFG ioctl;
 
	DDK_GPIO_SET_CONFIG(ioctl, INTR_PMIC);
    DDKGpioDisable (&ioctl); 

    return TRUE;

}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicClearIrq
//
// Clears the PMIC interrupt request.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicClearIrq()
{
    return DDKGpioClearIntrPin(BSP_PMIC_GPIO_PORT, BSP_PMIC_GPIO_PIN);
}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicGetIrqStatus
//
// Retrieves the PMIC interrupt request status.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicGetIrqStatus(UINT32 *status)
{
    return DDKGpioReadIntrPin(BSP_PMIC_GPIO_PORT, BSP_PMIC_GPIO_PIN, status);

}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicInitCspi
//
// Initializes the platform-specific configuration for the CSPI port.
//
// Parameters:
//      port
//          [in] - CSPI port to configure.
//
// Returns:
//      TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicInitCspi(int port)
{
    BOOL rc = FALSE;
// Commented since already done in OAL - 6th April
#if 0
    PHYSICAL_ADDRESS phyAddr;

    phyAddr.QuadPart = CSP_BASE_REG_PA_CSPI1;
    
	// CSPI1 mapping
	g_pCSPI = (PCSP_CSPI_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_CSPI_REGS), FALSE);
	if (g_pCSPI == NULL)
	{
		DEBUGMSG(TRUE,
			(TEXT("BSPPmicInitCspi:MmMapIoSpace returned NULL\r\n"),
			__WFUNCTION__));
		goto cleanUp;
	}

	// Turn on CSPI clocks
	g_CGI = DDK_CLOCK_GATE_INDEX_CSPI1;
	DDKClockSetGatingMode(g_CGI, DDK_CLOCK_GATE_MODE_ENABLE);

	// Configure the CSPI interface and enable it before writing to  
	// other CSPI registers
	OUTREG32(&g_pCSPI->CONTROLREG,
		CSP_BITFVAL(CSPI_CONTROLREG_SPIEN, CSPI_CONTROLREG_SPIEN_ENABLE) |
		CSP_BITFVAL(CSPI_CONTROLREG_MODE, CSPI_CONTROLREG_MODE_MASTER) |
		CSP_BITFVAL(CSPI_CONTROLREG_XCH, CSPI_CONTROLREG_XCH_IDLE) |
		CSP_BITFVAL(CSPI_CONTROLREG_POL, CSPI_CONTROLREG_POL_ACTIVE_HIGH) |
		CSP_BITFVAL(CSPI_CONTROLREG_PHA, CSPI_CONTROLREG_PHA0) |
		CSP_BITFVAL(CSPI_CONTROLREG_SSCTL, CSPI_CONTROLREG_SSCTL_ASSERT) |
		CSP_BITFVAL(CSPI_CONTROLREG_SSPOL, CSPI_CONTROLREG_SSPOL_ACTIVE_HIGH) |
		CSP_BITFVAL(CSPI_CONTROLREG_BITCOUNT, CSPI_CONTROLREG_BITCOUNT_32BIT) |
		CSP_BITFVAL(CSPI_CONTROLREG_DATARATE, OALPmicCalcDiv(BSP_PMIC_CSPI_FREQ)) |
		CSP_BITFVAL(CSPI_CONTROLREG_DRCTL, CSPI_CONTROLREG_DRCTL_DONTCARE) |
		CSP_BITFVAL(CSPI_CONTROLREG_CS, CSPI_CONTROLREG_CS_SS0));

		OUTREG32(&g_pCSPI->INT, 0);
		OUTREG32(&g_pCSPI->DMA, 0);
		OUTREG32(&g_pCSPI->TEST, 0);

		// Turn the CSPI module and clocks off to save power between transfers
		INSREG32BF(&g_pCSPI->CONTROLREG, CSPI_CONTROLREG_SPIEN, CSPI_CONTROLREG_SPIEN_DISABLE);
		DDKClockSetGatingMode(g_CGI, DDK_CLOCK_GATE_MODE_DISABLE);

#endif
     rc = TRUE;
 
    return rc;

}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicDeinitCspi
//
// Deinitializes the platform-specific configuration for the CSPI port.
//
// Parameters:
//      port
//          [in] - CSPI port to configure.
//
// Returns:
//      TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL BSPPmicDeinitCspi(int port)
{
    return TRUE;
}


//-----------------------------------------------------------------------------
//
// Function: BSPPmicPowerNotifySuspend
//
// Handler for notification of system suspend.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
VOID BSPPmicPowerNotifySuspend(void)
{
    // System is entering suspend
    g_bSuspended = TRUE;
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -