lib/sw_services/xilflash/src/xilflash_amd.c
int XFlashAmd_Lock(XFlash * InstancePtr, u32 Offset, u32 Bytes)
{
	u8 Mode;
	u8 AddrMul;
	volatile u16 StatusReg;
	u16 Region;
	u16 Block;
	u16 NumAttempt = 0;
	u32 Dummy;
	u32 BaseAddress;
	u32 BlockAddress;
	u32 GroupAddress;
	int Status = (int)XST_FAILURE;
	XFlashGeometry *GeomPtr;
	XFlashVendorData_Amd *DevDataPtr;

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

	DevDataPtr = GET_PARTDATA(InstancePtr);

	GeomPtr = &InstancePtr->Geometry;
	BaseAddress = GeomPtr->BaseAddress;

	Mode = (InstancePtr->Geometry.MemoryLayout &
			XFL_LAYOUT_PART_MODE_MASK) >> 8;

	if (Mode == 2) {
		AddrMul = 1;
	}
	else if (Mode == 1) {
		AddrMul = 2;
	}
	else {
		return (XST_FAILURE);
	}

	/*
	 * Convert the starting address to block coordinates. This also verifies
	 * the starting address is within the instance's address space.
	 */
	Status = XFlashGeometry_ToBlock(GeomPtr, Offset, &Region, &Block,
						&Dummy);
	if (Status != XST_SUCCESS) {
		return (XFLASH_ADDRESS_ERROR);
	}

	/*
	 * Get the physical address to write the command to and send command.
	 */
	(void) XFlashGeometry_ToAbsolute(GeomPtr, Region, Block, 0,
			 &BlockAddress);

	GroupAddress = (BlockAddress | (XFL_AMD_PROT_STATUS_OFFSET * AddrMul));

	 /*
	  * Set-up Phase.
	  */
	DevDataPtr->WriteFlash(BaseAddress,
				GroupAddress, XFL_AMD_CMD_GROUP_PROTECT1);

	Status = XST_FAILURE;
	do {
		/*
		 * Protect Phase.
		 */
		DevDataPtr->WriteFlash(BaseAddress,
				GroupAddress, XFL_AMD_CMD_GROUP_PROTECT1);

		FlashPause(100);

		/*
		 * Verify Phase.
		 */
		DevDataPtr->WriteFlash(BaseAddress,
				GroupAddress, XFL_AMD_CMD_GROUP_PROTECT2);

		FlashPause(4);

		StatusReg = DevDataPtr->GetStatus(InstancePtr->Geometry.
					BaseAddress, GroupAddress);
		/*
		 * Check Protection completed.
		 */
		if(StatusReg == XFL_AMD_GROUP_PROTECTED) {
			Status = XST_SUCCESS;
		        break;
		}
	}
	while(++NumAttempt < 25);

	/*
	 * Reset the bank(s) so that it returns to the read mode.
	 */
	(void) XFlashAmd_ResetBank(InstancePtr, Offset, Bytes);

	return (Status);
}
/*****************************************************************************/
/**
*
* Locks the blocks in the specified range of the AMD flash device.
*
* @param	InstancePtr is the pointer to the XFlash instance.
* @param	Offset is the offset into the device(s) address space from which
*		to begin block locking.
* @param	Bytes indicates the number of bytes to Lock in the Block
*		starting from Offset.
*
* @return
* 		- XST_SUCCESS if successful.
*		- XFLASH_ADDRESS_ERROR if the destination address range is
*		  not completely within the addressable areas of the device(s).
*		- XST_FAILURE if failed.
*
* @note		This API should be called after applying VID (voltage) to the RP
*		pin of flash device. This API is not tested.
*
******************************************************************************/
Locks the blocks in the specified range of the AMD flash device.
Locks the blocks in the specified range of the AMD flash device .
int XFlashAmd_Lock(XFlash * InstancePtr, u32 Offset, u32 Bytes)
{
	u8 Mode;
	u8 AddrMul;
	volatile u16 StatusReg;
	u16 Region;
	u16 Block;
	u16 NumAttempt = 0;
	u32 Dummy;
	u32 BaseAddress;
	u32 BlockAddress;
	u32 GroupAddress;
	int Status = (int)XST_FAILURE;
	XFlashGeometry *GeomPtr;
	XFlashVendorData_Amd *DevDataPtr;
	if(InstancePtr == NULL) {
		return (XST_FAILURE);
	}
	DevDataPtr = GET_PARTDATA(InstancePtr);
	GeomPtr = &InstancePtr->Geometry;
	BaseAddress = GeomPtr->BaseAddress;
	Mode = (InstancePtr->Geometry.MemoryLayout &
			XFL_LAYOUT_PART_MODE_MASK) >> 8;
	if (Mode == 2) {
		AddrMul = 1;
	}
	else if (Mode == 1) {
		AddrMul = 2;
	}
	else {
		return (XST_FAILURE);
	}
	Status = XFlashGeometry_ToBlock(GeomPtr, Offset, &Region, &Block,
						&Dummy);
	if (Status != XST_SUCCESS) {
		return (XFLASH_ADDRESS_ERROR);
	}
	(void) XFlashGeometry_ToAbsolute(GeomPtr, Region, Block, 0,
			 &BlockAddress);
	GroupAddress = (BlockAddress | (XFL_AMD_PROT_STATUS_OFFSET * AddrMul));
	DevDataPtr->WriteFlash(BaseAddress,
				GroupAddress, XFL_AMD_CMD_GROUP_PROTECT1);
	Status = XST_FAILURE;
	do {
		DevDataPtr->WriteFlash(BaseAddress,
				GroupAddress, XFL_AMD_CMD_GROUP_PROTECT1);
		FlashPause(100);
		DevDataPtr->WriteFlash(BaseAddress,
				GroupAddress, XFL_AMD_CMD_GROUP_PROTECT2);
		FlashPause(4);
		StatusReg = DevDataPtr->GetStatus(InstancePtr->Geometry.
					BaseAddress, GroupAddress);
		if(StatusReg == XFL_AMD_GROUP_PROTECTED) {
			Status = XST_SUCCESS;
		        break;
		}
	}
	while(++NumAttempt < 25);
	(void) XFlashAmd_ResetBank(InstancePtr, Offset, Bytes);
	return (Status);
}
int XFlashAmd_Lock ( XFlash * InstancePtr , u32 Offset , u32 Bytes ) { u8 Mode ; u8 AddrMul ; volatile u16 StatusReg ; u16 Region ; u16 Block ; u16 NumAttempt = 0 ; u32 Dummy ; u32 BaseAddress ; u32 BlockAddress ; u32 GroupAddress ; int Status = ( int ) XST_FAILURE ; XFlashGeometry * GeomPtr ; XFlashVendorData_Amd * DevDataPtr ; if ( InstancePtr == NULL ) { return ( XST_FAILURE ) ; } DevDataPtr = GET_PARTDATA ( InstancePtr ) ; GeomPtr = & InstancePtr -> Geometry ; BaseAddress = GeomPtr -> BaseAddress ; Mode = ( InstancePtr -> Geometry . MemoryLayout & XFL_LAYOUT_PART_MODE_MASK ) >> 8 ; if ( Mode == 2 ) { AddrMul = 1 ; } else if ( Mode == 1 ) { AddrMul = 2 ; } else { return ( XST_FAILURE ) ; } Status = XFlashGeometry_ToBlock ( GeomPtr , Offset , & Region , & Block , & Dummy ) ; if ( Status != XST_SUCCESS ) { return ( XFLASH_ADDRESS_ERROR ) ; } ( void ) XFlashGeometry_ToAbsolute ( GeomPtr , Region , Block , 0 , & BlockAddress ) ; GroupAddress = ( BlockAddress | ( XFL_AMD_PROT_STATUS_OFFSET * AddrMul ) ) ; DevDataPtr -> WriteFlash ( BaseAddress , GroupAddress , XFL_AMD_CMD_GROUP_PROTECT1 ) ; Status = XST_FAILURE ; do { DevDataPtr -> WriteFlash ( BaseAddress , GroupAddress , XFL_AMD_CMD_GROUP_PROTECT1 ) ; FlashPause ( 100 ) ; DevDataPtr -> WriteFlash ( BaseAddress , GroupAddress , XFL_AMD_CMD_GROUP_PROTECT2 ) ; FlashPause ( 4 ) ; StatusReg = DevDataPtr -> GetStatus ( InstancePtr -> Geometry . BaseAddress , GroupAddress ) ; if ( StatusReg == XFL_AMD_GROUP_PROTECTED ) { Status = XST_SUCCESS ; break ; } } while ( ++ NumAttempt < 25 ) ; ( void ) XFlashAmd_ResetBank ( InstancePtr , Offset , Bytes ) ; return ( Status ) ; }
Locks the blocks in the specified range of the AMD flash device.
Locks the blocks in the specified range of the AMD flash device .
/*
	 * Verify inputs are valid.
	 */ /*
	 * Convert the starting address to block coordinates. This also verifies
	 * the starting address is within the instance's address space.
	 */ /*
	 * Get the physical address to write the command to and send command.
	 */ /*
	  * Set-up Phase.
	  */ /*
		 * Protect Phase.
		 */ /*
		 * Verify Phase.
		 */ /*
		 * Check Protection completed.
		 */ /*
	 * Reset the bank(s) so that it returns to the read mode.
	 */