lib/sw_apps/zynqmp_pmufw/src/idle_hooks.c
void NodeSdioIdle(u32 BaseAddress)
{
	u16 EmmcStatus;
	u8 Val;
	u32 StatusReg;
	u32 PresentStateReg;
	u32 Timeout = MAX_TIMEOUT;
	u32 SdpsActive = (XSDPS_PSR_INHIBIT_CMD_MASK | XSDPS_PSR_INHIBIT_DAT_MASK
													| XSDPS_PSR_DAT_ACTIVE_MASK);

	PresentStateReg = XSdPs_ReadReg8(BaseAddress, XSDPS_PRES_STATE_OFFSET);
	/* Check for Card Present */
	if (PresentStateReg & XSDPS_PSR_CARD_INSRT_MASK) {
		/* Check for SD idle */
		do {
			StatusReg = XSdPs_ReadReg8(BaseAddress, XSDPS_PRES_STATE_OFFSET);
		} while ((StatusReg & SdpsActive) && --Timeout);
	}
	if (Timeout == 0) {
		PmWarn("sd not idle\r\n");
	}

	/* Reset the eMMC card */
	EmmcStatus = Xil_In32(IOU_SLCR_BASE + IOU_SD_CTRL_OFFSET);

#ifdef XPMU_SD_0
	if ((BaseAddress == XPMU_SD_0_BASEADDR)
			&& (EmmcStatus & SD0_EMMC_SEL_MASK)) {
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET);
		XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET,
				Val | XSDPS_PC_EMMC_HW_RST_MASK);
		usleep(1000 * EMMC_RESET_TIME);
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET);
		XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET,
				Val & ~XSDPS_PC_EMMC_HW_RST_MASK);
	}
#endif

#ifdef XPMU_SD_1
	if ((BaseAddress == XPMU_SD_1_BASEADDR)
			&& (EmmcStatus & SD1_EMMC_SEL_MASK)) {
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET);
		XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET,
				Val | XSDPS_PC_EMMC_HW_RST_MASK);
		usleep(1000 * EMMC_RESET_TIME);
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET);
		XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET,
				Val & ~XSDPS_PC_EMMC_HW_RST_MASK);
	}
#endif
	/* Disable bus power */
	XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET, 0);
	usleep(1000 * SD_SLEEP_TIME);

	/* "Software reset for all" is initiated */
	XSdPs_WriteReg8(BaseAddress, XSDPS_SW_RST_OFFSET, XSDPS_SWRST_ALL_MASK);

	Timeout = MAX_TIMEOUT;
	/* Proceed with initialization only after reset is complete */
	Val = XSdPs_ReadReg8(BaseAddress, XSDPS_SW_RST_OFFSET);
	while (((Val & XSDPS_SWRST_ALL_MASK) != 0U) && --Timeout) {
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_SW_RST_OFFSET);
	}
	if (Timeout == 0) {
		PmWarn("sd not reset\r\n");
	}
}
/**
 * NodeSdioIdle() - Custom code to idle the SDIO
 *
 * @BaseAddress: SDIO base address
 */
Custom code to idle the SDIO
@BaseAddress: SDIO base address
Custom code to idle the SDIO @BaseAddress : SDIO base address
void NodeSdioIdle(u32 BaseAddress)
{
	u16 EmmcStatus;
	u8 Val;
	u32 StatusReg;
	u32 PresentStateReg;
	u32 Timeout = MAX_TIMEOUT;
	u32 SdpsActive = (XSDPS_PSR_INHIBIT_CMD_MASK | XSDPS_PSR_INHIBIT_DAT_MASK
													| XSDPS_PSR_DAT_ACTIVE_MASK);
	PresentStateReg = XSdPs_ReadReg8(BaseAddress, XSDPS_PRES_STATE_OFFSET);
	if (PresentStateReg & XSDPS_PSR_CARD_INSRT_MASK) {
		do {
			StatusReg = XSdPs_ReadReg8(BaseAddress, XSDPS_PRES_STATE_OFFSET);
		} while ((StatusReg & SdpsActive) && --Timeout);
	}
	if (Timeout == 0) {
		PmWarn("sd not idle\r\n");
	}
	EmmcStatus = Xil_In32(IOU_SLCR_BASE + IOU_SD_CTRL_OFFSET);
#ifdef XPMU_SD_0
	if ((BaseAddress == XPMU_SD_0_BASEADDR)
			&& (EmmcStatus & SD0_EMMC_SEL_MASK)) {
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET);
		XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET,
				Val | XSDPS_PC_EMMC_HW_RST_MASK);
		usleep(1000 * EMMC_RESET_TIME);
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET);
		XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET,
				Val & ~XSDPS_PC_EMMC_HW_RST_MASK);
	}
#endif
#ifdef XPMU_SD_1
	if ((BaseAddress == XPMU_SD_1_BASEADDR)
			&& (EmmcStatus & SD1_EMMC_SEL_MASK)) {
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET);
		XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET,
				Val | XSDPS_PC_EMMC_HW_RST_MASK);
		usleep(1000 * EMMC_RESET_TIME);
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET);
		XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET,
				Val & ~XSDPS_PC_EMMC_HW_RST_MASK);
	}
#endif
	XSdPs_WriteReg8(BaseAddress, XSDPS_POWER_CTRL_OFFSET, 0);
	usleep(1000 * SD_SLEEP_TIME);
	XSdPs_WriteReg8(BaseAddress, XSDPS_SW_RST_OFFSET, XSDPS_SWRST_ALL_MASK);
	Timeout = MAX_TIMEOUT;
	Val = XSdPs_ReadReg8(BaseAddress, XSDPS_SW_RST_OFFSET);
	while (((Val & XSDPS_SWRST_ALL_MASK) != 0U) && --Timeout) {
		Val = XSdPs_ReadReg8(BaseAddress, XSDPS_SW_RST_OFFSET);
	}
	if (Timeout == 0) {
		PmWarn("sd not reset\r\n");
	}
}
void NodeSdioIdle ( u32 BaseAddress ) { u16 EmmcStatus ; u8 Val ; u32 StatusReg ; u32 PresentStateReg ; u32 Timeout = MAX_TIMEOUT ; u32 SdpsActive = ( XSDPS_PSR_INHIBIT_CMD_MASK | XSDPS_PSR_INHIBIT_DAT_MASK | XSDPS_PSR_DAT_ACTIVE_MASK ) ; PresentStateReg = XSdPs_ReadReg8 ( BaseAddress , XSDPS_PRES_STATE_OFFSET ) ; if ( PresentStateReg & XSDPS_PSR_CARD_INSRT_MASK ) { do { StatusReg = XSdPs_ReadReg8 ( BaseAddress , XSDPS_PRES_STATE_OFFSET ) ; } while ( ( StatusReg & SdpsActive ) && -- Timeout ) ; } if ( Timeout == 0 ) { PmWarn ( " \r \n " ) ; } EmmcStatus = Xil_In32 ( IOU_SLCR_BASE + IOU_SD_CTRL_OFFSET ) ; #ifdef XPMU_SD_0 if ( ( BaseAddress == XPMU_SD_0_BASEADDR ) && ( EmmcStatus & SD0_EMMC_SEL_MASK ) ) { Val = XSdPs_ReadReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET ) ; XSdPs_WriteReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET , Val | XSDPS_PC_EMMC_HW_RST_MASK ) ; usleep ( 1000 * EMMC_RESET_TIME ) ; Val = XSdPs_ReadReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET ) ; XSdPs_WriteReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET , Val & ~ XSDPS_PC_EMMC_HW_RST_MASK ) ; } #endif #ifdef XPMU_SD_1 if ( ( BaseAddress == XPMU_SD_1_BASEADDR ) && ( EmmcStatus & SD1_EMMC_SEL_MASK ) ) { Val = XSdPs_ReadReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET ) ; XSdPs_WriteReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET , Val | XSDPS_PC_EMMC_HW_RST_MASK ) ; usleep ( 1000 * EMMC_RESET_TIME ) ; Val = XSdPs_ReadReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET ) ; XSdPs_WriteReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET , Val & ~ XSDPS_PC_EMMC_HW_RST_MASK ) ; } #endif XSdPs_WriteReg8 ( BaseAddress , XSDPS_POWER_CTRL_OFFSET , 0 ) ; usleep ( 1000 * SD_SLEEP_TIME ) ; XSdPs_WriteReg8 ( BaseAddress , XSDPS_SW_RST_OFFSET , XSDPS_SWRST_ALL_MASK ) ; Timeout = MAX_TIMEOUT ; Val = XSdPs_ReadReg8 ( BaseAddress , XSDPS_SW_RST_OFFSET ) ; while ( ( ( Val & XSDPS_SWRST_ALL_MASK ) != 0U ) && -- Timeout ) { Val = XSdPs_ReadReg8 ( BaseAddress , XSDPS_SW_RST_OFFSET ) ; } if ( Timeout == 0 ) { PmWarn ( " \r \n " ) ; } }
NodeSdioIdle() - Custom code to idle the SDIO
 @BaseAddress: SDIO base address
NodeSdioIdle () - Custom code to idle the SDIO @BaseAddress : SDIO base address
/* Check for Card Present */ /* Check for SD idle */ /* Reset the eMMC card */ /* Disable bus power */ /* "Software reset for all" is initiated */ /* Proceed with initialization only after reset is complete */