blob: de7ee87bd6bba9f0d1d8bef9d425d1ee9a9c5bf2 [file] [log] [blame]
// GEU_FuseCommon.c
//
/******************************************************************************
*
* (C)Copyright 2005 - 2011 Marvell. All Rights Reserved.
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL.
* The copyright notice above does not evidence any actual or intended
* publication of such source code.
* This Module contains Proprietary Information of Marvell and should be
* treated as Confidential.
* The information in this file is provided for the exclusive use of the
* licensees of Marvell.
* Such users have the right to use, modify, and incorporate this code into
* products for purposes authorized by the license agreement provided they
* include this notice and the associated copyright notice with any such
* product.
* The information in this file is provided "AS IS" without warranty.
******************************************************************************/
#include <Typedef.h>
#include <predefines.h>
#include <geu_interface.h>
#include <Errors.h>
#include <timer.h>
//#include <platform_timer.h>
//#include <GEU.h>
#include <platform_geu_fuse_internal.h>
//++
//************************************************************
// Unit Test Support
#ifdef _GEU_EM
#include "em_platform_geu_fuse_internal.h"
#endif
//************************************************************
//--
//static struct GEU_FuseGlobalData *pActiveFuseData;
extern struct GEU_FuseGlobalData *pActiveFuseData;
/***********************************************************
* Function:
* _geuUpdateRegister
*
* Description:
* Does a read/modify/write to update a bitfield within a register.
*
* Input:
* registerAddress - address of register to update
* NewData - 32 bit value containg new data (properly aligned)
* to write to the specified register
* NewDataMask - 32 bit mask specifying which bits are "write enabled".
*
* Output:
* none
* Returns:
* void
*
*
************************************************************/
void _geuWriteRegister(UINT_T registerAddress, UINT_T NewData, UINT_T NewDataMask)
{
UINT_T scratch;
scratch = (NewData & NewDataMask);
GEU_REG_WRITE(registerAddress, scratch);
return;
};
UINT_T _geuReadRegister(UINT_T registerAddress, UINT_T ReadMask)
{
UINT_T scratch;
GEU_REG_READ(registerAddress, scratch);
//scratch = scratch & !NewDataMask;
scratch = scratch & ReadMask;
return scratch;
};
void _geuUpdateRegister(UINT_T registerAddress, UINT_T NewData, UINT_T WriteMask)
{
UINT_T scratch;
GEU_REG_READ(registerAddress, scratch);
scratch = scratch & ~WriteMask; // Keep the portion we're not updating
scratch = scratch | (NewData & WriteMask);
GEU_REG_WRITE(registerAddress, scratch);
return;
};
/***********************************************************
* Function:
* _geuGetPhysicalBitCount
*
* Description:
* Counts the number of bits set in the first NumBits of the 32 bit value n.
*
* Input:
* n - 32 bit value in which to count the bits that are set.
* NumBits - Size of the bitfield in the low order portion of n in which to count
* bits that are set.
*
* Output:
* none
*
* Returns:
* Number of Bits set in the specified subfield of n.
*
*
************************************************************/
UINT_T _geuGetPhysicalBitCount(UINT_T n,UINT_T NumBits)
{
UINT_T i;
UINT_T count = 0;
for (i=0; i<NumBits;i++)
{
if ((n & 0x1) == 1){count++;}
n = n >> 1;
}
return(count);
};
/***********************************************************
* Function:
* _geuCompare
*
* Description:
* Compares n consecutive bytes longs in the two specified buffers.
*
* Input:
* src1 - 1st buffer.
* src2 - 2nd buffer
* size - number of bytes to compare.
*
* Output:
* none
*
* Returns:
* NoError
* FUSE_FuseBlockCompareFailed
*
************************************************************/
UINT_T _geu_compare(UINT_T * src1, UINT_T * src2, UINT_T size)
{
UINT_T status;
UINT_T i;
UINT8_T * bpsrc1, * bpsrc2; //Byte pointers to buffers
status = NoError;
bpsrc1 = (UINT8_T *)src1;
bpsrc2 = (UINT8_T *)src2;
for (i=0; i<size; i++)
{
if (bpsrc1[i] != bpsrc2[i])
{
status = FUSE_FuseBlockCompareFailed ;
break;
}
}//End For
return status;
}//End Routine _geu_compare
/***********************************************************
* Function:
* _geuSetStatus
*
* Description:
* Sets the bits specified by BitMask at the address specified.
*
* Input:
* ptr - address at which to set the specified bit
* BitMask - Bits to set at the specified address
* Output:
* none
*
* Returns:
* NoError
*
************************************************************/
void _geu_SetStatus(UINT_T *ptr, UINT_T BitMask)
{
*ptr = *ptr |BitMask;
return;
}//End Routine _geu_SetStatus
/***********************************************************
* Function:
* _geuWaitForFuseOperationComplete
*
* Description:
* Waits for the specified bit to be set or Times out
*
* Input:
* ptr - address at which to set the specified bit
* BitMask - Bits to set at the specified address
* Output:
* none
*
* Returns:
* NoError
*
************************************************************///----------------------------------------------------------------------------
// _WaitForProtectionOperationComplete
// Replaces method susceptible to "infinite loop"
//
//
//----------------------------------------------------------------------------
UINT_T _geuWaitForFuseOperationComplete( unsigned int statusMask, UINT32 TimeOutMillisec )
{
UINT32 startTime, endTime;
UINT32 geu_fuse_status;
startTime = GetOSCR0();
do
{
GEU_REG_READ(GEU_FUSE_STATUS, geu_fuse_status);
if( (statusMask & geu_fuse_status) == 0 )
break;
endTime = GetOSCR0();
}
while( OSCR0IntervalInMicro(startTime, endTime) < 50 );
startTime = GetOSCR0();
do
{
GEU_REG_READ(GEU_FUSE_STATUS, geu_fuse_status);
if(statusMask & geu_fuse_status)
return 0;
endTime = GetOSCR0();
}
while( OSCR0IntervalInMilli(startTime, endTime) < TimeOutMillisec );
return 1; // TimeOut return - Caller expecting non-zero for timeout.
}