lib/sw_services/xilflash/src/xilflash_amd.c
int XFlashAmd_Initialize(XFlash * InstancePtr)
{
	u8 Index;
	u8 BusWidth;
	u32 Layout;
	u32 PartMode;
	u32 ParamBlocks;
	u32 ParamBlockSize;
	u32 CurrentAbsoluteOffset;
	u32 CurrentAbsoluteBlock;
	XFlashVendorData_Amd *DevDataPtr;

	/*
	 * Verify inputs are valid.
	 */
	if(InstancePtr == NULL) {
		return (XST_FAILURE);
	}

	/*
	 * Grab layout and get Vendor specific part information.
	 */
	Layout = InstancePtr->Geometry.MemoryLayout;
	DevDataPtr = GET_PARTDATA(InstancePtr);

	/*
	 * Setup alignment of the write buffer.
	 */
	if (InstancePtr->Properties.ProgCap.WriteBufferSize != 0) {
		InstancePtr->Properties.ProgCap.WriteBufferAlignmentMask =
			InstancePtr->Properties.ProgCap.WriteBufferSize - 1;
	}

	/*
	 * Setup layout dependent attributes. These include:
	 *	- Part access primitive functions optimized for a specific bus
	 *	  width.
	 */
	switch (Layout) {
		case XFL_LAYOUT_X16_X8_X1:
			DevDataPtr->SendCmd = SendCmd8;
			DevDataPtr->SendCmdSeq = SendCmdSeq8;
			DevDataPtr->WriteFlash = WriteFlash8;
			DevDataPtr->PollSR = PollSR8;
			DevDataPtr->WriteBuffer = WriteBuffer8;
			DevDataPtr->GetStatus = GetStatus8;
			break;

		case XFL_LAYOUT_X16_X16_X1:
			DevDataPtr->SendCmd = SendCmd16;
			DevDataPtr->SendCmdSeq = SendCmdSeq16;
			DevDataPtr->WriteFlash = WriteFlash16;
			DevDataPtr->PollSR = PollSR16;
			DevDataPtr->WriteBuffer = WriteBuffer16;
			DevDataPtr->GetStatus = GetStatus16;
			break;

		case XFL_LAYOUT_X16_X16_X2:
			DevDataPtr->SendCmd = SendCmd32;
			DevDataPtr->SendCmdSeq = SendCmdSeq32;
			DevDataPtr->WriteFlash = WriteFlash32;
			DevDataPtr->PollSR = PollSR32;
			DevDataPtr->WriteBuffer = WriteBuffer32;
			DevDataPtr->GetStatus = GetStatus32;
			break;

		default:
			return (XFLASH_PART_NOT_SUPPORTED);
	}

	/*
	 * Get part ID and Reset the part.
	 */
	GetPartID(InstancePtr);

	/*
	 * Setup bank information as per the boot block location.
	 */

	 /*
	  * Get device operational mode.
	  */
	 PartMode = (Layout & XFL_LAYOUT_PART_MODE_MASK);
	if (PartMode == XFL_LAYOUT_PART_MODE_8) {
		BusWidth = 1;
	}
	else if (PartMode == XFL_LAYOUT_PART_MODE_16) {
		BusWidth = 2;
	}
	else {
		return (XFLASH_PART_NOT_SUPPORTED);
	}

	InstancePtr->Geometry.DeviceSize = InstancePtr->Geometry.DeviceSize /
						BusWidth;
	for (Index = 0; Index < InstancePtr->Geometry.NumEraseRegions;
		Index++) {
		InstancePtr->Geometry.EraseRegion[Index].Size =
		InstancePtr->Geometry.EraseRegion[Index].Size / BusWidth;
	}
	/*
	 * If device is top boot then change erase region information.
	 */
	if (((InstancePtr->Geometry.BootMode == XFL_AMD_TOP_BOOT) ||
	    (InstancePtr->Geometry.BootMode == XFL_AMD_TOP_WP_UNIFORM)) &&
	    (InstancePtr->Geometry.NumEraseRegions > 1)) {
		/*
		 * Move boot block region to top.
		 */
		ParamBlocks = InstancePtr->Geometry.EraseRegion[0].Number;
		ParamBlockSize = InstancePtr->Geometry.EraseRegion[0].Size;

		InstancePtr->Geometry.EraseRegion[0].Number =
			InstancePtr->Geometry.EraseRegion[1].Number;
		InstancePtr->Geometry.EraseRegion[0].Size =
			InstancePtr->Geometry.EraseRegion[1].Size ;

		InstancePtr->Geometry.EraseRegion[1].Number = ParamBlocks ;
		InstancePtr->Geometry.EraseRegion[1].Size = ParamBlockSize;

		/*
		 * Calculate Erase region offset and block address.
		 */
		CurrentAbsoluteOffset = 0;
		CurrentAbsoluteBlock = 0;
		for (Index = 0;
			Index < InstancePtr->Geometry.NumEraseRegions;
			Index++) {
			/*
			 * Calculate part offset.
			 */
			InstancePtr->Geometry.EraseRegion[Index].AbsoluteOffset
					= CurrentAbsoluteOffset;
			InstancePtr->Geometry.EraseRegion[Index].AbsoluteBlock
					= CurrentAbsoluteBlock;

			/*
			 * Increment absolute counters.
			 */
			CurrentAbsoluteOffset +=
			(InstancePtr->Geometry.EraseRegion[Index].Size *
			InstancePtr->Geometry.EraseRegion[Index].Number);
			CurrentAbsoluteBlock +=
			InstancePtr->Geometry.EraseRegion[Index].Number;
		}
	}
	else if (BusWidth != 1) {
		/*
		 * Calculate Erase region offset and block address.
		 */
		CurrentAbsoluteOffset = 0;
		CurrentAbsoluteBlock = 0;
		for (Index = 0;
			Index < InstancePtr->Geometry.NumEraseRegions;
			Index++) {
			/*
			 * Calculate part offset.
			 */
			InstancePtr->Geometry.EraseRegion[Index].AbsoluteOffset
					= CurrentAbsoluteOffset;
			InstancePtr->Geometry.EraseRegion[Index].AbsoluteBlock
					= CurrentAbsoluteBlock;

			/*
			 * Increment absolute counters.
			 */
			CurrentAbsoluteOffset +=
			(InstancePtr->Geometry.EraseRegion[Index].Size *
			InstancePtr->Geometry.EraseRegion[Index].Number);
			CurrentAbsoluteBlock +=
			InstancePtr->Geometry.EraseRegion[Index].Number;
		}
	}


	(void) XFlashAmd_Reset(InstancePtr);

	return (XST_SUCCESS);
}
/*****************************************************************************/
/**
*
* Initializes a XFlash instance with device family specific details. The
* initialization entails:
*
* - Assign part access primitive functions depending on bus width.
* - Reset the device.
*
* @param	InstancePtr is a pointer to the XFlash instance.
*
* @return
* 		- XST_SUCCESS if successful.
*		- XFLASH_PART_NOT_SUPPORTED if the command set algorithm or
*		  Layout is not supported by any specific flash device family
*		  compiled into the system.
*		- XST_FAILURE if failed.
*
* @note		None.
*
******************************************************************************/
Initializes a XFlash instance with device family specific details. The
initialization entails.

Assign part access primitive functions depending on bus width.
Reset the device.
Initializes a XFlash instance with device family specific details . The initialization entails . Assign part access primitive functions depending on bus width . Reset the device .
int XFlashAmd_Initialize(XFlash * InstancePtr)
{
	u8 Index;
	u8 BusWidth;
	u32 Layout;
	u32 PartMode;
	u32 ParamBlocks;
	u32 ParamBlockSize;
	u32 CurrentAbsoluteOffset;
	u32 CurrentAbsoluteBlock;
	XFlashVendorData_Amd *DevDataPtr;
	if(InstancePtr == NULL) {
		return (XST_FAILURE);
	}
	Layout = InstancePtr->Geometry.MemoryLayout;
	DevDataPtr = GET_PARTDATA(InstancePtr);
	if (InstancePtr->Properties.ProgCap.WriteBufferSize != 0) {
		InstancePtr->Properties.ProgCap.WriteBufferAlignmentMask =
			InstancePtr->Properties.ProgCap.WriteBufferSize - 1;
	}
	switch (Layout) {
		case XFL_LAYOUT_X16_X8_X1:
			DevDataPtr->SendCmd = SendCmd8;
			DevDataPtr->SendCmdSeq = SendCmdSeq8;
			DevDataPtr->WriteFlash = WriteFlash8;
			DevDataPtr->PollSR = PollSR8;
			DevDataPtr->WriteBuffer = WriteBuffer8;
			DevDataPtr->GetStatus = GetStatus8;
			break;
		case XFL_LAYOUT_X16_X16_X1:
			DevDataPtr->SendCmd = SendCmd16;
			DevDataPtr->SendCmdSeq = SendCmdSeq16;
			DevDataPtr->WriteFlash = WriteFlash16;
			DevDataPtr->PollSR = PollSR16;
			DevDataPtr->WriteBuffer = WriteBuffer16;
			DevDataPtr->GetStatus = GetStatus16;
			break;
		case XFL_LAYOUT_X16_X16_X2:
			DevDataPtr->SendCmd = SendCmd32;
			DevDataPtr->SendCmdSeq = SendCmdSeq32;
			DevDataPtr->WriteFlash = WriteFlash32;
			DevDataPtr->PollSR = PollSR32;
			DevDataPtr->WriteBuffer = WriteBuffer32;
			DevDataPtr->GetStatus = GetStatus32;
			break;
		default:
			return (XFLASH_PART_NOT_SUPPORTED);
	}
	GetPartID(InstancePtr);
	 PartMode = (Layout & XFL_LAYOUT_PART_MODE_MASK);
	if (PartMode == XFL_LAYOUT_PART_MODE_8) {
		BusWidth = 1;
	}
	else if (PartMode == XFL_LAYOUT_PART_MODE_16) {
		BusWidth = 2;
	}
	else {
		return (XFLASH_PART_NOT_SUPPORTED);
	}
	InstancePtr->Geometry.DeviceSize = InstancePtr->Geometry.DeviceSize /
						BusWidth;
	for (Index = 0; Index < InstancePtr->Geometry.NumEraseRegions;
		Index++) {
		InstancePtr->Geometry.EraseRegion[Index].Size =
		InstancePtr->Geometry.EraseRegion[Index].Size / BusWidth;
	}
	if (((InstancePtr->Geometry.BootMode == XFL_AMD_TOP_BOOT) ||
	    (InstancePtr->Geometry.BootMode == XFL_AMD_TOP_WP_UNIFORM)) &&
	    (InstancePtr->Geometry.NumEraseRegions > 1)) {
		ParamBlocks = InstancePtr->Geometry.EraseRegion[0].Number;
		ParamBlockSize = InstancePtr->Geometry.EraseRegion[0].Size;
		InstancePtr->Geometry.EraseRegion[0].Number =
			InstancePtr->Geometry.EraseRegion[1].Number;
		InstancePtr->Geometry.EraseRegion[0].Size =
			InstancePtr->Geometry.EraseRegion[1].Size ;
		InstancePtr->Geometry.EraseRegion[1].Number = ParamBlocks ;
		InstancePtr->Geometry.EraseRegion[1].Size = ParamBlockSize;
		CurrentAbsoluteOffset = 0;
		CurrentAbsoluteBlock = 0;
		for (Index = 0;
			Index < InstancePtr->Geometry.NumEraseRegions;
			Index++) {
			InstancePtr->Geometry.EraseRegion[Index].AbsoluteOffset
					= CurrentAbsoluteOffset;
			InstancePtr->Geometry.EraseRegion[Index].AbsoluteBlock
					= CurrentAbsoluteBlock;
			CurrentAbsoluteOffset +=
			(InstancePtr->Geometry.EraseRegion[Index].Size *
			InstancePtr->Geometry.EraseRegion[Index].Number);
			CurrentAbsoluteBlock +=
			InstancePtr->Geometry.EraseRegion[Index].Number;
		}
	}
	else if (BusWidth != 1) {
		CurrentAbsoluteOffset = 0;
		CurrentAbsoluteBlock = 0;
		for (Index = 0;
			Index < InstancePtr->Geometry.NumEraseRegions;
			Index++) {
			InstancePtr->Geometry.EraseRegion[Index].AbsoluteOffset
					= CurrentAbsoluteOffset;
			InstancePtr->Geometry.EraseRegion[Index].AbsoluteBlock
					= CurrentAbsoluteBlock;
			CurrentAbsoluteOffset +=
			(InstancePtr->Geometry.EraseRegion[Index].Size *
			InstancePtr->Geometry.EraseRegion[Index].Number);
			CurrentAbsoluteBlock +=
			InstancePtr->Geometry.EraseRegion[Index].Number;
		}
	}
	(void) XFlashAmd_Reset(InstancePtr);
	return (XST_SUCCESS);
}
int XFlashAmd_Initialize ( XFlash * InstancePtr ) { u8 Index ; u8 BusWidth ; u32 Layout ; u32 PartMode ; u32 ParamBlocks ; u32 ParamBlockSize ; u32 CurrentAbsoluteOffset ; u32 CurrentAbsoluteBlock ; XFlashVendorData_Amd * DevDataPtr ; if ( InstancePtr == NULL ) { return ( XST_FAILURE ) ; } Layout = InstancePtr -> Geometry . MemoryLayout ; DevDataPtr = GET_PARTDATA ( InstancePtr ) ; if ( InstancePtr -> Properties . ProgCap . WriteBufferSize != 0 ) { InstancePtr -> Properties . ProgCap . WriteBufferAlignmentMask = InstancePtr -> Properties . ProgCap . WriteBufferSize - 1 ; } switch ( Layout ) { case XFL_LAYOUT_X16_X8_X1 : DevDataPtr -> SendCmd = SendCmd8 ; DevDataPtr -> SendCmdSeq = SendCmdSeq8 ; DevDataPtr -> WriteFlash = WriteFlash8 ; DevDataPtr -> PollSR = PollSR8 ; DevDataPtr -> WriteBuffer = WriteBuffer8 ; DevDataPtr -> GetStatus = GetStatus8 ; break ; case XFL_LAYOUT_X16_X16_X1 : DevDataPtr -> SendCmd = SendCmd16 ; DevDataPtr -> SendCmdSeq = SendCmdSeq16 ; DevDataPtr -> WriteFlash = WriteFlash16 ; DevDataPtr -> PollSR = PollSR16 ; DevDataPtr -> WriteBuffer = WriteBuffer16 ; DevDataPtr -> GetStatus = GetStatus16 ; break ; case XFL_LAYOUT_X16_X16_X2 : DevDataPtr -> SendCmd = SendCmd32 ; DevDataPtr -> SendCmdSeq = SendCmdSeq32 ; DevDataPtr -> WriteFlash = WriteFlash32 ; DevDataPtr -> PollSR = PollSR32 ; DevDataPtr -> WriteBuffer = WriteBuffer32 ; DevDataPtr -> GetStatus = GetStatus32 ; break ; default : return ( XFLASH_PART_NOT_SUPPORTED ) ; } GetPartID ( InstancePtr ) ; PartMode = ( Layout & XFL_LAYOUT_PART_MODE_MASK ) ; if ( PartMode == XFL_LAYOUT_PART_MODE_8 ) { BusWidth = 1 ; } else if ( PartMode == XFL_LAYOUT_PART_MODE_16 ) { BusWidth = 2 ; } else { return ( XFLASH_PART_NOT_SUPPORTED ) ; } InstancePtr -> Geometry . DeviceSize = InstancePtr -> Geometry . DeviceSize / BusWidth ; for ( Index = 0 ; Index < InstancePtr -> Geometry . NumEraseRegions ; Index ++ ) { InstancePtr -> Geometry . EraseRegion [ Index ] . Size = InstancePtr -> Geometry . EraseRegion [ Index ] . Size / BusWidth ; } if ( ( ( InstancePtr -> Geometry . BootMode == XFL_AMD_TOP_BOOT ) || ( InstancePtr -> Geometry . BootMode == XFL_AMD_TOP_WP_UNIFORM ) ) && ( InstancePtr -> Geometry . NumEraseRegions > 1 ) ) { ParamBlocks = InstancePtr -> Geometry . EraseRegion [ 0 ] . Number ; ParamBlockSize = InstancePtr -> Geometry . EraseRegion [ 0 ] . Size ; InstancePtr -> Geometry . EraseRegion [ 0 ] . Number = InstancePtr -> Geometry . EraseRegion [ 1 ] . Number ; InstancePtr -> Geometry . EraseRegion [ 0 ] . Size = InstancePtr -> Geometry . EraseRegion [ 1 ] . Size ; InstancePtr -> Geometry . EraseRegion [ 1 ] . Number = ParamBlocks ; InstancePtr -> Geometry . EraseRegion [ 1 ] . Size = ParamBlockSize ; CurrentAbsoluteOffset = 0 ; CurrentAbsoluteBlock = 0 ; for ( Index = 0 ; Index < InstancePtr -> Geometry . NumEraseRegions ; Index ++ ) { InstancePtr -> Geometry . EraseRegion [ Index ] . AbsoluteOffset = CurrentAbsoluteOffset ; InstancePtr -> Geometry . EraseRegion [ Index ] . AbsoluteBlock = CurrentAbsoluteBlock ; CurrentAbsoluteOffset += ( InstancePtr -> Geometry . EraseRegion [ Index ] . Size * InstancePtr -> Geometry . EraseRegion [ Index ] . Number ) ; CurrentAbsoluteBlock += InstancePtr -> Geometry . EraseRegion [ Index ] . Number ; } } else if ( BusWidth != 1 ) { CurrentAbsoluteOffset = 0 ; CurrentAbsoluteBlock = 0 ; for ( Index = 0 ; Index < InstancePtr -> Geometry . NumEraseRegions ; Index ++ ) { InstancePtr -> Geometry . EraseRegion [ Index ] . AbsoluteOffset = CurrentAbsoluteOffset ; InstancePtr -> Geometry . EraseRegion [ Index ] . AbsoluteBlock = CurrentAbsoluteBlock ; CurrentAbsoluteOffset += ( InstancePtr -> Geometry . EraseRegion [ Index ] . Size * InstancePtr -> Geometry . EraseRegion [ Index ] . Number ) ; CurrentAbsoluteBlock += InstancePtr -> Geometry . EraseRegion [ Index ] . Number ; } } ( void ) XFlashAmd_Reset ( InstancePtr ) ; return ( XST_SUCCESS ) ; }
Initializes a XFlash instance with device family specific details.
Initializes a XFlash instance with device family specific details .
/*
	 * Verify inputs are valid.
	 */ /*
	 * Grab layout and get Vendor specific part information.
	 */ /*
	 * Setup alignment of the write buffer.
	 */ /*
	 * Setup layout dependent attributes. These include:
	 *	- Part access primitive functions optimized for a specific bus
	 *	  width.
	 */ /*
	 * Get part ID and Reset the part.
	 */ /*
	 * Setup bank information as per the boot block location.
	 */ /*
	  * Get device operational mode.
	  */ /*
	 * If device is top boot then change erase region information.
	 */ /*
		 * Move boot block region to top.
		 */ /*
		 * Calculate Erase region offset and block address.
		 */ /*
			 * Calculate part offset.
			 */ /*
			 * Increment absolute counters.
			 */ /*
		 * Calculate Erase region offset and block address.
		 */ /*
			 * Calculate part offset.
			 */ /*
			 * Increment absolute counters.
			 */