xref: /utopia/UTPA2-700.0.x/mxlib/include/drvSERFLASH.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 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// @file   drvSERFLASH.h
98 /// @brief  Serial Flash Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 /*! \defgroup G_SERFLASH SERFLASH interface
103    *  \ingroup  G_PERIPHERAL
104 
105      \brief
106 
107      Flash Self Programming controlleris designed to for easy read/write external Serial Peripheral interface (SPI) flash.
108 
109      <b>Features</b>
110 
111      - Read ID Sequence
112      - Read SPI Status Sequence
113      - Write SPI Status Sequence
114      - Chip Erase Sequence
115      - Sector/Block Erase Sequence
116      - Page Program Sequence
117      - Read Data Sequence
118 
119     <b>SPI Diagram</b> \n
120      \image html drvSERFLASH_pic.png
121 
122      *! \defgroup G_SERFLASH_INIT Initialization Task relative
123      *  \ingroup  G_SERFLASH
124      \defgroup G_SERFLASH_COMMON Common Task relative
125      \ingroup  G_SERFLASH
126      \defgroup G_SERFLASH_CONTROL Control relative
127      \ingroup  G_SERFLASH
128      \defgroup G_SERFLASH_FSP FSP relative
129      \ingroup  G_SERFLASH
130      *! \defgroup G_SERFLASH_OTHER  other relative
131      *  \ingroup  G_SERFLASH
132      *! \defgroup G_SERFLASH_ToBeModified SERFLASH api to be modified
133      *  \ingroup  G_SERFLASH
134      \defgroup G_SERFLASH_ToBeRemove SERFLASH api to be removed
135      \ingroup  G_SERFLASH
136 */
137 
138 #ifndef _DRV_SERFLASH_H_
139 #define _DRV_SERFLASH_H_
140 
141 #include "MsCommon.h"
142 
143 #ifdef __cplusplus
144 extern "C"
145 {
146 #endif
147 
148 //-------------------------------------------------------------------------------------------------
149 //  Driver Capability
150 //-------------------------------------------------------------------------------------------------
151 
152 //-------------------------------------------------------------------------------------------------
153 //  Macro and Define
154 //-------------------------------------------------------------------------------------------------
155 #define SERFLASH_UTOPIA20                  (0)
156 #define MSIF_SPIF_LIB_CODE                     {'S','P','I','F'}    //Lib code
157 #define MSIF_SPIF_LIBVER                       	{'0','6'}            //LIB version
158 #define MSIF_SPIF_BUILDNUM                      {'0','1'}            //Build Number
159 #define MSIF_SPIF_CHANGELIST                    {'0','0','4','5','6','1','5','8'} //P4 ChangeList Number
160 
161 #define      SPIF_DRV_VERSION                  /* Character String for DRV/API version             */  \
162         MSIF_TAG,                         /* 'MSIF'                                           */  \
163         MSIF_CLASS,                       /* '00'                                             */  \
164         MSIF_CUS,                         /* 0x0000                                           */  \
165         MSIF_MOD,                         /* 0x0000                                           */  \
166         MSIF_CHIP,                                                                              \
167         MSIF_CPU,                                                                               \
168         MSIF_SPIF_LIB_CODE,                    /* IP__                                             */  \
169         MSIF_SPIF_LIBVER,                      /* 0.0 ~ Z.Z                                        */  \
170         MSIF_SPIF_BUILDNUM,                    /* 00 ~ 99                                          */  \
171         MSIF_SPIF_CHANGELIST,                  /* CL#                                              */  \
172         MSIF_OS
173 
174 /// Operation cfg
175 #define SPIDMA_CFG_ADDR_DIR_BIT   (0)
176 #define SPIDMA_CFG_REFLECT_BIT    (1)
177 #define SPIDMA_CFG_CRCCOPY_BIT    (2)
178 #define SPIDMA_CFG_NOWAITCOPY_BIT (3)
179 
180 #define SPIDMA_OPCFG_DEF          (0)
181 #define SPIDMA_OPCFG_INV_COPY     _LShift(1, SPIDMA_CFG_ADDR_DIR_BIT)
182 #define SPIDMA_OPCFG_CRC_REFLECT  _LShift(1, SPIDMA_CFG_REFLECT_BIT)    //bit reflection of each input byte
183 #define SPIDMA_OPCFG_CRC_COPY     _LShift(1, SPIDMA_CFG_CRCCOPY_BIT)    //copy then crc check
184 #define SPIDMA_OPCFG_NOWAIT_COPY  _LShift(1, SPIDMA_CFG_NOWAITCOPY_BIT) //copy then quit
185 //-------------------------------------------------------------------------------------------------
186 //  Type and Structure
187 //-------------------------------------------------------------------------------------------------
188 /// Serial Flash information structure
189 typedef struct
190 {
191     MS_U32 u32AccessWidth;      //data access width in bytes
192     MS_U32 u32TotalSize;        //total size in bytes
193     MS_U32 u32SecNum;           //number of sectors
194     MS_U32 u32SecSize;          //sector size in bytes
195 } SERFLASH_Info;
196 
197 typedef struct
198 {
199     MS_BOOL bIsBusy;
200 } SERFLASH_DrvStatus;
201 
202 typedef enum
203 {
204     E_SERFLASH_DBGLV_NONE,    //disable all the debug message
205     E_SERFLASH_DBGLV_INFO,    //information
206     E_SERFLASH_DBGLV_NOTICE,  //normal but significant condition
207     E_SERFLASH_DBGLV_WARNING, //warning conditions
208     E_SERFLASH_DBGLV_ERR,     //error conditions
209     E_SERFLASH_DBGLV_CRIT,    //critical conditions
210     E_SERFLASH_DBGLV_ALERT,   //action must be taken immediately
211     E_SERFLASH_DBGLV_EMERG,   //system is unusable
212     E_SERFLASH_DBGLV_DEBUG,   //debug-level messages
213 } SERFLASH_DbgLv;
214 
215 typedef enum _SPIDMA_Dev
216 {
217      E_SPIDMA_DEV_MIU0
218     ,E_SPIDMA_DEV_MIU1
219     ,E_SPIDMA_DEV_DMDMCU = 6
220     ,E_SPIDMA_DEV_VDMCU
221     ,E_SPIDMA_DEV_DSP
222     ,E_SPIDMA_DEV_TSP
223     ,E_SPIDMA_DEV_1KSRAM_HK51
224     ,E_SPIDMA_DEV_MIU2
225     ,E_SPIDMA_DEV_MIU3
226     ,E_SPIDMA_DEV_NOT_SUPPORT
227 }SPIDMA_Dev;
228 
229 typedef enum _SPI_DrvCKG
230 {
231      E_SPI_XTALI = 0
232     ,E_SPI_27M
233     ,E_SPI_36M
234     ,E_SPI_43M
235     ,E_SPI_54M
236     ,E_SPI_72M
237     ,E_SPI_86M
238     ,E_SPI_108M
239     ,E_SPI_24M = 15 // T3 only
240     ,E_SPI_HALCKG_NOT_SUPPORT
241 }SPI_DrvCKG;
242 
243 typedef enum _SPI_DrvClkDiv
244 {
245      E_SPI_DIV2
246     ,E_SPI_DIV4
247     ,E_SPI_DIV8
248     ,E_SPI_DIV16
249     ,E_SPI_DIV32
250     ,E_SPI_DIV64
251     ,E_SPI_DIV128
252     ,E_SPI_ClkDiv_NOT_SUPPORT
253 }SPI_DrvClkDiv;
254 
255 typedef enum _SERFLASH_RegionMapType
256 {
257     E_SERFLASH_REGION_BLOCK_PROTECTION
258    ,E_SERFLASH_REGION_INDIVIDUAL_BLOCK_LOCK
259    ,E_SERFLASH_REGION_ONE_TIME_PROGRAM
260    ,E_SERFLASH_REGION_SPECIAL_REGION
261 }SERFLASH_RegionMapType;
262 
263 typedef struct
264 {
265    MS_U32  u32OtpLowerRecord;
266    MS_U32  u32OtpUpperRecord;
267    MS_U8    u8OtpBuffer[1024];
268    void         *pstNext;
269 }ST_OTP_Record;
270 
271 
272 typedef struct
273 {
274     MS_BOOL bProtectMark;
275     MS_U32   u32Indicator;
276     MS_U32   u32LowerBound;
277     MS_U32   u32UpperBound;
278     //ST_OTP_Record   StrOptRecord[3];
279     void        *pstNext;
280 }SERFLASH_ProtecLayoutInfo;
281 
282 typedef struct
283 {
284    MS_U32 u32Start;
285    MS_U32 u32Len;
286    MS_U8 *u8data;
287 } SERFLASH_AccessInfo;
288 
289 typedef struct
290 {
291    MS_U32 u32StartAddr;
292    MS_U32 u32EraseSize;
293    MS_BOOL bWait;
294 } SERFLASH_EraseInfo;
295 
296 typedef struct
297 {
298    MS_U32 u32StartAddr;
299    MS_U32 u32Endaddr;
300 } SERFLASH_SectorEraseInfo;
301 
302 
303 typedef struct
304 {
305   MS_U32 u32DisableLowerBound;
306   MS_U32 u32DisableSize;
307 } SERFLASH_DisRangeInfo;
308 
309 typedef enum _SPI_Attribute
310 {
311      E_SPI_ATTRI_USER_DRV
312     ,E_SPI_ATTRI_KERNEL_DRV
313     ,E_SPI_ATTRI_UNKNOWN
314 }SPI_Attribute;
315 
316 ///SPI CS callback
317 typedef void (*ms_Mcu_ChipSelect_CB)(void);
318 typedef void (*ms_Flash_SetHWWP_CB)(MS_BOOL);
319 ////////////////////////////////////////////////////////////////////////////////
320 // include utopia v2  header files here
321 ////////////////////////////////////////////////////////////////////////////////
322 #include "drvSERFLASH_v2.h"
323 
324 //-------------------------------------------------------------------------------------------------
325 //  Function and Variable
326 //-------------------------------------------------------------------------------------------------
327 
328 //-------------------------------------------------------------------------------------------------
329 /// Description : Get the information of Serial Flash
330 /// @ingroup G_SERFLASH_COMMON
331 /// @return the pointer to the driver information
332 //-------------------------------------------------------------------------------------------------
333 const SERFLASH_Info *MDrv_SERFLASH_GetInfo(void);
334 
335 //------------------------------------------------------------------------------
336 /// Description : Show the SERFLASH driver version
337 /// @ingroup G_SERFLASH_COMMON
338 /// @param  ppVersion    \b OUT: output NORF driver version
339 /// @return TRUE : succeed
340 /// @return FALSE : failed
341 //------------------------------------------------------------------------------
342 MS_BOOL MDrv_SERFLASH_GetLibVer(const MSIF_Version **ppVersion);
343 
344 //------------------------------------------------------------------------------
345 /// Description : Get Serial Flash driver status
346 /// @ingroup G_SERFLASH_COMMON
347 /// @param  pDrvStatus    \b OUT: poniter to store the returning driver status
348 /// @return TRUE : succeed
349 /// @return FALSE : failed to get the driver status
350 //------------------------------------------------------------------------------
351 MS_BOOL MDrv_SERFLASH_GetStatus(SERFLASH_DrvStatus* pDrvStatus);
352 
353 //------------------------------------------------------------------------------
354 /// Description : Set detailed level of Parallel Flash driver debug message
355 /// @ingroup G_SERFLASH_COMMON
356 /// @param u8DbgLevel    \b IN  debug level for Serial Flash driver
357 /// @return TRUE : succeed
358 /// @return FALSE : failed to set the debug level
359 //------------------------------------------------------------------------------
360 MS_BOOL MDrv_SERFLASH_SetDbgLevel(MS_U8 u8DbgLevel);
361 //------------------------------------------------------------------------------
362 /// Description : Set detailed level of Parallel Flash driver debug message
363 /// @ingroup G_SERFLASH_CONTROL
364 /// @param u8DbgLevel    \b IN  debug level for Serial Flash driver
365 /// @return TRUE : succeed
366 /// @return FALSE : failed to set the debug level
367 //------------------------------------------------------------------------------
368 MS_BOOL MDrv_SERFLASH_SetWPInfo(MS_BOOL bWPInfo);
369 
370 //------------------------------------------------------------------------------
371 /// Description : HK ask 8051 to select flash chip by call back function
372 /// @ingroup G_SERFLASH_COMMON
373 /// @param ms_Mcu_ChipSelect_CB    \b IN  call back function
374 /// @return TRUE : succeed
375 /// @return NULL :
376 //------------------------------------------------------------------------------
377 void MDrv_SERFLASH_SetMcuCSCallBack(ms_Mcu_ChipSelect_CB ChipSel_cb);
378 //------------------------------------------------------------------------------
379 /// Description : HK ask 8051 to select flash chip by call back function
380 /// @ingroup G_SERFLASH_COMMON
381 /// @param ms_Mcu_ChipSelect_CB    \b IN  call back function
382 /// @return TRUE : succeed
383 /// @return NULL :
384 //------------------------------------------------------------------------------
385 void MDrv_SERFLASH_SetFlashWPCallBack(ms_Flash_SetHWWP_CB FlashWP_cb);
386 
387 //-------------------------------------------------------------------------------------------------
388 /// Description : Detect flash type by reading the MID and DID
389 /// @ingroup G_SERFLASH_CONTROL
390 /// @return TRUE : succeed
391 /// @return FALSE : unknown flash type
392 /// @note   Not allowed in interrupt context
393 //-------------------------------------------------------------------------------------------------
394 MS_BOOL MDrv_SERFLASH_DetectType(void);
395 
396 //-------------------------------------------------------------------------------------------------
397 /// Description : Detect flash Size
398 /// @ingroup G_SERFLASH_CONTROL
399 /// @return TRUE : succeed
400 /// @return FALSE : unknown flash size
401 /// @note   Not allowed in interrupt context
402 //-------------------------------------------------------------------------------------------------
403 MS_BOOL MDrv_SERFLASH_DetectSize(MS_U32 *u32FlashSize);
404 
405 //-------------------------------------------------------------------------------------------------
406 /// Description : Enable Flash 2XREAD mode, if support
407 /// @ingroup G_SERFLASH_CONTROL
408 /// @param  b2XMode    \b IN: ENABLE/DISABLE
409 /// @return TRUE : succeed
410 /// @return FALSE : not succeed
411 /// @note   Please ref. sprc. to confirm Flash support or not
412 //-------------------------------------------------------------------------------------------------
413 MS_BOOL MDrv_SERFLASH_Set2XRead(MS_BOOL b2XMode);
414 
415 //-------------------------------------------------------------------------------------------------
416 /// Description : Set ckg_spi which flash supports (please ref. the spec. before using this function)
417 /// @ingroup G_SERFLASH_CONTROL
418 /// @param  SPI_DrvCKG    \b IN: enumerate the ckg_spi
419 /// @return TRUE : succeed
420 /// @return FALSE : not succeed
421 /// @note   Please ref. sprc. to confirm Flash support or not. It is safty to run at 43M (Default).
422 //-------------------------------------------------------------------------------------------------
423 MS_BOOL MDrv_SERFLASH_SetCKG(SPI_DrvCKG eCKGspi);
424 
425 //-------------------------------------------------------------------------------------------------
426 /// Description : Set clock div such that spi clock = mcu clock /clock_div.
427 /// @ingroup G_SERFLASH_CONTROL
428 /// @param  SPI_DrvClkDiv    \b IN: enumerate the clock_div
429 /// @return TRUE : succeed
430 /// @return FALSE : not succeed
431 /// @note
432 //-------------------------------------------------------------------------------------------------
433 void MDrv_SERFLASH_ClkDiv(SPI_DrvClkDiv eClkDivspi);
434 
435 //-------------------------------------------------------------------------------------------------
436 /// Description : Set XIU/RIU mode (Default : XIU)
437 /// @ingroup G_SERFLASH_CONTROL
438 /// @param  bXiuRiu    \b IN: 1 for XIU, 0 for RIU
439 /// @return TRUE : succeed
440 /// @return FALSE : not succeed
441 /// @note   XIU mode is faster than RIU mode. It is stable to run by XIU (Default)
442 //-------------------------------------------------------------------------------------------------
443 MS_BOOL MDrv_SERFLASH_SetMode(MS_BOOL bXiuRiu);
444 
445 //-------------------------------------------------------------------------------------------------
446 /// Description : Get Unique ID
447 /// @ingroup G_SERFLASH_CONTROL
448 /// @param  None
449 /// @return the SPI Flash's Unique ID
450 //-------------------------------------------------------------------------------------------------
451 MS_U64 MDrv_SERFLASH_ReadUID(void);
452 
453 //-------------------------------------------------------------------------------------------------
454 /// Description :  Set active flash among multi-spi flashes
455 /// @ingroup G_SERFLASH_CONTROL
456 /// @param  u8FlashIndex    \b IN: The Flash index, 0 for external #1 spi flash, 1 for external #2 spi flash
457 /// @return TRUE : succeed
458 /// @return FALSE : not succeed
459 /// @note   For Secure booting = 0, please check hw_strapping or e-fuse  (the board needs to jump)
460 //-------------------------------------------------------------------------------------------------
461 MS_BOOL MDrv_SERFLASH_ChipSelect(MS_U8 u8FlashIndex);
462 
463 //-------------------------------------------------------------------------------------------------
464 /// Initialize Serial Flash
465 /// @ingroup G_INIT
466 /// @return None
467 //-------------------------------------------------------------------------------------------------
468 void MDrv_SERFLASH_Init(void);
469 
470 //-------------------------------------------------------------------------------------------------
471 /// Description : Read ID from Serial Flash
472 /// @ingroup G_SERFLASH_CONTROL
473 /// @param  pu8FlashID    \b OUT: Virtual data ptr to store the read ID
474 /// @param  u32IDSize    \b IN: size in Bytes
475 /// @return TRUE : succeed
476 /// @return FALSE : fail before timeout
477 /// @note   Not allowed in interrupt context
478 /// @note
479 /// [NONOS_SUPPORT]
480 //-------------------------------------------------------------------------------------------------
481 MS_BOOL MDrv_SERFLASH_ReadID(MS_U8 *pu8FlashID, MS_U32 u32IDSize);
482 
483 //-------------------------------------------------------------------------------------------------
484 /// Description : Read data from Serial Flash
485 /// @ingroup G_SERFLASH_CONTROL
486 /// @param  u32FlashAddr    \b IN: Flash Address
487 /// @param  u32FlashSize    \b IN: Flash Size Data in Bytes
488 /// @param  user_buffer    \b OUT: Virtual Buffer Address ptr to store flash read data
489 /// @return TRUE : succeed
490 /// @return FALSE : fail before timeout or illegal parameters
491 /// @note   Not allowed in interrupt context
492 /// [NONOS_SUPPORT]
493 //-------------------------------------------------------------------------------------------------
494 MS_BOOL MDrv_SERFLASH_Read(MS_U32 u32FlashAddr, MS_U32 u32FlashSize, MS_U8 *user_buffer);
495 
496 //-------------------------------------------------------------------------------------------------
497 /// Description : Erase all sectors in Serial Flash
498 /// @ingroup G_SERFLASH_CONTROL
499 /// @return TRUE : succeed
500 /// @return FALSE : fail before timeout
501 /// @note   Not allowed in interrupt context
502 //-------------------------------------------------------------------------------------------------
503 MS_BOOL MDrv_SERFLASH_EraseChip(void);
504 
505 //-------------------------------------------------------------------------------------------------
506 /// Description : Get flash start block index of a flash address
507 /// @ingroup G_SERFLASH_CONTROL
508 /// @param  u32FlashAddr    \b IN: flash address
509 /// @param  pu32BlockIndex    \b IN: poniter to store the returning block index
510 /// @return TRUE : succeed
511 /// @return FALSE : illegal parameters
512 /// @note   Not allowed in interrupt context
513 //-------------------------------------------------------------------------------------------------
514 MS_BOOL MDrv_SERFLASH_AddressToBlock(MS_U32 u32FlashAddr, MS_U32 *pu32BlockIndex);
515 
516 //-------------------------------------------------------------------------------------------------
517 /// Description : Get flash start address of a block index
518 /// @ingroup G_SERFLASH_CONTROL
519 /// @param  u32BlockIndex    \b IN: block index
520 /// @param  pu32FlashAddr    \b IN: pointer to store the returning flash address
521 /// @return TRUE : succeed
522 /// @return FALSE : illegal parameters
523 /// @note   Not allowed in interrupt context
524 //-------------------------------------------------------------------------------------------------
525 MS_BOOL MDrv_SERFLASH_BlockToAddress(MS_U32 u32BlockIndex, MS_U32 *pu32FlashAddr);
526 
527 //-------------------------------------------------------------------------------------------------
528 /// Description : Erase certain sectors given starting address and size in Serial Flash
529 /// @ingroup G_SERFLASH_CONTROL
530 /// @param  u32StartAddr    \b IN: start address at block boundry
531 /// @param  u32EraseSize    \b IN: size to erase
532 /// @param  bWait    \b IN: wait write done or not
533 /// @return TRUE : succeed
534 /// @return FALSE : fail before timeout or illegal parameters
535 /// @note   Not allowed in interrupt context
536 //-------------------------------------------------------------------------------------------------
537 MS_BOOL MDrv_SERFLASH_AddressErase(MS_U32 u32StartAddr, MS_U32 u32EraseSize, MS_BOOL bWait);
538 
539 //-------------------------------------------------------------------------------------------------
540 /// Description : Erase certain sectors in Serial Flash
541 /// @ingroup G_SERFLASH_CONTROL
542 /// @param  u32StartBlock    \b IN: start block
543 /// @param  u32EndBlock    \b IN: end block
544 /// @param  bWait    \b IN: wait write done or not
545 /// @return TRUE : succeed
546 /// @return FALSE : fail before timeout or illegal parameters
547 /// @note   Not allowed in interrupt context
548 //-------------------------------------------------------------------------------------------------
549 MS_BOOL MDrv_SERFLASH_BlockErase(MS_U32 u32StartBlock, MS_U32 u32EndBlock, MS_BOOL bWait);
550 
551 //-------------------------------------------------------------------------------------------------
552 /// Description : Erase certain 4K sectors in Serial Flash
553 /// @ingroup G_SERFLASH_CONTROL
554 /// @param  u32StartBlock    \b IN: start address
555 /// @param  u32EndBlock    \b IN: end address
556 /// @return TRUE : succeed
557 /// @return FALSE : fail before timeout or illegal parameters
558 /// @note   Not allowed in interrupt context
559 //-------------------------------------------------------------------------------------------------
560 MS_BOOL MDrv_SERFLASH_SectorErase(MS_U32 u32StartAddr, MS_U32 u32EndAddr);
561 
562 //-------------------------------------------------------------------------------------------------
563 /// Description : Check write done in Serial Flash
564 /// @ingroup G_SERFLASH_COMMON
565 /// @return TRUE : done
566 /// @return FALSE : not done
567 /// @note   Not allowed in interrupt context
568 //-------------------------------------------------------------------------------------------------
569 MS_BOOL MDrv_SERFLASH_CheckWriteDone(void);
570 
571 //-------------------------------------------------------------------------------------------------
572 /// Description : Write data to Serial Flash
573 /// @ingroup G_SERFLASH_CONTROL
574 /// @param  u32FlashAddr    \b IN: start address (4-B aligned)
575 /// @param  u32FlashSize    \b IN: size in Bytes (4-B aligned)
576 /// @param  user_buffer    \b IN: Virtual Buffer Address ptr to flash write data
577 /// @return TRUE : succeed
578 /// @return FALSE : fail before timeout or illegal parameters
579 /// @note   Not allowed in interrupt context
580 /// [NONOS_SUPPORT]
581 //-------------------------------------------------------------------------------------------------
582 MS_BOOL MDrv_SERFLASH_Write(MS_U32 u32FlashAddr, MS_U32 u32FlashSize, MS_U8 *user_buffer);
583 
584 //-------------------------------------------------------------------------------------------------
585 /// Description : Read data from Serial Flash to DRAM in DMA mode
586 /// @ingroup G_SERFLASH_CONTROL
587 /// @param  u32FlashStart    \b IN: src start address in flash (0 ~ flash size-1)
588 /// @param  u32DRAMStart    \b IN: dst start address in DRAM (16B-aligned) (0 ~ DRAM size-1)
589 /// @param  u32Size    \b IN: size in Bytes (8B-aligned) (>=8)
590 /// @return TRUE : succeed
591 /// @return FALSE : fail before timeout or illegal parameters
592 /// @note   Not allowed in interrupt context
593 /// @note
594 /// [NONOS_SUPPORT]
595 //-------------------------------------------------------------------------------------------------
596 MS_BOOL MDrv_SERFLASH_DMA(MS_U32 u32FlashStart, MS_U32 u32DRAMStart, MS_U32 u32Size);
597 
598 //-------------------------------------------------------------------------------------------------
599 /// Description : Protect blocks in Serial Flash
600 /// @ingroup G_SERFLASH_CONTROL
601 /// @param  bEnable    \b IN: TRUE/FALSE: enable/disable protection
602 /// @return TRUE : succeed
603 /// @return FALSE : fail before timeout
604 /// @note   Not allowed in interrupt context
605 //-------------------------------------------------------------------------------------------------
606 MS_BOOL MDrv_SERFLASH_WriteProtect(MS_BOOL bEnable);
607 
608 //-------------------------------------------------------------------------------------------------
609 /// Description : Enables all range of flash write protection
610 /// @ingroup G_SERFLASH_ToBeRemove
611 /// @return TRUE : succeed
612 /// @return FALSE : fail before timeout
613 /// @note   Not allowed in interrupt context
614 //-------------------------------------------------------------------------------------------------
615 MS_BOOL MDrv_SERFLASH_WriteProtect_Enable_All_Range(void);
616 
617 //-------------------------------------------------------------------------------------------------
618 /// Description : Disables all range of flash write protection
619 /// @ingroup G_SERFLASH_ToBeRemove
620 /// @return TRUE : succeed
621 /// @return FALSE : fail before timeout
622 /// @note   Not allowed in interrupt context
623 //-------------------------------------------------------------------------------------------------
624 MS_BOOL MDrv_SERFLASH_WriteProtect_Disable_All_Range(void);
625 
626 //-------------------------------------------------------------------------------------------------
627 /// Description : Set flash disable lower bound and size
628 /// @ingroup G_SERFLASH_ToBeRemove
629 /// @param  u32DisableLowerBound    \b IN: the lower bound to disable write protect
630 /// @param  u32DisableSize    \b IN: size to disable write protect
631 /// @return TRUE : succeed
632 /// @return FALSE : fail before timeout or illegal parameters
633 /// @note   Not allowed in interrupt context
634 //-------------------------------------------------------------------------------------------------
635 MS_BOOL MDrv_SERFLASH_WriteProtect_Disable_Range_Set(MS_U32 u32DisableLowerBound, MS_U32 u32DisableSize);
636 
637 //-------------------------------------------------------------------------------------------------
638 /// Description : Set flash enable lower bound and size
639 /// @ingroup G_SERFLASH_ToBeRemove
640 /// @param  u32DisableLowerBound    \b IN: the lower bound to disable write protect
641 /// @param  u32DisableSize    \b IN: size to disable write protect
642 /// @return TRUE : succeed
643 /// @return FALSE : fail before timeout or illegal parameters
644 /// @note   Not allowed in interrupt context
645 //-------------------------------------------------------------------------------------------------
646 MS_BOOL MDrv_SERFLASH_WriteProtect_Enable_Range_Set(MS_U32 u32LowerBound, MS_U32 u32Size);
647 
648 //-------------------------------------------------------------------------------------------------
649 /// Description : Protect blocks in Serial Flash
650 /// @ingroup G_SERFLASH_ToBeRemove
651 /// @param  bEnableAllArea    \b IN: enable or disable protection
652 /// @param  u8BlockProtectBits    \b IN: block protection bits which stand for the area to enable write protect
653 /// @return TRUE : succeed
654 /// @return FALSE : fail before timeout
655 /// @note   Not allowed in interrupt context
656 //-------------------------------------------------------------------------------------------------
657 MS_BOOL MDrv_SERFLASH_WriteProtect_Area(MS_BOOL bEnableAllArea, MS_U8 u8BlockProtectBits);
658 
659 //------- ------------------------------------------------------------------------------------------
660 /// Description : Read Status Register in Serial Flash
661 /// @ingroup G_SERFLASH_CONTROL
662 /// @param  pu8StatusReg    \b OUT: ptr to Status Register value
663 /// @return TRUE : succeed
664 /// @return FALSE : fail before timeout
665 /// @note   Not allowed in interrupt context
666 //-------------------------------------------------------------------------------------------------
667 MS_BOOL MDrv_SERFLASH_ReadStatusRegister(MS_U8 *pu8StatusReg);
668 
669 //------- ------------------------------------------------------------------------------------------
670 /// Description : Read Status Register2 in Serial Flash
671 /// @ingroup G_SERFLASH_ToBeRemove
672 /// @param  pu8StatusReg    \b OUT: ptr to Status Register value
673 /// @return TRUE : succeed
674 /// @return FALSE : fail before timeout
675 /// @note   Not allowed in interrupt context
676 /// @note   For Specific Flash IC with 16-bit status register (high-byte)
677 /// [NONOS_SUPPORT]
678 //-------------------------------------------------------------------------------------------------
679 MS_BOOL MDrv_SERFLASH_ReadStatusRegister2(MS_U8 *pu8StatusReg);
680 
681 //------- ------------------------------------------------------------------------------------------
682 /// Description : Write Status Register in Serial Flash
683 /// @ingroup G_SERFLASH_CONTROL
684 /// @param  u16StatusReg    \b IN: Status Register value
685 /// @return TRUE : succeed
686 /// @return FALSE : fail before timeout
687 /// @note   Not allowed in interrupt context
688 /// @note   For Specific Flash IC with 16-bit status register
689 /// [NONOS_SUPPORT]
690 //-------------------------------------------------------------------------------------------------
691 MS_BOOL MDrv_SERFLASH_WriteStatusRegister(MS_U16 u16StatusReg);
692 
693 //------- ------------------------------------------------------------------------------------------
694 /// Description : Handle for BDMA copy data from ONLY Flash src to other dst
695 /// @ingroup G_SERFLASH_ToBeRemove
696 /// @param u32FlashAddr \b IN: Physical Source address in spi flash
697 /// @param u32DramAddr \b IN: Physical Dst address
698 /// @param u32Len \b IN: data length
699 /// @param eDstDev \b IN: The Dst Device of Flash BDMA
700 /// @param u8OpCfg \b IN: u8OpCfg: default is SPIDMA_OPCFG_DEF
701 /// - Bit0: inverse mode --> SPIDMA_OPCFG_INV_COPY
702 /// - Bit2: Copy & CRC check in wait mode --> SPIDMA_OPCFG_CRC_COPY
703 /// - Bit3: Copy without waiting --> SPIDMA_OPCFG_NOWAIT_COPY
704 /// @return \b MS_BOOL
705 /// [NONOS_SUPPORT]
706 /// [fw : drvBDMA ]
707 //-------------------------------------------------------------------------------------------------
708 MS_BOOL MDrv_SERFLASH_CopyHnd(MS_PHYADDR u32FlashAddr, MS_PHYADDR u32DstAddr, MS_U32 u32Len, SPIDMA_Dev eDstDev, MS_U8 u8OpCfg);
709 
710 //------- ------------------------------------------------------------------------------------------
711 /// Description : Switch SPI as GPIO Input
712 /// @ingroup G_SERFLASH_CONTROL
713 /// @param  bSwitch    \b IN: 1 for GPIO, 0 for NORMAL
714 /// @note   Not allowed in interrupt context
715 /// @note   For project's power consumption
716 /// [NONOS_SUPPORT]
717 //-------------------------------------------------------------------------------------------------
718 void MDrv_SERFLASH_SetGPIO(MS_BOOL bSwitch);
719 
720 //------- ------------------------------------------------------------------------------------------
721 /// Description : Change Kernel or User Mode in Serial Flash
722 /// @ingroup G_SERFLASH_CONTROL
723 /// @param  SpiAttri
724 /// @return TRUE : succeed
725 /// @return FALSE : fail not suppported enum
726 /// @note   No
727 /// @note   Use Kernel Enum to Kernel Space
728 /// [NONOS_SUPPORT]
729 //-------------------------------------------------------------------------------------------------
730 MS_BOOL MDrv_FLASH_Attribute(SPI_Attribute SpiAttri);
731 
732 //-------------------------------------------------------------------------------------------------
733 //  WRAPPER FOR CHAKRA
734 //-------------------------------------------------------------------------------------------------
735 MS_BOOL MDrv_SERFLASH_WriteProtect_Area_Lookup(MS_U32 u32ProtectSpace, MS_U32 u32NonProtectSpace, MS_U8 *pu8BlockProtectBits);
736 //-------------------------------------------------------------------------------------------------
737 /// MOBF Encrypt
738 /// @ingroup G_SERFLASH_ToBeRemove
739 /// @param u32Key \b IN: Key
740 /// @param bEnable \b IN: TRUE/FLASE
741 /// @return DRVAESDMA_OK : Success
742 /// @return Others : Fail
743 //-------------------------------------------------------------------------------------------------
744 MS_U32 MDrv_SERFLASH_WriteProtect_Area_Boundary(void);
745 //-------------------------------------------------------------------------------------------------
746 /// MOBF Encrypt
747 /// @ingroup G_SERFLASH_ToBeRemove
748 /// @param u32Key \b IN: Key
749 /// @param bEnable \b IN: TRUE/FLASE
750 /// @return DRVAESDMA_OK : Success
751 /// @return Others : Fail
752 //-------------------------------------------------------------------------------------------------
753 MS_BOOL MDrv_FLASH_Write(MS_U32 u32FlashAddr,MS_U32 u32FlashSize,MS_U8 * user_buffer);
754 //-------------------------------------------------------------------------------------------------
755 /// MOBF Encrypt
756 /// @ingroup G_SERFLASH_ToBeRemove
757 /// @param u32Key \b IN: Key
758 /// @param bEnable \b IN: TRUE/FLASE
759 /// @return DRVAESDMA_OK : Success
760 /// @return Others : Fail
761 //-------------------------------------------------------------------------------------------------
762 MS_BOOL MDrv_FLASH_Read(MS_U32 u32FlashAddr,MS_U32 u32FlashSize,MS_U8 * user_buffer);
763 //-------------------------------------------------------------------------------------------------
764 /// MOBF Encrypt
765 /// @ingroup G_SERFLASH_ToBeRemove
766 /// @param u32Key \b IN: Key
767 /// @param bEnable \b IN: TRUE/FLASE
768 /// @return DRVAESDMA_OK : Success
769 /// @return Others : Fail
770 //-------------------------------------------------------------------------------------------------
771 MS_BOOL MDrv_FLASH_WriteProtect(MS_BOOL bEnable);
772 //-------------------------------------------------------------------------------------------------
773 /// MOBF Encrypt
774 /// @ingroup G_SERFLASH_ToBeRemove
775 /// @param u32Key \b IN: Key
776 /// @param bEnable \b IN: TRUE/FLASE
777 /// @return DRVAESDMA_OK : Success
778 /// @return Others : Fail
779 //-------------------------------------------------------------------------------------------------
780 MS_BOOL MDrv_FLASH_WriteProtect_Enable_All_Range(void);
781 //-------------------------------------------------------------------------------------------------
782 /// MOBF Encrypt
783 /// @ingroup G_SERFLASH_ToBeRemove
784 /// @param u32Key \b IN: Key
785 /// @param bEnable \b IN: TRUE/FLASE
786 /// @return DRVAESDMA_OK : Success
787 /// @return Others : Fail
788 //-------------------------------------------------------------------------------------------------
789 MS_BOOL MDrv_FLASH_WriteProtect_Disable_All_Range(void);
790 //-------------------------------------------------------------------------------------------------
791 /// MOBF Encrypt
792 /// @ingroup G_SERFLASH_ToBeRemove
793 /// @param u32Key \b IN: Key
794 /// @param bEnable \b IN: TRUE/FLASE
795 /// @return DRVAESDMA_OK : Success
796 /// @return Others : Fail
797 //-------------------------------------------------------------------------------------------------
798 MS_BOOL MDrv_FLASH_WriteProtect_Disable_Range_Set(MS_U32 DisableLowerBound, MS_U32 DisableSize);
799 //-------------------------------------------------------------------------------------------------
800 /// MOBF Encrypt
801 /// @ingroup G_SERFLASH_ToBeRemove
802 /// @param u32Key \b IN: Key
803 /// @param bEnable \b IN: TRUE/FLASE
804 /// @return DRVAESDMA_OK : Success
805 /// @return Others : Fail
806 //-------------------------------------------------------------------------------------------------
807 MS_BOOL MDrv_FLASH_WriteProtect_Area(MS_BOOL bEnableAllArea, MS_U8 BlockProtectBits);
808 //-------------------------------------------------------------------------------------------------
809 /// MOBF Encrypt
810 /// @ingroup G_SERFLASH_ToBeRemove
811 /// @param u32Key \b IN: Key
812 /// @param bEnable \b IN: TRUE/FLASE
813 /// @return DRVAESDMA_OK : Success
814 /// @return Others : Fail
815 //-------------------------------------------------------------------------------------------------
816 MS_BOOL MDrv_FLASH_ReadStatusRegister(MS_U8 *pu8StatusReg);
817 //-------------------------------------------------------------------------------------------------
818 /// MOBF Encrypt
819 /// @ingroup G_SERFLASH_ToBeRemove
820 /// @param u32Key \b IN: Key
821 /// @param bEnable \b IN: TRUE/FLASE
822 /// @return DRVAESDMA_OK : Success
823 /// @return Others : Fail
824 //-------------------------------------------------------------------------------------------------
825 MS_BOOL MDrv_FLASH_ReadStatusRegister2(MS_U8 *pu8StatusReg);
826 //-------------------------------------------------------------------------------------------------
827 /// MOBF Encrypt
828 /// @ingroup G_SERFLASH_ToBeRemove
829 /// @param u32Key \b IN: Key
830 /// @param bEnable \b IN: TRUE/FLASE
831 /// @return DRVAESDMA_OK : Success
832 /// @return Others : Fail
833 //-------------------------------------------------------------------------------------------------
834 MS_BOOL MDrv_FLASH_WriteStatusRegister(MS_U16 u16StatusReg);
835 //-------------------------------------------------------------------------------------------------
836 /// MOBF Encrypt
837 /// @ingroup G_SERFLASH_ToBeRemove
838 /// @param u32Key \b IN: Key
839 /// @param bEnable \b IN: TRUE/FLASE
840 /// @return DRVAESDMA_OK : Success
841 /// @return Others : Fail
842 //-------------------------------------------------------------------------------------------------
843 MS_BOOL MDrv_FLASH_DetectType(void);
844 //-------------------------------------------------------------------------------------------------
845 /// MOBF Encrypt
846 /// @ingroup G_SERFLASH_ToBeRemove
847 /// @param u32Key \b IN: Key
848 /// @param bEnable \b IN: TRUE/FLASE
849 /// @return DRVAESDMA_OK : Success
850 /// @return Others : Fail
851 //-------------------------------------------------------------------------------------------------
852 MS_BOOL MDrv_FLASH_DetectSize(MS_U32 *u32FlashSize);
853 //-------------------------------------------------------------------------------------------------
854 /// MOBF Encrypt
855 /// @ingroup G_SERFLASH_ToBeRemove
856 /// @param u32Key \b IN: Key
857 /// @param bEnable \b IN: TRUE/FLASE
858 /// @return DRVAESDMA_OK : Success
859 /// @return Others : Fail
860 //-------------------------------------------------------------------------------------------------
861 MS_BOOL MDrv_FLASH_AddressToBlock(MS_U32 u32FlashAddr, MS_U32 *pu32BlockIndex);
862 //-------------------------------------------------------------------------------------------------
863 /// MOBF Encrypt
864 /// @ingroup G_SERFLASH_ToBeRemove
865 /// @param u32Key \b IN: Key
866 /// @param bEnable \b IN: TRUE/FLASE
867 /// @return DRVAESDMA_OK : Success
868 /// @return Others : Fail
869 //-------------------------------------------------------------------------------------------------
870 MS_BOOL MDrv_FLASH_BlockToAddress(MS_U32 u32BlockIndex, MS_U32 *pu32FlashAddr);
871 //-------------------------------------------------------------------------------------------------
872 /// MOBF Encrypt
873 /// @ingroup G_SERFLASH_ToBeRemove
874 /// @param u32Key \b IN: Key
875 /// @param bEnable \b IN: TRUE/FLASE
876 /// @return DRVAESDMA_OK : Success
877 /// @return Others : Fail
878 //-------------------------------------------------------------------------------------------------
879 MS_BOOL MDrv_FLASH_AddressErase(MS_U32 u32StartAddr,MS_U32 u32EraseSize,MS_BOOL bWait);
880 //-------------------------------------------------------------------------------------------------
881 /// MOBF Encrypt
882 /// @ingroup G_SERFLASH_ToBeRemove
883 /// @param u32Key \b IN: Key
884 /// @param bEnable \b IN: TRUE/FLASE
885 /// @return DRVAESDMA_OK : Success
886 /// @return Others : Fail
887 //-------------------------------------------------------------------------------------------------
888 MS_BOOL MDrv_FLASH_BlockErase(MS_U16 u16StartBlock,MS_U16 u16EndBlock,MS_BOOL bWait);
889 //-------------------------------------------------------------------------------------------------
890 /// MOBF Encrypt
891 /// @ingroup G_SERFLASH_ToBeRemove
892 /// @param u32Key \b IN: Key
893 /// @param bEnable \b IN: TRUE/FLASE
894 /// @return DRVAESDMA_OK : Success
895 /// @return Others : Fail
896 //-------------------------------------------------------------------------------------------------
897 MS_BOOL MDrv_FLASH_CheckWriteDone(void);
898 
899 #ifdef MXIC_IBPM
900 //-------------------------------------------------------------------------------------------------
901 /// MOBF Encrypt
902 /// @ingroup G_SERFLASH_ToBeRemove
903 /// @param u32Key \b IN: Key
904 /// @param bEnable \b IN: TRUE/FLASE
905 /// @return DRVAESDMA_OK : Success
906 /// @return Others : Fail
907 //-------------------------------------------------------------------------------------------------
908 void MDrv_SERFLASH_EnterIBPM(void);
909 //-------------------------------------------------------------------------------------------------
910 /// MOBF Encrypt
911 /// @ingroup G_SERFLASH_ToBeRemove
912 /// @param u32Key \b IN: Key
913 /// @param bEnable \b IN: TRUE/FLASE
914 /// @return DRVAESDMA_OK : Success
915 /// @return Others : Fail
916 //-------------------------------------------------------------------------------------------------
917 MS_U8 MDrv_SERFLASH_ReadBlockStatus(MS_PHYADDR u32FlashAddr);
918 //-------------------------------------------------------------------------------------------------
919 /// MOBF Encrypt
920 /// @ingroup G_SERFLASH_ToBeRemove
921 /// @param u32Key \b IN: Key
922 /// @param bEnable \b IN: TRUE/FLASE
923 /// @return DRVAESDMA_OK : Success
924 /// @return Others : Fail
925 //-------------------------------------------------------------------------------------------------
926 MS_BOOL MDrv_SERFLASH_SingleBlockProtect(MS_PHYADDR u32FlashAddr,MS_BOOL bLock);
927 //-------------------------------------------------------------------------------------------------
928 /// MOBF Encrypt
929 /// @ingroup G_SERFLASH_ToBeRemove
930 /// @param u32Key \b IN: Key
931 /// @param bEnable \b IN: TRUE/FLASE
932 /// @return DRVAESDMA_OK : Success
933 /// @return Others : Fail
934 //-------------------------------------------------------------------------------------------------
935 MS_U32 MDrv_SERFLASH_MultiBlockProtect(MS_U32 u32StartBlock, MS_U32 u32EndBlock, MS_BOOL bLock);
936 #endif
937 
938 #ifdef MUNINN_ENABLE
939 //-------------------------------------------------------------------------------------------------
940 /// MOBF Encrypt
941 /// @ingroup G_SERFLASH_ToBeRemove
942 /// @param u32Key \b IN: Key
943 /// @param bEnable \b IN: TRUE/FLASE
944 /// @return DRVAESDMA_OK : Success
945 /// @return Others : Fail
946 //-------------------------------------------------------------------------------------------------
947 MS_U8 MDrv_OTP_ReadStatusReg(MS_U8 u8ByteAddr);
948 //-------------------------------------------------------------------------------------------------
949 /// MOBF Encrypt
950 /// @ingroup G_SERFLASH_ToBeRemove
951 /// @param u32Key \b IN: Key
952 /// @param bEnable \b IN: TRUE/FLASE
953 /// @return DRVAESDMA_OK : Success
954 /// @return Others : Fail
955 //-------------------------------------------------------------------------------------------------
956 void MDrv_OTP_WriteStatusReg(MS_U8 u8ByteAddr, MS_U8 u8ByteReg);
957 //-------------------------------------------------------------------------------------------------
958 /// MOBF Encrypt
959 /// @ingroup G_SERFLASH_ToBeRemove
960 /// @param u32Key \b IN: Key
961 /// @param bEnable \b IN: TRUE/FLASE
962 /// @return DRVAESDMA_OK : Success
963 /// @return Others : Fail
964 //-------------------------------------------------------------------------------------------------
965 MS_PHYADDR MDrv_OTP_Read(MS_U32 u32FlashAddr, MS_U32 u32FlashSize, MS_U8 *user_buffer);
966 //-------------------------------------------------------------------------------------------------
967 /// MOBF Encrypt
968 /// @ingroup G_SERFLASH_ToBeRemove
969 /// @param u32Key \b IN: Key
970 /// @param bEnable \b IN: TRUE/FLASE
971 /// @return DRVAESDMA_OK : Success
972 /// @return Others : Fail
973 //-------------------------------------------------------------------------------------------------
974 MS_PHYADDR MDrv_OTP_FastRead(MS_U32 u32FlashAddr, MS_U32 u32FlashSize, MS_U8 *user_buffer);
975 //-------------------------------------------------------------------------------------------------
976 /// MOBF Encrypt
977 /// @ingroup G_SERFLASH_ToBeRemove
978 /// @param u32Key \b IN: Key
979 /// @param bEnable \b IN: TRUE/FLASE
980 /// @return DRVAESDMA_OK : Success
981 /// @return Others : Fail
982 //-------------------------------------------------------------------------------------------------
983 MS_PHYADDR MDrv_OTP_Write(MS_U32 u32FlashAddr, MS_U32 u32FlashSize, MS_U8 *user_buffer);
984 //-------------------------------------------------------------------------------------------------
985 /// MOBF Encrypt
986 /// @ingroup G_SERFLASH_ToBeRemove
987 /// @param u32Key \b IN: Key
988 /// @param bEnable \b IN: TRUE/FLASE
989 /// @return DRVAESDMA_OK : Success
990 /// @return Others : Fail
991 //-------------------------------------------------------------------------------------------------
992 MS_BOOL MDrv_OTP_WriteTestMode(MS_U32 u32FlashAddr, MS_U8 ByteData);
993 #endif
994 
995 // FSP
996 //-------------------------------------------------------------------------------------------------
997 /// MOBF Encrypt
998 /// @ingroup G_SERFLASH_FSP
999 /// @param u32Key \b IN: Key
1000 /// @param bEnable \b IN: TRUE/FLASE
1001 /// @return DRVAESDMA_OK : Success
1002 /// @return Others : Fail
1003 //-------------------------------------------------------------------------------------------------
1004 MS_BOOL MDrv_FSP_WriteData(MS_U32 u32Addr, MS_U32 u32DataSize, MS_U8 *pu8Data);
1005 //-------------------------------------------------------------------------------------------------
1006 /// MOBF Encrypt
1007 /// @ingroup G_SERFLASH_FSP
1008 /// @param u32Key \b IN: Key
1009 /// @param bEnable \b IN: TRUE/FLASE
1010 /// @return DRVAESDMA_OK : Success
1011 /// @return Others : Fail
1012 //-------------------------------------------------------------------------------------------------
1013 MS_BOOL MDrv_FSP_ReadData(MS_U32 u32Addr, MS_U32 u32DataSize, MS_U8 *pu8Data);
1014 //-------------------------------------------------------------------------------------------------
1015 /// MOBF Encrypt
1016 /// @ingroup G_SERFLASH_FSP
1017 /// @param u32Key \b IN: Key
1018 /// @param bEnable \b IN: TRUE/FLASE
1019 /// @return DRVAESDMA_OK : Success
1020 /// @return Others : Fail
1021 //-------------------------------------------------------------------------------------------------
1022 MS_BOOL MDrv_FSP_BlockErase(MS_U32 u32StartBlock, MS_U32 u32EndBlock, MS_BOOL bWait);
1023 //-------------------------------------------------------------------------------------------------
1024 /// MOBF Encrypt
1025 /// @ingroup G_SERFLASH_FSP
1026 /// @param u32Key \b IN: Key
1027 /// @param bEnable \b IN: TRUE/FLASE
1028 /// @return DRVAESDMA_OK : Success
1029 /// @return Others : Fail
1030 //-------------------------------------------------------------------------------------------------
1031 MS_BOOL MDrv_FSP_AddressErase(MS_U32 u32StartAddr, MS_U32 u32EraseSize, MS_BOOL bWait);
1032 
1033 //power state
1034 //-------------------------------------------------------------------------------------------------
1035 /// MOBF Encrypt
1036 /// @ingroup G_SERFLASH_COMMON
1037 /// @param u32Key \b IN: Key
1038 /// @param bEnable \b IN: TRUE/FLASE
1039 /// @return DRVAESDMA_OK : Success
1040 /// @return Others : Fail
1041 //-------------------------------------------------------------------------------------------------
1042 MS_U32 MDrv_SERFLASH_SetPowerState(EN_POWER_MODE u16PowerState);
1043 
1044 //-------------------------------------------------------------------------------------------------
1045 //  Flash OTP USAGE
1046 //-------------------------------------------------------------------------------------------------
1047 
1048 //------------------------------------------------------------------------------
1049 /// Description : Get Protection Info
1050 /// @param  Protection_Type,Protection Size ,Protection Info
1051 /// @return TRUE : succeed
1052 /// @return FALSE : failed
1053 //------------------------------------------------------------------------------
1054 MS_BOOL MDrv_SERFLASH_WriteProtect_TableInfo(SERFLASH_RegionMapType type, void  *pstTable);
1055 
1056 //------------------------------------------------------------------------------
1057 /// Description : OTP Read
1058 /// @param  OTP address, OTP Size , OTP read data buffer
1059 /// @return TRUE : succeed
1060 /// @return FALSE : failed
1061 //------------------------------------------------------------------------------
1062 MS_BOOL  MDrv_FLASH_OTP_Read(MS_U32 u32FlashAddr, MS_U16 u16FlashSize, MS_U8 *user_buffer);
1063 
1064 //------------------------------------------------------------------------------
1065 /// Description : OTP Write
1066 /// @param  OTP address, OTP Size , OTP read data buffer
1067 /// @return TRUE : succeed
1068 /// @return FALSE : failed
1069 //------------------------------------------------------------------------------
1070 MS_BOOL MDrv_FLASH_OTP_Write(MS_U32 u32FlashAddr, MS_U16 u16FlashSize, MS_U8 *user_buffer);
1071 
1072 //------------------------------------------------------------------------------
1073 /// Description : OTP Erase
1074 /// @param  OTP address
1075 /// @return TRUE : succeed
1076 /// @return FALSE : failed
1077 //------------------------------------------------------------------------------
1078 MS_BOOL MDrv_FLASH_OTP_ERASE(MS_U32  u32Addr);
1079 
1080 extern ms_Mcu_ChipSelect_CB McuChipSelectCB;
1081 extern ms_Flash_SetHWWP_CB FlashSetHWWPCB;
1082 #ifdef __cplusplus
1083 }
1084 #endif
1085 
1086 #endif // _DRV_SERFLASH_H_
1087