blob: de7ee87bd6bba9f0d1d8bef9d425d1ee9a9c5bf2 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// GEU_FuseCommon.c
2//
3/******************************************************************************
4 *
5 * (C)Copyright 2005 - 2011 Marvell. All Rights Reserved.
6 *
7 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL.
8 * The copyright notice above does not evidence any actual or intended
9 * publication of such source code.
10 * This Module contains Proprietary Information of Marvell and should be
11 * treated as Confidential.
12 * The information in this file is provided for the exclusive use of the
13 * licensees of Marvell.
14 * Such users have the right to use, modify, and incorporate this code into
15 * products for purposes authorized by the license agreement provided they
16 * include this notice and the associated copyright notice with any such
17 * product.
18 * The information in this file is provided "AS IS" without warranty.
19
20 ******************************************************************************/
21
22#include <Typedef.h>
23#include <predefines.h>
24#include <geu_interface.h>
25#include <Errors.h>
26#include <timer.h>
27//#include <platform_timer.h>
28
29//#include <GEU.h>
30#include <platform_geu_fuse_internal.h>
31
32//++
33//************************************************************
34// Unit Test Support
35#ifdef _GEU_EM
36#include "em_platform_geu_fuse_internal.h"
37#endif
38//************************************************************
39//--
40
41//static struct GEU_FuseGlobalData *pActiveFuseData;
42extern struct GEU_FuseGlobalData *pActiveFuseData;
43
44/***********************************************************
45* Function:
46* _geuUpdateRegister
47*
48* Description:
49* Does a read/modify/write to update a bitfield within a register.
50*
51* Input:
52* registerAddress - address of register to update
53* NewData - 32 bit value containg new data (properly aligned)
54* to write to the specified register
55* NewDataMask - 32 bit mask specifying which bits are "write enabled".
56*
57* Output:
58* none
59* Returns:
60* void
61*
62*
63************************************************************/
64void _geuWriteRegister(UINT_T registerAddress, UINT_T NewData, UINT_T NewDataMask)
65{
66 UINT_T scratch;
67
68 scratch = (NewData & NewDataMask);
69 GEU_REG_WRITE(registerAddress, scratch);
70 return;
71};
72
73UINT_T _geuReadRegister(UINT_T registerAddress, UINT_T ReadMask)
74{
75 UINT_T scratch;
76
77 GEU_REG_READ(registerAddress, scratch);
78 //scratch = scratch & !NewDataMask;
79 scratch = scratch & ReadMask;
80 return scratch;
81};
82
83void _geuUpdateRegister(UINT_T registerAddress, UINT_T NewData, UINT_T WriteMask)
84{
85 UINT_T scratch;
86 GEU_REG_READ(registerAddress, scratch);
87 scratch = scratch & ~WriteMask; // Keep the portion we're not updating
88 scratch = scratch | (NewData & WriteMask);
89 GEU_REG_WRITE(registerAddress, scratch);
90 return;
91};
92
93/***********************************************************
94* Function:
95* _geuGetPhysicalBitCount
96*
97* Description:
98* Counts the number of bits set in the first NumBits of the 32 bit value n.
99*
100* Input:
101* n - 32 bit value in which to count the bits that are set.
102* NumBits - Size of the bitfield in the low order portion of n in which to count
103* bits that are set.
104*
105* Output:
106* none
107*
108* Returns:
109* Number of Bits set in the specified subfield of n.
110*
111*
112************************************************************/
113UINT_T _geuGetPhysicalBitCount(UINT_T n,UINT_T NumBits)
114{
115 UINT_T i;
116 UINT_T count = 0;
117 for (i=0; i<NumBits;i++)
118 {
119 if ((n & 0x1) == 1){count++;}
120 n = n >> 1;
121 }
122 return(count);
123};
124
125
126/***********************************************************
127* Function:
128* _geuCompare
129*
130* Description:
131* Compares n consecutive bytes longs in the two specified buffers.
132*
133* Input:
134* src1 - 1st buffer.
135* src2 - 2nd buffer
136* size - number of bytes to compare.
137*
138* Output:
139* none
140*
141* Returns:
142* NoError
143* FUSE_FuseBlockCompareFailed
144*
145************************************************************/
146UINT_T _geu_compare(UINT_T * src1, UINT_T * src2, UINT_T size)
147{
148 UINT_T status;
149 UINT_T i;
150 UINT8_T * bpsrc1, * bpsrc2; //Byte pointers to buffers
151
152 status = NoError;
153 bpsrc1 = (UINT8_T *)src1;
154 bpsrc2 = (UINT8_T *)src2;
155 for (i=0; i<size; i++)
156 {
157 if (bpsrc1[i] != bpsrc2[i])
158 {
159 status = FUSE_FuseBlockCompareFailed ;
160 break;
161 }
162 }//End For
163 return status;
164}//End Routine _geu_compare
165
166/***********************************************************
167* Function:
168* _geuSetStatus
169*
170* Description:
171* Sets the bits specified by BitMask at the address specified.
172*
173* Input:
174* ptr - address at which to set the specified bit
175* BitMask - Bits to set at the specified address
176* Output:
177* none
178*
179* Returns:
180* NoError
181*
182************************************************************/
183void _geu_SetStatus(UINT_T *ptr, UINT_T BitMask)
184{
185 *ptr = *ptr |BitMask;
186 return;
187}//End Routine _geu_SetStatus
188
189/***********************************************************
190* Function:
191* _geuWaitForFuseOperationComplete
192*
193* Description:
194* Waits for the specified bit to be set or Times out
195*
196* Input:
197* ptr - address at which to set the specified bit
198* BitMask - Bits to set at the specified address
199* Output:
200* none
201*
202* Returns:
203* NoError
204*
205************************************************************///----------------------------------------------------------------------------
206// _WaitForProtectionOperationComplete
207// Replaces method susceptible to "infinite loop"
208//
209//
210//----------------------------------------------------------------------------
211
212UINT_T _geuWaitForFuseOperationComplete( unsigned int statusMask, UINT32 TimeOutMillisec )
213{
214 UINT32 startTime, endTime;
215 UINT32 geu_fuse_status;
216
217 startTime = GetOSCR0();
218 do
219 {
220 GEU_REG_READ(GEU_FUSE_STATUS, geu_fuse_status);
221 if( (statusMask & geu_fuse_status) == 0 )
222 break;
223 endTime = GetOSCR0();
224 }
225 while( OSCR0IntervalInMicro(startTime, endTime) < 50 );
226
227 startTime = GetOSCR0();
228 do
229 {
230 GEU_REG_READ(GEU_FUSE_STATUS, geu_fuse_status);
231 if(statusMask & geu_fuse_status)
232 return 0;
233 endTime = GetOSCR0();
234 }
235 while( OSCR0IntervalInMilli(startTime, endTime) < TimeOutMillisec );
236
237 return 1; // TimeOut return - Caller expecting non-zero for timeout.
238}
239
240