📄 bspsdhc.c
字号:
DDK_IOMUX_PAD_DRIVE_MAX, DDK_IOMUX_PAD_MODE_CMOS,
DDK_IOMUX_PAD_TRIG_SCHMITT,
DDK_IOMUX_PAD_PULL_UP_22K);
}
else
{
// Configure IOMUX to request SDHC2 bus signals
DDKIomuxSetPinMux(DDK_IOMUX_PIN_PC_CD1_B, DDK_IOMUX_OUT_ALT1, DDK_IOMUX_IN_ALT1);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_PC_CD2_B, DDK_IOMUX_OUT_ALT1, DDK_IOMUX_IN_ALT1);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_PC_WAIT_B, DDK_IOMUX_OUT_ALT1, DDK_IOMUX_IN_ALT1);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_PC_READY, DDK_IOMUX_OUT_ALT1, DDK_IOMUX_IN_ALT1);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_PC_VS1, DDK_IOMUX_OUT_ALT1, DDK_IOMUX_IN_ALT1);
DDKIomuxSetPinMux(DDK_IOMUX_PIN_PC_PWRON, DDK_IOMUX_OUT_ALT1, DDK_IOMUX_IN_ALT1);
DDKIomuxSetPadConfig(DDK_IOMUX_PIN_PC_CD1_B, DDK_IOMUX_PAD_SLEW_FAST,
DDK_IOMUX_PAD_DRIVE_MAX, DDK_IOMUX_PAD_MODE_CMOS,
DDK_IOMUX_PAD_TRIG_SCHMITT,
DDK_IOMUX_PAD_PULL_UP_22K);
DDKIomuxSetPadConfig(DDK_IOMUX_PIN_PC_CD2_B, DDK_IOMUX_PAD_SLEW_FAST,
DDK_IOMUX_PAD_DRIVE_MAX, DDK_IOMUX_PAD_MODE_CMOS,
DDK_IOMUX_PAD_TRIG_SCHMITT,
DDK_IOMUX_PAD_PULL_UP_22K);
DDKIomuxSetPadConfig(DDK_IOMUX_PIN_PC_WAIT_B, DDK_IOMUX_PAD_SLEW_FAST,
DDK_IOMUX_PAD_DRIVE_MAX, DDK_IOMUX_PAD_MODE_CMOS,
DDK_IOMUX_PAD_TRIG_SCHMITT,
DDK_IOMUX_PAD_PULL_UP_22K);
DDKIomuxSetPadConfig(DDK_IOMUX_PIN_PC_READY, DDK_IOMUX_PAD_SLEW_FAST,
DDK_IOMUX_PAD_DRIVE_MAX, DDK_IOMUX_PAD_MODE_CMOS,
DDK_IOMUX_PAD_TRIG_SCHMITT,
DDK_IOMUX_PAD_PULL_UP_22K);
DDKIomuxSetPadConfig(DDK_IOMUX_PIN_PC_VS1, DDK_IOMUX_PAD_SLEW_FAST,
DDK_IOMUX_PAD_DRIVE_MAX, DDK_IOMUX_PAD_MODE_CMOS,
DDK_IOMUX_PAD_TRIG_SCHMITT,
DDK_IOMUX_PAD_PULL_UP_22K);
DDKIomuxSetPadConfig(DDK_IOMUX_PIN_PC_PWRON, DDK_IOMUX_PAD_SLEW_FAST,
DDK_IOMUX_PAD_DRIVE_MAX, DDK_IOMUX_PAD_MODE_CMOS,
DDK_IOMUX_PAD_TRIG_SCHMITT,
DDK_IOMUX_PAD_PULL_UP_22K);
}
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcGetIrq
//
// This function is to get the interrupt line
//
// Parameters:
// None
//
// Returns:
// Interrupt line
//
//------------------------------------------------------------------------------
UINT BspSdhcGetIrq(DWORD ControllerIndex)
{
if (ControllerIndex == 1)
{
return IRQ_SDHC1;
}
else
{
return IRQ_SDHC2;
}
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcCardDetectInitialize
//
// setup GPIO pins for cadr detection
//
// Parameters:
// ControllerIndex [in] SDHC controller index
//
// Returns: TRUE if successful
// FALSE if not successful
//
//------------------------------------------------------------------------------
BOOL BspSdhcCardDetectInitialize(DWORD ControllerIndex)
{
PHYSICAL_ADDRESS phyAddr;
CSP_PBC_REGS *pPBC;
phyAddr.QuadPart = BSP_BASE_REG_PA_PBC_BASE;
// Map PBC registers to virtual address space
pPBC = (PCSP_PBC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_PBC_REGS), FALSE);
if (pPBC == NULL)
{
DEBUGMSG(1,
(TEXT("%s(): MmMapIoSpace failed!\r\n"), __WFUNCTION__));
return FALSE;
}
if (ControllerIndex == 1)
{
//Confiure GPIO1_1 for card detection interrupt
DDKIomuxSetPinMux(DDK_IOMUX_PIN_GPIO1_1, DDK_IOMUX_OUT_GPIO, DDK_IOMUX_IN_GPIO);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_GPIO1_1, 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(DDK_GPIO_PORT1, 1, DDK_GPIO_DIR_IN, DDK_GPIO_INTR_HIGH_LEV);
DDKGpioClearIntrPin(DDK_GPIO_PORT1, 1);
DDKGpioBindIrq(DDK_GPIO_PORT1, 1, BspSdhcGetIrq(ControllerIndex));
// Enable card detect interface in PBC (BCTRL3[10] - CARD1_SEL)
OUTREG16(&pPBC->BCTRL3_CLEAR, (1<<PBC_BCTRL3_CARD1_SEL));
}
else
{
//Confiure GPIO1_2 for card detection interrupt
DDKIomuxSetPinMux(DDK_IOMUX_PIN_GPIO1_2, DDK_IOMUX_OUT_GPIO, DDK_IOMUX_IN_GPIO);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_GPIO1_2, 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(DDK_GPIO_PORT1, 2, DDK_GPIO_DIR_IN, DDK_GPIO_INTR_HIGH_LEV);
DDKGpioClearIntrPin(DDK_GPIO_PORT1, 2);
DDKGpioBindIrq(DDK_GPIO_PORT1, 2, BspSdhcGetIrq(ControllerIndex));
// Enable card detect interface in PBC (BCTRL3[11] - CARD2_SEL)
OUTREG16(&pPBC->BCTRL3_CLEAR, (1<<PBC_BCTRL3_CARD2_SEL));
}
// free the virtual space allocated for PBC memory map
MmUnmapIoSpace(pPBC, sizeof(CSP_PBC_REGS));
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcSetcardDetectType
//
// setup card detection type (removal or insertion)
//
// Parameters:
// ControllerIndex [in] controller index
// type [in] detection type (insertion or removal)
//
// Returns: None
//
//------------------------------------------------------------------------------
void BspSdhcSetcardDetectType(DWORD ControllerIndex, UINT8 type)
{
if (ControllerIndex == 1)
{
if (type == CARD_DETECT_INSERTION)
{
//Set GPIO pin to sense card insertion
DDKGpioSetConfig(DDK_GPIO_PORT1, 1, DDK_GPIO_DIR_IN, DDK_GPIO_INTR_HIGH_LEV);
}
if (type == CARD_DETECT_REMOVAL)
{
//Set GPIO pin to sense card removal
DDKGpioSetConfig(DDK_GPIO_PORT1, 1, DDK_GPIO_DIR_IN, DDK_GPIO_INTR_LOW_LEV);
}
}
else
{
if (type == CARD_DETECT_INSERTION)
{
//Set GPIO pin to sense card insertion
DDKGpioSetConfig(DDK_GPIO_PORT1, 2, DDK_GPIO_DIR_IN, DDK_GPIO_INTR_HIGH_LEV);
}
if (type == CARD_DETECT_REMOVAL)
{
//Set GPIO pin to sense card removal
DDKGpioSetConfig(DDK_GPIO_PORT1, 2, DDK_GPIO_DIR_IN, DDK_GPIO_INTR_LOW_LEV);
}
}
}
//------------------------------------------------------------------------------
//
// Function: BSPSdhcIsCardWriteProtected
//
// This function is to check whether card is write protected.
//
// Parameters:
// ControllerIndex [in] controller index
//
// Returns:
// Return TRUE if card is write protected
// FALSE if card is not write protected
//
//------------------------------------------------------------------------------
BOOL BSPSdhcIsCardWriteProtected(DWORD ControllerIndex)
{
BOOL bWriteProtected = FALSE; //Whether card is write protected
PHYSICAL_ADDRESS phyAddr;
CSP_PBC_REGS *pPBC;
phyAddr.QuadPart = BSP_BASE_REG_PA_PBC_BASE;
// Map PBC registers to virtual address space
pPBC = (PCSP_PBC_REGS) MmMapIoSpace(phyAddr, sizeof(CSP_PBC_REGS), FALSE);
if (pPBC == NULL)
{
DEBUGMSG(1,
(TEXT("%s(): MmMapIoSpace failed!\r\n"), __WFUNCTION__));
return FALSE;
}
if (ControllerIndex == 1)
{
//BSTAT1[7] = 1 means card is write protected
if (EXTREG32BF(&pPBC->BSTAT1, PBC_STAT1_SD1_WP))
{
bWriteProtected = TRUE;
}
}
else
{
//BSTAT1[8] = 1 means card is write protected
if (EXTREG32BF(&pPBC->BSTAT1, PBC_STAT1_SD2_WP))
{
bWriteProtected = TRUE;
}
}
// free the virtual space allocated for PBC memory map
MmUnmapIoSpace(pPBC, sizeof(CSP_PBC_REGS));
return bWriteProtected;
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcGetSdmaChannelPriority
//
// This function is to get sdma channel priority
//
// Parameters:
// None
//
// Returns:
// Return channel priority
//
//------------------------------------------------------------------------------
UINT BspSdhcGetSdmaChannelPriority(DWORD ControllerIndex)
{
if (ControllerIndex == 1)
{
return BSP_SDMA_CHNPRI_SDHC1;
}
else
{
return BSP_SDMA_CHNPRI_SDHC2;
}
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcGetSdmaChannelTx
//
// This function is to get Tx channel number
//
// Parameters:
// None
//
// Returns:
// Tx Channel Number
//
//------------------------------------------------------------------------------
UINT BspSdhcGetSdmaChannelTx(DWORD ControllerIndex)
{
if (ControllerIndex == 1)
{
return DDK_DMA_REQ_SDHC1_TX;
}
else
{
return DDK_DMA_REQ_SDHC2_TX;
}
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcGetSdmaChannelRx
//
// This function is to get Rx channel number
//
// Parameters:
// None
//
// Returns:
// Rx Channel Number
//
//------------------------------------------------------------------------------
UINT BspSdhcGetSdmaChannelRx(DWORD ControllerIndex)
{
if (ControllerIndex == 1)
{
return DDK_DMA_REQ_SDHC1_RX;
}
else
{
return DDK_DMA_REQ_SDHC2_RX;
}
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcIsSdmaSupported
//
// This function is to know whether DMA support is enabled for the controller
//
// Parameters:
// None
//
// Returns:
// TRUE - DMA supported
// FALSE - DMA not supported
//
//------------------------------------------------------------------------------
BOOL BspSdhcIsSdmaSupported(DWORD ControllerIndex)
{
if (ControllerIndex == 1)
{
#if BSP_SDMA_SUPPORT_SDHC1
return TRUE;
#else
return FALSE;
#endif // BSP_SDMA_SUPPORT_SDHC1
}
else
{
#if BSP_SDMA_SUPPORT_SDHC2
return TRUE;
#else
return FALSE;
#endif // BSP_SDMA_SUPPORT_SDHC2
}
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcIsClockGatingBetweenCmdsSupported
//
// This function is to know whether controller can be clock gated between commands
//
// Parameters:
// None
//
// Returns:
// TRUE - if supported
// FALSE - if not supported
//
//------------------------------------------------------------------------------
BOOL BspSdhcIsClockGatingBetweenCmdsSupported(DWORD ControllerIndex)
{
if (ControllerIndex == 1)
{
#if BSP_CLK_GATING_BETWEEN_CMDS_SDHC1
return TRUE;
#else
return FALSE;
#endif // BSP_CLK_GATING_BETWEEN_CMDS_SDHC1
}
else
{
#if BSP_CLK_GATING_BETWEEN_CMDS_SDHC2
return TRUE;
#else
return FALSE;
#endif // BSP_CLK_GATING_BETWEEN_CMDS_SDHC2
}
}
//------------------------------------------------------------------------------
//
// Function: BspSdhcGetSdmaMinTransfer
//
// Specifies the minimum transfer size for which DMA should be used. Small
// transfers may not benefit from DMA usage due to the overhead associated with
// setting up the DMA transfer.
//
// Parameters:
// None
//
// Returns:
// Minimum transfer size for DMA in bytes.
//
//------------------------------------------------------------------------------
UINT32 BspSdhcGetSdmaMinTransfer(VOID)
{
return BSP_SDHC_SDMA_MIN_TRANSFER;
}
//------------------------------------------------------------------------------
//
// Function: BSPGetMaxCardCLK
//
// Specifies the maximum card clock frequency supported by the platform.
// Note that this is a limitation.
//
// Parameters:
// None
//
// Returns:
// card clock frequency
//
//------------------------------------------------------------------------------
UINT32 BSPGetMaxCardCLK(void)
{
return BSP_SDHC_MAX_SDBUS_CLK_SUPPORTED;
}
//------------------------------------------------------------------------------
//
// Function: BSPPollDataLength
//
// Specifies the polling duration of data transfer in terms of data bytes.
//
// Parameters:
// None
//
// Returns:
// number of bytes to poll for
//
//------------------------------------------------------------------------------
UINT32 BSPPollDataLength(void)
{
return BSP_SDHC_POLL_DATA_LENGTH;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -