xref: /utopia/UTPA2-700.0.x/modules/flash/drv/flash/serial/drvSERFLASH_private.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) 2008-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 #ifndef _DRVSERFLASH_PRIV_H_
95 #define _DRVSERFLASH_PRIV_H_
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// @file drvBDMA.h
99 /// @author MStar Semiconductor Inc.
100 /// @brief Byte DMA control driver
101 ////////////////////////////////////////////////////////////////////////////////
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 // Header Files
105 ////////////////////////////////////////////////////////////////////////////////
106 #ifdef __cplusplus
107 extern "C"
108 {
109 #endif
110 
111 #include "MsTypes.h"
112 #include "drvSERFLASH.h"
113 
114 
115 typedef const SERFLASH_Info* (*IOCTL_SERFLASH_GetInfo)(void);
116 typedef MS_BOOL (*IOCTL_SERFLASH_GetLibVer)(const MSIF_Version**);
117 typedef MS_BOOL (*IOCTL_SERFLASH_GetStatus)(SERFLASH_DrvStatus*);
118 typedef MS_BOOL (*IOCTL_SERFLASH_SetDbgLevel)(MS_U8);
119 typedef MS_BOOL (*IOCTL_SERFLASH_SetWPInfo)(MS_BOOL);
120 typedef void (*IOCTL_SERFLASH_SetMcuCSCallBack)(ms_Mcu_ChipSelect_CB);
121 typedef void (*IOCTL_SERFLASH_SetFlashWPCallBack)(ms_Flash_SetHWWP_CB);
122 typedef MS_BOOL (*IOCTL_SERFLASH_DetectType)(void);
123 typedef MS_BOOL (*IOCTL_SERFLASH_DetectSize)(MS_U32*);
124 typedef MS_BOOL (*IOCTL_SERFLASH_Set2XRead)(MS_BOOL);
125 typedef MS_BOOL (*IOCTL_SERFLASH_SetCKG)(SPI_DrvCKG);
126 typedef void (*IOCTL_SERFLASH_ClkDiv)(SPI_DrvClkDiv);
127 typedef MS_BOOL (*IOCTL_SERFLASH_SetMode)(MS_BOOL);
128 typedef MS_U64 (*IOCTL_SERFLASH_ReadUID)(void);
129 typedef MS_BOOL (*IOCTL_SERFLASH_ChipSelect)(MS_U8);
130 typedef void (*IOCTL_SERFLASH_Init)(void);
131 typedef MS_BOOL (*IOCTL_SERFLASH_ReadID)(MS_U8*, MS_U32);
132 typedef MS_BOOL (*IOCTL_SERFLASH_Read)(MS_U32, MS_U32, MS_U8*);
133 typedef MS_BOOL (*IOCTL_SERFLASH_EraseChip)(void);
134 typedef MS_BOOL (*IOCTL_SERFLASH_AddressToBlock)(MS_U32, MS_U32*);
135 typedef MS_BOOL (*IOCTL_SERFLASH_BlockToAddress)(MS_U32, MS_U32*);
136 typedef MS_BOOL (*IOCTL_SERFLASH_AddressErase)(MS_U32, MS_U32, MS_BOOL);
137 typedef MS_BOOL (*IOCTL_SERFLASH_BlockErase)(MS_U32, MS_U32, MS_BOOL);
138 typedef MS_BOOL (*IOCTL_SERFLASH_SectorErase)(MS_U32, MS_U32);
139 typedef MS_BOOL (*IOCTL_SERFLASH_CheckWriteDone)(void);
140 typedef MS_BOOL (*IOCTL_SERFLASH_Write)(MS_U32, MS_U32, MS_U8*);
141 typedef MS_BOOL (*IOCTL_SERFLASH_DMA)(MS_U32, MS_U32, MS_U32);
142 typedef MS_BOOL (*IOCTL_SERFLASH_WriteProtect)(MS_BOOL);
143 typedef MS_BOOL (*IOCTL_SERFLASH_WriteProtect_Enable_All_Range)(void);
144 typedef MS_BOOL (*IOCTL_SERFLASH_WriteProtect_Disable_All_Range)(void);
145 typedef MS_BOOL (*IOCTL_SERFLASH_WriteProtect_Disable_Range_Set)(MS_U32, MS_U32);
146 typedef MS_BOOL (*IOCTL_SERFLASH_WriteProtect_Area)(MS_BOOL, MS_U8);
147 typedef MS_BOOL (*IOCTL_SERFLASH_ReadStatusRegister)(MS_U8*);
148 typedef MS_BOOL (*IOCTL_SERFLASH_ReadStatusRegister2)(MS_U8*);
149 typedef MS_BOOL (*IOCTL_SERFLASH_WriteStatusRegister)(MS_U16);
150 typedef MS_BOOL (*IOCTL_SERFLASH_CopyHnd)(MS_PHYADDR, MS_PHYADDR, MS_U32, SPIDMA_Dev, MS_U8);
151 typedef void (*IOCTL_SERFLASH_SetGPIO)(MS_BOOL);
152 
153 
154 typedef struct _SERFLASH_RESOURCE_PRIVATE
155 {
156     MS_U32 Dummy;
157 }SERFLASH_RESOURCE_PRIVATE;
158 
159 typedef struct _SERFLASH_INSTANT_PRIVATE
160 {
161     IOCTL_SERFLASH_GetInfo                              fpSERFLASHGetInfo;
162     IOCTL_SERFLASH_GetLibVer                            fpSERFLASHGetLibVer;
163     IOCTL_SERFLASH_GetStatus                            fpSERFLASHGetStatus;
164     IOCTL_SERFLASH_SetDbgLevel                          fpSERFLASHSetDbgLevel;
165     IOCTL_SERFLASH_SetWPInfo                            fpSERFLASHSetWPInfo;
166     IOCTL_SERFLASH_SetMcuCSCallBack                     fpSERFLASHSetMcuCSCallBack;
167     IOCTL_SERFLASH_SetFlashWPCallBack                   fpSERFLASHSetFlashWPCallBack;
168     IOCTL_SERFLASH_DetectType                           fpSERFLASHDetectType;
169     IOCTL_SERFLASH_DetectSize                           fpSERFLASHDetectSize;
170     IOCTL_SERFLASH_Set2XRead                            fpSERFLASHSet2XRead;
171     IOCTL_SERFLASH_SetCKG                               fpSERFLASHSetCKG;
172     IOCTL_SERFLASH_ClkDiv                               fpSERFLASHClkDiv;
173     IOCTL_SERFLASH_SetMode                              fpSERFLASHSetMode;
174     IOCTL_SERFLASH_ReadUID                              fpSERFLASHReadUID;
175     IOCTL_SERFLASH_ChipSelect                           fpSERFLASHChipSelect;
176     IOCTL_SERFLASH_Init                                 fpSERFLASHInit;
177     IOCTL_SERFLASH_ReadID                               fpSERFLASHReadID;
178     IOCTL_SERFLASH_Read                                 fpSERFLASHRead;
179     IOCTL_SERFLASH_EraseChip                            fpSERFLASHEraseChip;
180     IOCTL_SERFLASH_AddressToBlock                       fpSERFLASHAddressToBlock;
181     IOCTL_SERFLASH_BlockToAddress                       fpSERFLASHBlockToAddress;
182     IOCTL_SERFLASH_AddressErase                         fpSERFLASHAddressErase;
183     IOCTL_SERFLASH_BlockErase                           fpSERFLASHBlockErase;
184     IOCTL_SERFLASH_SectorErase                          fpSERFLASHSectorErase;
185     IOCTL_SERFLASH_CheckWriteDone                       fpSERFLASHCheckWriteDone;
186     IOCTL_SERFLASH_Write                                fpSERFLASHWrite;
187     IOCTL_SERFLASH_DMA                                  fpSERFLASHDMA;
188     IOCTL_SERFLASH_WriteProtect                         fpSERFLASHWriteProtect;
189     IOCTL_SERFLASH_WriteProtect_Enable_All_Range        fpSERFLASHWriteProtectEnableAllRange;
190     IOCTL_SERFLASH_WriteProtect_Disable_All_Range       fpSERFLASHWriteProtectDisableAllRange;
191     IOCTL_SERFLASH_WriteProtect_Disable_Range_Set       fpSERFLASHWriteProtectDisableRangeSet;
192     IOCTL_SERFLASH_WriteProtect_Area                    fpSERFLASHWriteProtectArea;
193     IOCTL_SERFLASH_ReadStatusRegister                   fpSERFLASHReadStatusRegister;
194     IOCTL_SERFLASH_ReadStatusRegister2                  fpSERFLASHReadStatusRegister2;
195     IOCTL_SERFLASH_WriteStatusRegister                  fpSERFLASHWriteStatusRegister;
196     IOCTL_SERFLASH_CopyHnd                              fpSERFLASHCopyHnd;
197     IOCTL_SERFLASH_SetGPIO                              fpSERFLASHSetGPIO;
198 }SERFLASH_INSTANT_PRIVATE;
199 
200 void FLASHRegisterToUtopia(FUtopiaOpen ModuleType);
201 MS_U32 FLASHOpen(void** ppInstance, MS_U32 u32ModuleVersion, void* pAttribute);
202 MS_U32 FLASHClose(void* pInstance);
203 MS_U32 FLASHIoctl(void* pInstance, MS_U32 u32Cmd, void* pArgs);
204 #if (SERFLASH_UTOPIA20)
205 //------------------------------------------------------------------------------
206 /// Description : Set detailed level of Parallel Flash driver debug message
207 /// @param u8DbgLevel    \b IN  debug level for Serial Flash driver
208 /// @return TRUE : succeed
209 /// @return FALSE : failed to set the debug level
210 //------------------------------------------------------------------------------
211 MS_BOOL _MDrv_SERFLASH_SetDbgLevel(MS_U8 u8DbgLevel);
212 
213 //------------------------------------------------------------------------------
214 /// Description : Set WP pin info to driver
215 /// @param bWPInfo
216 /// @return TRUE : succeed
217 /// @return FALSE : failed to set the WP pin info
218 //------------------------------------------------------------------------------
219 MS_BOOL _MDrv_SERFLASH_SetWPInfo(MS_BOOL bWPInfo);
220 
221 //------------------------------------------------------------------------------
222 /// Description : HK ask 8051 to select flash chip by call back function
223 /// @param ms_Mcu_ChipSelect_CB    \b IN  call back function
224 /// @return TRUE : succeed
225 /// @return NULL :
226 //------------------------------------------------------------------------------
227 void _MDrv_SERFLASH_SetMcuCSCallBack(ms_Mcu_ChipSelect_CB ChipSel_cb);
228 
229 void _MDrv_SERFLASH_SetFlashWPCallBack(ms_Flash_SetHWWP_CB FlashWP_cb);
230 
231 //-------------------------------------------------------------------------------------------------
232 /// Description : Detect flash type by reading the MID and DID
233 /// @return TRUE : succeed
234 /// @return FALSE : unknown flash type
235 /// @note   Not allowed in interrupt context
236 //-------------------------------------------------------------------------------------------------
237 MS_BOOL _MDrv_SERFLASH_DetectType(void);
238 
239 //-------------------------------------------------------------------------------------------------
240 /// Description : Detect flash Size
241 /// @param  u32FlashSize    \b OUT: u32 ptr to store flash size
242 /// @return TRUE : succeed
243 /// @return FALSE : unknown flash size
244 /// @note   Not allowed in interrupt context
245 //-------------------------------------------------------------------------------------------------
246 MS_BOOL _MDrv_SERFLASH_DetectSize(MS_U32 *u32FlashSize);
247 
248 //-------------------------------------------------------------------------------------------------
249 /// Description : Enable Flash 2XREAD mode, if support
250 /// @param  b2XMode    \b IN: ENABLE/DISABLE
251 /// @return TRUE : succeed
252 /// @return FALSE : not succeed
253 /// @note   Please ref. sprc. to confirm Flash support or not
254 //-------------------------------------------------------------------------------------------------
255 MS_BOOL _MDrv_SERFLASH_Set2XRead(MS_BOOL b2XMode);
256 
257 //-------------------------------------------------------------------------------------------------
258 /// Description : Set ckg_spi which flash supports (please ref. the spec. before using this function)
259 /// @param  SPI_DrvCKG    \b IN: enumerate the ckg_spi
260 /// @return TRUE : succeed
261 /// @return FALSE : not succeed
262 /// @note   Please ref. sprc. to confirm Flash support or not. It is safty to run at 43M (Default).
263 //-------------------------------------------------------------------------------------------------
264 MS_BOOL _MDrv_SERFLASH_SetCKG(SPI_DrvCKG eCKGspi);
265 
266 //-------------------------------------------------------------------------------------------------
267 /// Description : Set clock div such that spi clock = mcu clock /clock_div.
268 /// @param  SPI_DrvClkDiv    \b IN: enumerate the clock_div
269 /// @return TRUE : succeed
270 /// @return FALSE : not succeed
271 /// @note
272 //-------------------------------------------------------------------------------------------------
273 void _MDrv_SERFLASH_ClkDiv(SPI_DrvClkDiv eClkDivspi);
274 
275 //-------------------------------------------------------------------------------------------------
276 /// Description : Set XIU/RIU mode (Default : XIU)
277 /// @param  bXiuRiu    \b IN: 1 for XIU, 0 for RIU
278 /// @return TRUE : succeed
279 /// @return FALSE : not succeed
280 /// @note   XIU mode is faster than RIU mode. It is stable to run by XIU (Default)
281 //-------------------------------------------------------------------------------------------------
282 MS_BOOL _MDrv_SERFLASH_SetMode(MS_BOOL bXiuRiu);
283 
284 //-------------------------------------------------------------------------------------------------
285 /// Description :  Set active flash among multi-spi flashes
286 /// @param  u8FlashIndex    \b IN: The Flash index, 0 for external #1 spi flash, 1 for external #2 spi flash
287 /// @return TRUE : succeed
288 /// @return FALSE : not succeed
289 /// @note   For Secure booting = 0, please check hw_strapping or e-fuse (the board needs to jump)
290 //-------------------------------------------------------------------------------------------------
291 MS_BOOL _MDrv_SERFLASH_ChipSelect(MS_U8 u8FlashIndex);
292 
293 //-------------------------------------------------------------------------------------------------
294 /// Description : Erase all sectors in Serial Flash
295 /// @return TRUE : succeed
296 /// @return FALSE : fail before timeout
297 /// @note   Not allowed in interrupt context
298 /// [NONOS_SUPPORT]
299 //-------------------------------------------------------------------------------------------------
300 MS_BOOL _MDrv_SERFLASH_EraseChip(void);
301 
302 //-------------------------------------------------------------------------------------------------
303 /// Description : Get flash start block index of a flash address
304 /// @param  u32FlashAddr    \b IN: flash address
305 /// @param  pu32BlockIndex    \b IN: poniter to store the returning block index
306 /// @return TRUE : succeed
307 /// @return FALSE : illegal parameters
308 /// @note   Not allowed in interrupt context
309 //-------------------------------------------------------------------------------------------------
310 MS_BOOL _MDrv_SERFLASH_AddressToBlock(MS_U32 u32FlashAddr, MS_U32 *pu32BlockIndex);
311 
312 //-------------------------------------------------------------------------------------------------
313 /// Description : Get flash start address of a block index
314 /// @param  u32BlockIndex    \b IN: block index
315 /// @param  pu32FlashAddr    \b IN: pointer to store the returning flash address
316 /// @return TRUE : succeed
317 /// @return FALSE : illegal parameters
318 /// @note   Not allowed in interrupt context
319 //-------------------------------------------------------------------------------------------------
320 MS_BOOL _MDrv_SERFLASH_BlockToAddress(MS_U32 u32BlockIndex, MS_U32 *pu32FlashAddr);
321 
322 //-------------------------------------------------------------------------------------------------
323 /// Description : Get Unique ID
324 /// @param  None
325 /// @return the SPI Flash's Unique ID
326 //-------------------------------------------------------------------------------------------------
327 MS_U64 _MDrv_SERFLASH_ReadUID(void);
328 
329 //-------------------------------------------------------------------------------------------------
330 /// Description : Erase certain sectors given starting address and size in Serial Flash
331 /// @param  u32StartAddr    \b IN: start address at block boundry
332 /// @param  u32EraseSize    \b IN: size to erase
333 /// @param  bWait    \b IN: wait write done or not
334 /// @return TRUE : succeed
335 /// @return FALSE : fail before timeout or illegal parameters
336 /// @note   Not allowed in interrupt context
337 //-------------------------------------------------------------------------------------------------
338 MS_BOOL _MDrv_SERFLASH_AddressErase(MS_U32 u32StartAddr, MS_U32 u32EraseSize, MS_BOOL bWait);
339 
340 //-------------------------------------------------------------------------------------------------
341 /// Description : Erase certain sectors in Serial Flash
342 /// @param  u32StartBlock    \b IN: start block
343 /// @param  u32EndBlock    \b IN: end block
344 /// @param  bWait    \b IN: wait write done or not
345 /// @return TRUE : succeed
346 /// @return FALSE : fail before timeout or illegal parameters
347 /// @note   Not allowed in interrupt context
348 //-------------------------------------------------------------------------------------------------
349 MS_BOOL _MDrv_SERFLASH_BlockErase(MS_U32 u32StartBlock, MS_U32 u32EndBlock, MS_BOOL bWait);
350 
351 //-------------------------------------------------------------------------------------------------
352 /// Description : Erase certain 4K sectors in Serial Flash
353 /// @param  u32StartBlock    \b IN: start address
354 /// @param  u32EndBlock    \b IN: end address
355 /// @return TRUE : succeed
356 /// @return FALSE : fail before timeout or illegal parameters
357 /// @note   Not allowed in interrupt context
358 //-------------------------------------------------------------------------------------------------
359 MS_BOOL _MDrv_SERFLASH_SectorErase(MS_U32 u32StartAddr, MS_U32 u32EndAddr);
360 
361 //-------------------------------------------------------------------------------------------------
362 /// Description : Check write done in Serial Flash
363 /// @return TRUE : done
364 /// @return FALSE : not done
365 /// @note   Not allowed in interrupt context
366 //-------------------------------------------------------------------------------------------------
367 MS_BOOL _MDrv_SERFLASH_CheckWriteDone(void);
368 
369 //-------------------------------------------------------------------------------------------------
370 /// Description : Write data to Serial Flash
371 /// @param  u32FlashAddr    \b IN: start address (4-B aligned)
372 /// @param  u32FlashSize    \b IN: size in Bytes (4-B aligned)
373 /// @param  user_buffer    \b IN: Virtual Buffer Address ptr to flash write data
374 /// @return TRUE : succeed
375 /// @return FALSE : fail before timeout or illegal parameters
376 /// @note   Not allowed in interrupt context
377 /// [NONOS_SUPPORT]
378 //-------------------------------------------------------------------------------------------------
379 MS_BOOL _MDrv_SERFLASH_Write(MS_U32 u32FlashAddr, MS_U32 u32FlashSize, MS_U8 *user_buffer);
380 
381 //-------------------------------------------------------------------------------------------------
382 /// Description : Read data from Serial Flash
383 /// @param  u32FlashAddr    \b IN: Flash Address
384 /// @param  u32FlashSize    \b IN: Flash Size Data in Bytes
385 /// @param  user_buffer    \b OUT: Virtual Buffer Address ptr to store flash read data
386 /// @return TRUE : succeed
387 /// @return FALSE : fail before timeout or illegal parameters
388 /// @note   Not allowed in interrupt context
389 /// [NONOS_SUPPORT]
390 //-------------------------------------------------------------------------------------------------
391 MS_BOOL _MDrv_SERFLASH_Read(MS_U32 u32FlashAddr, MS_U32 u32FlashSize, MS_U8 *user_buffer);
392 
393 //-------------------------------------------------------------------------------------------------
394 /// Description : Protect blocks in Serial Flash
395 /// @param  bEnable    \b IN: TRUE/FALSE: enable/disable protection
396 /// @return TRUE : succeed
397 /// @return FALSE : fail before timeout
398 /// @note   Not allowed in interrupt context
399 /// @note
400 /// [NONOS_SUPPORT]
401 //-------------------------------------------------------------------------------------------------
402 MS_BOOL _MDrv_SERFLASH_WriteProtect(MS_BOOL bEnable);
403 
404 //-------------------------------------------------------------------------------------------------
405 /// Description : Enables all range of flash write protection
406 /// @return TRUE : succeed
407 /// @return FALSE : fail before timeout
408 /// @note   Not allowed in interrupt context
409 //-------------------------------------------------------------------------------------------------
410 MS_BOOL _MDrv_SERFLASH_WriteProtect_Enable_All_Range(void);
411 
412 //-------------------------------------------------------------------------------------------------
413 /// Description : Disables all range of flash write protection
414 /// @return TRUE : succeed
415 /// @return FALSE : fail before timeout
416 /// @note   Not allowed in interrupt context
417 //-------------------------------------------------------------------------------------------------
418 MS_BOOL _MDrv_SERFLASH_WriteProtect_Disable_All_Range(void);
419 
420 //-------------------------------------------------------------------------------------------------
421 /// Description : Set flash disable lower bound and size
422 /// @param  u32DisableLowerBound    \b IN: the lower bound to disable write protect
423 /// @param  u32DisableSize    \b IN: size to disable write protect
424 /// @return TRUE : succeed
425 /// @return FALSE : fail before timeout or illegal parameters
426 /// @note   Not allowed in interrupt context
427 //-------------------------------------------------------------------------------------------------
428 MS_BOOL _MDrv_SERFLASH_WriteProtect_Disable_Range_Set(MS_U32 u32DisableLowerBound, MS_U32 u32DisableSize);
429 
430 //-------------------------------------------------------------------------------------------------
431 /// Description : Protect blocks in Serial Flash
432 /// @param  bEnableAllArea    \b IN: enable or disable protection
433 /// @param  u8BlockProtectBits    \b IN: block protection bits which stand for the area to enable write protect
434 /// @return TRUE : succeed
435 /// @return FALSE : fail before timeout
436 /// @note   Not allowed in interrupt context
437 //-------------------------------------------------------------------------------------------------
438 MS_BOOL _MDrv_SERFLASH_WriteProtect_Area(MS_BOOL bEnableAllArea, MS_U8 u8BlockProtectBits);
439 
440 //-------------------------------------------------------------------------------------------------
441 /// Description : Read ID from Serial Flash
442 /// @param  pu8FlashID    \b OUT: Virtual data ptr to store the read ID
443 /// @param  u32IDSize    \b IN: size in Bytes
444 /// @return TRUE : succeed
445 /// @return FALSE : fail before timeout
446 /// @note   Not allowed in interrupt context
447 /// @note
448 /// [NONOS_SUPPORT]
449 //-------------------------------------------------------------------------------------------------
450 MS_BOOL _MDrv_SERFLASH_ReadID(MS_U8 *pu8FlashID, MS_U32 u32IDSize);
451 
452 //-------------------------------------------------------------------------------------------------
453 /// Description : Read data from Serial Flash to DRAM in DMA mode
454 /// @param  u32FlashStart    \b IN: src start address in flash (0 ~ flash size-1)
455 /// @param  u32DRAMStart    \b IN: dst start address in DRAM (16B-aligned) (0 ~ DRAM size-1)
456 /// @param  u32Size    \b IN: size in Bytes (8B-aligned) (>=8)
457 /// @return TRUE : succeed
458 /// @return FALSE : fail before timeout or illegal parameters
459 /// @note   Not allowed in interrupt context
460 /// @note
461 /// [NONOS_SUPPORT]
462 //-------------------------------------------------------------------------------------------------
463 MS_BOOL _MDrv_SERFLASH_DMA(MS_U32 u32FlashStart, MS_U32 u32DRAMStart, MS_U32 u32Size);
464 
465 //------- ------------------------------------------------------------------------------------------
466 /// Description : Read Status Register in Serial Flash
467 /// @param  pu8StatusReg    \b OUT: ptr to Status Register value
468 /// @return TRUE : succeed
469 /// @return FALSE : fail before timeout
470 /// @note   Not allowed in interrupt context
471 /// @note
472 /// [NONOS_SUPPORT]
473 //-------------------------------------------------------------------------------------------------
474 MS_BOOL _MDrv_SERFLASH_ReadStatusRegister(MS_U8 *pu8StatusReg);
475 
476 //------- ------------------------------------------------------------------------------------------
477 /// Description : Read Status Register2 in Serial Flash
478 /// @param  pu8StatusReg    \b OUT: ptr to Status Register value
479 /// @return TRUE : succeed
480 /// @return FALSE : fail before timeout
481 /// @note   Not allowed in interrupt context
482 /// @note   For Specific Flash IC with 16-bit status register (high-byte)
483 /// [NONOS_SUPPORT]
484 //-------------------------------------------------------------------------------------------------
485 MS_BOOL _MDrv_SERFLASH_ReadStatusRegister2(MS_U8 *pu8StatusReg);
486 
487 //------- ------------------------------------------------------------------------------------------
488 /// Description : Write Status Register in Serial Flash
489 /// @param  u16StatusReg    \b IN: Status Register value
490 /// @return TRUE : succeed
491 /// @return FALSE : fail before timeout
492 /// @note   Not allowed in interrupt context
493 /// @note   For Specific Flash IC with 16-bit status register
494 /// [NONOS_SUPPORT]
495 //-------------------------------------------------------------------------------------------------
496 MS_BOOL _MDrv_SERFLASH_WriteStatusRegister(MS_U16 u16StatusReg);
497 
498 //------- ------------------------------------------------------------------------------------------
499 /// Description : Handle for BDMA copy data from ONLY Flash src to other dst
500 /// @param u32FlashAddr \b IN: Physical Source address in spi flash
501 /// @param u32DramAddr \b IN: Physical Dst address
502 /// @param u32Len \b IN: data length
503 /// @param eDstDev \b IN: The Dst Device of Flash BDMA
504 /// @param u8OpCfg \b IN: u8OpCfg: default is SPIDMA_OPCFG_DEF
505 /// - Bit0: inverse mode --> SPIDMA_OPCFG_INV_COPY
506 /// - Bit2: Copy & CRC check in wait mode --> SPIDMA_OPCFG_CRC_COPY
507 /// - Bit3: Copy without waiting --> SPIDMA_OPCFG_NOWAIT_COPY
508 /// @return \b MS_BOOL
509 /// [NONOS_SUPPORT]
510 /// [fw : drvBDMA ]
511 //-------------------------------------------------------------------------------------------------
512 MS_BOOL _MDrv_SERFLASH_CopyHnd(MS_PHYADDR u32FlashAddr,
513                                           MS_PHYADDR u32DstAddr,
514                                           MS_U32 u32Len,
515                                           SPIDMA_Dev eDstDev,
516                                           MS_U8 u8OpCfg);
517 
518 //------- ------------------------------------------------------------------------------------------
519 /// Description : Switch SPI as GPIO Input
520 /// @param  bSwitch    \b IN: 1 for GPIO, 0 for NORMAL
521 /// @note   Not allowed in interrupt context
522 /// @note   For project's power consumption
523 /// [NONOS_SUPPORT]
524 //-------------------------------------------------------------------------------------------------
525 void _MDrv_SERFLASH_SetGPIO(MS_BOOL bSwitch);
526 
527 #endif
528 
529 #ifdef __cplusplus
530 }
531 #endif
532 #endif // _DRVBDMA_PRIV_H_
533