📄 pmicpdk.c
字号:
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004-2005, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004-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: 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"
#include "display_vf.h"
#ifdef PLAT_PMC
#include <pmcpm.h>
#endif
//-----------------------------------------------------------------------------
// 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_REG g_pCSPI;
//-----------------------------------------------------------------------------
// 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_IPG, &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_ENABLED_ALL : DDK_CLOCK_GATE_MODE_DISABLED;
#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;
// Configure PMIC bindings to IOMUX/GPIO
DDKIomuxSetPinMux(BSP_PMIC_IOMUX_PIN, DDK_IOMUX_OUT_GPIO, DDK_IOMUX_IN_GPIO);
DDKIomuxSetPadConfig(BSP_PMIC_IOMUX_PAD, DDK_IOMUX_PAD_SLEW_SLOW, DDK_IOMUX_PAD_DRIVE_NORMAL, DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_SCHMITT, DDK_IOMUX_PAD_PULL_UP_100K);
DDKGpioSetConfig(BSP_PMIC_GPIO_PORT, BSP_PMIC_GPIO_PIN, DDK_GPIO_DIR_IN, DDK_GPIO_INTR_HIGH_LEV);
DDKGpioClearIntrPin(BSP_PMIC_GPIO_PORT, BSP_PMIC_GPIO_PIN);
DDKGpioBindIrq(BSP_PMIC_GPIO_PORT, BSP_PMIC_GPIO_PIN, BSP_PMIC_IRQ);
// 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()
{
// Release PMIC bindings to IOMUX/GPIO
DDKGpioSetConfig(BSP_PMIC_GPIO_PORT, BSP_PMIC_GPIO_PIN, DDK_GPIO_DIR_IN, DDK_GPIO_INTR_NONE);
DDKGpioClearIntrPin(BSP_PMIC_GPIO_PORT, BSP_PMIC_GPIO_PIN);
DDKGpioUnbindIrq(BSP_PMIC_GPIO_PORT, BSP_PMIC_GPIO_PIN);
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;
if (port == 1)
{
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SPI_RDY, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SCLK, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SS2, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SS1, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_SS0, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_MISO, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI1_MOSI, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
rc = TRUE;
}
else if (port == 2)
{
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SPI_RDY, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SCLK, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SS2, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SS1, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_SS0, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_MISO, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_CSPI2_MOSI, DDK_IOMUX_OUT_FUNC, DDK_IOMUX_IN_FUNC);
rc = TRUE;
}
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: BSPPmicDeinitCspi
//
// Deinitializes the platform-specific configuration for the CSPI port.
//
// Parameters:
// port
// [in] - CSPI port to configure.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -