XilinxProcessorIPLib/drivers/nandps/src/xnandps.c
int XNandPs_CfgInitialize(XNandPs *InstancePtr, XNandPs_Config *ConfigPtr,
				u32 SmcBaseAddr, u32 FlashBaseAddr)
{
	u32 PageSize;
	int Status;

	/*
	 * Assert the input arguments.
	 */
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(ConfigPtr != NULL);

	/*
	 * Set the values read from the device config and the base address.
	 */
	InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
	InstancePtr->Config.SmcBase = SmcBaseAddr;
	InstancePtr->Config.FlashBase = FlashBaseAddr;
	InstancePtr->Config.FlashWidth = ConfigPtr->FlashWidth;

	XNandPs_WriteReg(InstancePtr->Config.SmcBase +
		XNANDPS_MEMC_CLR_CONFIG_OFFSET,
		XNANDPS_CLR_CONFIG);	/* Disable interrupts */

	/*
	 * ONFI query to get geometry
	 */
	Status = Onfi_NandInit(InstancePtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}

	/*
	 * Updating Config structure flash width
	 */
	InstancePtr->Config.FlashWidth = InstancePtr->Geometry.FlashWidth;

	/*
	 * Fill the spare buffer pointer
	 */
	PageSize = InstancePtr->Geometry.BytesPerPage;
	InstancePtr->SpareBufPtr = &InstancePtr->DataBuf[PageSize];

	/*
	 * Initialize ECC Block Parameters
	 */
	switch (InstancePtr->EccMode)
	{
		case XNANDPS_ECC_NONE:
			/* Fall through */
		case XNANDPS_ECC_ONDIE:
			/* Bypass the ECC block in the SMC controller */
			XNandPs_EccDisable(InstancePtr);

			/* Initialize the Read/Write page routines */
			InstancePtr->ReadPage = XNandPs_ReadPage;
			InstancePtr->WritePage = XNandPs_WritePage;
			break;
		case XNANDPS_ECC_HW:
			/* Use SMC ECC controller ECC block */
			Status = XNandPs_EccHwInit(InstancePtr);
			if (Status != XST_SUCCESS)
				return Status;

			/* Initialize ECC SW parameters */
			Status = XNandPs_EccSwInit(InstancePtr);
			if (Status != XST_SUCCESS)
				return Status;

			/* Initialize the Read/Write page routines */
			InstancePtr->ReadPage = XNandPs_ReadPage_HwEcc;
			InstancePtr->WritePage = XNandPs_WritePage_HwEcc;
			break;
		default:
			return XST_FAILURE;
	}

	/*
	 * Indicate the instance is now ready to use, initialized without error.
	 */
	InstancePtr->IsReady = XIL_COMPONENT_IS_READY;

	/*
	 * Scan for the bad block table(bbt) stored in the flash & load it in
	 * memory(RAM).  If bbt is not found, create bbt by scanning factory
	 * marked bad blocks and store it in last good blocks of flash.
	 */
	XNandPs_InitBbtDesc(InstancePtr);
	Status = XNandPs_ScanBbt(InstancePtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* This function initializes a specific XNandPs device/instance. This function
* must be called prior to using the flash device to read or write any data.
*
* @param	InstancePtr is a pointer to the XNandPs instance.
* @param	ConfigPtr points to the XNandPs device configuration structure.
* @param	SmcBaseAddr is the base address of SMC controller.
* @param	FlashBaseAddr is the base address of NAND flash.
*
* @return
*		- XST_SUCCESS if successful.
*		- XST_FAILURE if fail.
*
* @note		The user needs to first call the XNandPs_LookupConfig() API
*		which returns the Configuration structure pointer which is
*		passed as a parameter to the XNandPs_CfgInitialize() API.
*
******************************************************************************/
This function initializes a specific XNandPs device/instance. This function
must be called prior to using the flash device to read or write any data.
This function initializes a specific XNandPs device / instance . This function must be called prior to using the flash device to read or write any data .
int XNandPs_CfgInitialize(XNandPs *InstancePtr, XNandPs_Config *ConfigPtr,
				u32 SmcBaseAddr, u32 FlashBaseAddr)
{
	u32 PageSize;
	int Status;
	Xil_AssertNonvoid(InstancePtr != NULL);
	Xil_AssertNonvoid(ConfigPtr != NULL);
	InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
	InstancePtr->Config.SmcBase = SmcBaseAddr;
	InstancePtr->Config.FlashBase = FlashBaseAddr;
	InstancePtr->Config.FlashWidth = ConfigPtr->FlashWidth;
	XNandPs_WriteReg(InstancePtr->Config.SmcBase +
		XNANDPS_MEMC_CLR_CONFIG_OFFSET,
		XNANDPS_CLR_CONFIG);	
	Status = Onfi_NandInit(InstancePtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}
	InstancePtr->Config.FlashWidth = InstancePtr->Geometry.FlashWidth;
	PageSize = InstancePtr->Geometry.BytesPerPage;
	InstancePtr->SpareBufPtr = &InstancePtr->DataBuf[PageSize];
	switch (InstancePtr->EccMode)
	{
		case XNANDPS_ECC_NONE:
		case XNANDPS_ECC_ONDIE:
			XNandPs_EccDisable(InstancePtr);
			InstancePtr->ReadPage = XNandPs_ReadPage;
			InstancePtr->WritePage = XNandPs_WritePage;
			break;
		case XNANDPS_ECC_HW:
			Status = XNandPs_EccHwInit(InstancePtr);
			if (Status != XST_SUCCESS)
				return Status;
			Status = XNandPs_EccSwInit(InstancePtr);
			if (Status != XST_SUCCESS)
				return Status;
			InstancePtr->ReadPage = XNandPs_ReadPage_HwEcc;
			InstancePtr->WritePage = XNandPs_WritePage_HwEcc;
			break;
		default:
			return XST_FAILURE;
	}
	InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
	XNandPs_InitBbtDesc(InstancePtr);
	Status = XNandPs_ScanBbt(InstancePtr);
	if (Status != XST_SUCCESS) {
		return Status;
	}
	return XST_SUCCESS;
}
int XNandPs_CfgInitialize ( XNandPs * InstancePtr , XNandPs_Config * ConfigPtr , u32 SmcBaseAddr , u32 FlashBaseAddr ) { u32 PageSize ; int Status ; Xil_AssertNonvoid ( InstancePtr != NULL ) ; Xil_AssertNonvoid ( ConfigPtr != NULL ) ; InstancePtr -> Config . DeviceId = ConfigPtr -> DeviceId ; InstancePtr -> Config . SmcBase = SmcBaseAddr ; InstancePtr -> Config . FlashBase = FlashBaseAddr ; InstancePtr -> Config . FlashWidth = ConfigPtr -> FlashWidth ; XNandPs_WriteReg ( InstancePtr -> Config . SmcBase + XNANDPS_MEMC_CLR_CONFIG_OFFSET , XNANDPS_CLR_CONFIG ) ; Status = Onfi_NandInit ( InstancePtr ) ; if ( Status != XST_SUCCESS ) { return Status ; } InstancePtr -> Config . FlashWidth = InstancePtr -> Geometry . FlashWidth ; PageSize = InstancePtr -> Geometry . BytesPerPage ; InstancePtr -> SpareBufPtr = & InstancePtr -> DataBuf [ PageSize ] ; switch ( InstancePtr -> EccMode ) { case XNANDPS_ECC_NONE : case XNANDPS_ECC_ONDIE : XNandPs_EccDisable ( InstancePtr ) ; InstancePtr -> ReadPage = XNandPs_ReadPage ; InstancePtr -> WritePage = XNandPs_WritePage ; break ; case XNANDPS_ECC_HW : Status = XNandPs_EccHwInit ( InstancePtr ) ; if ( Status != XST_SUCCESS ) return Status ; Status = XNandPs_EccSwInit ( InstancePtr ) ; if ( Status != XST_SUCCESS ) return Status ; InstancePtr -> ReadPage = XNandPs_ReadPage_HwEcc ; InstancePtr -> WritePage = XNandPs_WritePage_HwEcc ; break ; default : return XST_FAILURE ; } InstancePtr -> IsReady = XIL_COMPONENT_IS_READY ; XNandPs_InitBbtDesc ( InstancePtr ) ; Status = XNandPs_ScanBbt ( InstancePtr ) ; if ( Status != XST_SUCCESS ) { return Status ; } return XST_SUCCESS ; }
This function initializes a specific XNandPs device/instance.
This function initializes a specific XNandPs device / instance .
/*
	 * Assert the input arguments.
	 */ /*
	 * Set the values read from the device config and the base address.
	 */ /* Disable interrupts */ /*
	 * ONFI query to get geometry
	 */ /*
	 * Updating Config structure flash width
	 */ /*
	 * Fill the spare buffer pointer
	 */ /*
	 * Initialize ECC Block Parameters
	 */ /* Fall through */ /* Bypass the ECC block in the SMC controller */ /* Initialize the Read/Write page routines */ /* Use SMC ECC controller ECC block */ /* Initialize ECC SW parameters */ /* Initialize the Read/Write page routines */ /*
	 * Indicate the instance is now ready to use, initialized without error.
	 */ /*
	 * Scan for the bad block table(bbt) stored in the flash & load it in
	 * memory(RAM).  If bbt is not found, create bbt by scanning factory
	 * marked bad blocks and store it in last good blocks of flash.
	 */