xref: /utopia/UTPA2-700.0.x/mxlib/include/drvPARFLASH.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// @file   drvPARFLASH.h
98 /// @brief  Parallel Flash Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 #ifndef _DRV_PARFLASH_H_
103 #define _DRV_PARFLASH_H_
104 
105 #include "MsCommon.h"
106 
107 #ifdef __cplusplus
108 extern "C"
109 {
110 #endif
111 
112 
113 //-------------------------------------------------------------------------------------------------
114 //  Driver Capability
115 //-------------------------------------------------------------------------------------------------
116 
117 //-------------------------------------------------------------------------------------------------
118 //  Macro and Define
119 //-------------------------------------------------------------------------------------------------
120 #define MSIF_NORF_TAG                          {'M','S','I','F'}    //Version ID header
121 #define MSIF_NORF_CLASS                        {'1','0'}            //info Class code
122 #define MSIF_NORF_CUS                          0x6666               //Customer ID
123 #define MSIF_NORF_MOD                          0x0001               //Module ID
124 #define MSIF_NORF_CHIP                         0x000F               //CHIP ID: T3
125 #define MSIF_NORF_CPU                          '1'                  //CPU
126 #define MSIF_NORF_LIB_CODE                     {'N','O','R','F'}    //Lib code
127 #define MSIF_NORF_LIBVER                       {'0','1'}            //LIB version
128 #define MSIF_NORF_BUILDNUM                     {'0','1'}            //Build Number
129 #define MSIF_NORF_CHANGELIST                   {'0','0','1','1','4','5','3','4'} //P4 ChangeList Number
130 #define MSIF_NORF_OS                           '0'                  //OS
131 
132 #define          NORF_DRV_VERSION                  /* Character String for DRV/API version             */  \
133             MSIF_NORF_TAG,                         /* 'MSIF'                                           */  \
134             MSIF_NORF_CLASS,                       /* '00'                                             */  \
135             MSIF_NORF_CUS,                         /* 0x0000                                           */  \
136             MSIF_NORF_MOD,                         /* 0x0000                                           */  \
137             MSIF_NORF_CHIP,                                                                              \
138             MSIF_NORF_CPU,                                                                               \
139             MSIF_NORF_LIB_CODE,                    /* IP__                                             */  \
140             MSIF_NORF_LIBVER,                      /* 0.0 ~ Z.Z                                        */  \
141             MSIF_NORF_BUILDNUM,                    /* 00 ~ 99                                          */  \
142             MSIF_NORF_CHANGELIST,                  /* CL#                                              */  \
143             MSIF_NORF_OS
144 
145 //-------------------------------------------------------------------------------------------------
146 //  Type and Structure
147 //-------------------------------------------------------------------------------------------------
148 
149 //flash support list, should sync to flash content table
150 typedef enum
151 {
152     enPF_MX29LV400CT = 0,
153     enPF_MX29LV400CB,
154     enPF_MX29LV800CT,
155     enPF_MX29LV800CB,
156     enPF_MX29LV160CT,
157     enPF_MX29LV160CB,
158     enPF_MX29LV640BT,
159     enPF_MX29LV640BB,
160     enPF_MX29GL256EH,
161     enPF_MX29GA128EH,
162     enPF_MX29GA128EL,
163     enPF_MX29GA256EH,
164     enPF_MX29GA256EL,
165 
166     enPF_SPAN_S29GL128P,
167     enPF_SPAN_S29GL256P,
168     enPF_SPAN_S29GL512P,
169     enPF_SPAN_S29GL01GP,
170 
171     enPF_SPAN_S29GL128P_S,
172     enPF_SPAN_S29GL256P_S,
173     enPF_SPAN_S29GL512P_S,
174 
175     evPF_NUM,
176 }PARFLASH_Device;
177 
178 typedef struct
179 {
180     MS_BOOL bTopBoot;
181     MS_BOOL bUniformSecTbl;
182     MS_U16 u16SecNum;   //sector num
183     MS_U32 u32TotBytes; //flash size
184     MS_U8* pu8SecTbl;   //Un-uniform sector table. if uniform sector table, pu8SecTbl = 0.
185 }PARFLASH_Content;
186 
187 /// Parallel Flash information structure
188 typedef struct
189 {
190     PARFLASH_Device enDevice;
191     MS_BOOL bbytemode;
192     MS_U16 u16SecNum;
193     MS_U32 u32TotBytes;
194 }PARFLASH_Info;
195 
196 typedef struct
197 {
198     MS_BOOL bIsBusy;
199 }PARFLASH_DevSts;
200 
201 //-------------------------------------------------------------------------------------------------
202 //  Function and Variable
203 //-------------------------------------------------------------------------------------------------
204 
205 
206 //-------------------------------------------------------------------------------------------------
207 /// Get the information of Parallel Flash
208 /// @return the pointer to the driver information
209 //-------------------------------------------------------------------------------------------------
210 const PARFLASH_Info *MDrv_PARFLASH_GetInfo(void);
211 
212 //------------------------------------------------------------------------------
213 /// Description: Show the NORF driver version
214 /// @param  ppVersion \b OUT: output NORF driver version
215 /// @return TRUE : succeed
216 /// @return FALSE : failed
217 //------------------------------------------------------------------------------
218 MS_BOOL MDrv_PARFLASH_GetLibVer(const MSIF_Version **ppVersion);
219 
220 //------------------------------------------------------------------------------
221 /// Get Parallel Flash driver status
222 /// @param  pDrvStatus \b OUT: poniter to store the returning driver status
223 /// @return TRUE : succeed
224 /// @return FALSE : failed to get the driver status
225 //------------------------------------------------------------------------------
226 MS_BOOL MDrv_PARFLASH_GetStatus(PARFLASH_DevSts* pDrvStatus);
227 
228 //------------------------------------------------------------------------------
229 /// Set detailed level of Parallel Flash driver debug message
230 /// @param u8DbgLevel  \b IN  debug level for Parallel Flash driver
231 /// @return TRUE : succeed
232 /// @return FALSE : failed to set the debug level
233 //------------------------------------------------------------------------------
234 MS_BOOL MDrv_PARFLASH_SetDbgLevel(MS_U8 u8DbgLevel);
235 
236 //-------------------------------------------------------------------------------------------------
237 /// Initialize Parallel Flash
238 /// @return None
239 /// @note   called only once at system initialization
240 //-------------------------------------------------------------------------------------------------
241 void MDrv_PARFLASH_Init(void) ;
242 
243 //-------------------------------------------------------------------------------------------------
244 /// Select chip
245 /// @param  u8cs    \b IN: Flash index. value: 0~1
246 /// @return FALSE : fail before timeout or illegal parameters
247 //-------------------------------------------------------------------------------------------------
248 MS_BOOL MDrv_PARFLASH_ChipSelect(MS_U8 u8cs);
249 
250 //-------------------------------------------------------------------------------------------------
251 /// Reset Parallel Flash
252 /// @return TRUE : succeed
253 /// @return FALSE : fail before timeout or illegal parameters
254 //-------------------------------------------------------------------------------------------------
255 MS_BOOL MDrv_PARFLASH_Reset(void);
256 
257 //-------------------------------------------------------------------------------------------------
258 /// Read ID in Parallel Flash
259 /// @param  pu16Data    \b IN: ID data, max length is 4 words
260 /// @param  pu8r_len    \b IN: ID data count
261 /// @return TRUE : succeed
262 /// @return FALSE : fail before timeout or illegal parameters
263 /// @note   Not allowed in interrupt context
264 //-------------------------------------------------------------------------------------------------
265 MS_BOOL MDrv_PARFLASH_ReadID(MS_U16 *pu16Data, MS_U8 *pu8r_len);
266 
267 //-------------------------------------------------------------------------------------------------
268 /// Read Sector protect condition
269 /// @param  u16sec      \b IN: Sector index
270 /// @param  pbProtect    \b Out: BOOL point to store protect condition.
271 /// @return TRUE : succeed
272 /// @return FALSE : fail before timeout or illegal parameters
273 /// @note   Not allowed in interrupt context
274 //-------------------------------------------------------------------------------------------------
275 MS_BOOL MDrv_PARFLASH_SectorProtectVerify(MS_U16 u16sec, MS_BOOL* pbProtect);
276 
277 //-------------------------------------------------------------------------------------------------
278 /// Read Sector protect condition
279 /// @param  u8addr      \b IN: CFI read address
280 /// @param  pu16data    \b IN: pointer to store CFI read data
281 /// @return TRUE : succeed
282 /// @return FALSE : fail before timeout or illegal parameters
283 /// @note   Not allowed in interrupt context
284 //-------------------------------------------------------------------------------------------------
285 MS_BOOL MDrv_PARFLASH_CFI_Read(MS_U8 u8addr, MS_U16* pu16data);
286 
287 //-------------------------------------------------------------------------------------------------
288 /// Read data from Parallel Flash
289 /// @param  u32Addr \b IN: start address (4-B aligned)
290 /// @param  pu8Data \b OUT: data ptr to store the read data
291 /// @param  u32Size \b IN: size in Bytes (4-B aligned)
292 /// @return TRUE : succeed
293 /// @return FALSE : fail before timeout or illegal parameters
294 /// @note   Not allowed in interrupt context
295 //-------------------------------------------------------------------------------------------------
296 MS_BOOL MDrv_PARFLASH_Read(MS_U32 u32Addr, MS_U8 *pu8Data, MS_U32 u32Size);
297 
298 //-------------------------------------------------------------------------------------------------
299 /// Erase all sectors in Parallel Flash
300 /// @return TRUE : succeed
301 /// @return FALSE : fail before timeout
302 /// @note   Not allowed in interrupt context
303 //-------------------------------------------------------------------------------------------------
304 MS_BOOL MDrv_PARFLASH_EraseChip(void);
305 
306 //-------------------------------------------------------------------------------------------------
307 /// Erase certain sectors in Parallel Flash
308 /// @param  u16StartSec    \b IN: start sector
309 /// @param  u16EndSec      \b IN: end sector
310 /// @return TRUE : succeed
311 /// @return FALSE : fail before timeout or illegal parameters
312 /// @note   Not allowed in interrupt context
313 //-------------------------------------------------------------------------------------------------
314 MS_BOOL MDrv_PARFLASH_EraseSec(MS_U16 u16StartSec, MS_U16 u16EndSec);
315 
316 //-------------------------------------------------------------------------------------------------
317 /// Write data to Parallel Flash
318 /// @param  u32Addr \b IN: start address (4-B aligned)
319 /// @param  pu8Data \b IN: data to be written
320 /// @param  u32Size \b IN: size in Bytes (4-B aligned)
321 /// @return TRUE : succeed
322 /// @return FALSE : fail before timeout or illegal parameters
323 /// @note   Not allowed in interrupt context
324 //-------------------------------------------------------------------------------------------------
325 MS_BOOL MDrv_PARFLASH_Write(MS_U32 u32Addr, MS_U8 *pu8Data, MS_U32 u32Size);
326 
327 //-------------------------------------------------------------------------------------------------
328 /// Write write commend directly
329 /// @param  u8cycles   \b IN: Bus cycles of commend. Maximun value is 8.
330 /// @param  pu32Addrs  \b IN: Commend Address array to be written.
331 /// @param  pu16Data   \b IN: Commend Data array to be written.
332 /// @return TRUE : succeed
333 /// @return FALSE : fail before timeout or illegal parameters
334 /// @note   Not allowed in interrupt context
335 //-------------------------------------------------------------------------------------------------
336 MS_BOOL MDrv_PARFLASH_WriteCmdCycle(MS_U8 u8cycles, MS_U32 *pu32Addrs, MS_U16 *pu16Data);
337 
338 //-------------------------------------------------------------------------------------------------
339 /// Getting Sector Offset address in byte unit
340 /// @param  u16sector   \b IN: Sector index
341 /// @return unsinged long value: Offset address
342 //-------------------------------------------------------------------------------------------------
343 MS_U32 MDrv_PARFLASH_GetSectorOffset(MS_U16 u16sector);
344 
345 //-------------------------------------------------------------------------------------------------
346 /// Getting Sector size in byte unit
347 /// @param  u16startsec   \b IN: Start Sector index
348 /// @param  u16endsec     \b IN: End Sector index
349 /// @return unsinged long value: sector size
350 //-------------------------------------------------------------------------------------------------
351 MS_U32 MDrv_PARFLASH_GetSectorSize(MS_U16 u16startsec, MS_U16 u16endsec);
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 
357 #endif // _DRV_PARFLASH_H_
358