1*53ee8cc1Swenshuai.xi //<MStar Software> 2*53ee8cc1Swenshuai.xi //****************************************************************************** 3*53ee8cc1Swenshuai.xi // MStar Software 4*53ee8cc1Swenshuai.xi // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved. 5*53ee8cc1Swenshuai.xi // All software, firmware and related documentation herein ("MStar Software") are 6*53ee8cc1Swenshuai.xi // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by 7*53ee8cc1Swenshuai.xi // law, including, but not limited to, copyright law and international treaties. 8*53ee8cc1Swenshuai.xi // Any use, modification, reproduction, retransmission, or republication of all 9*53ee8cc1Swenshuai.xi // or part of MStar Software is expressly prohibited, unless prior written 10*53ee8cc1Swenshuai.xi // permission has been granted by MStar. 11*53ee8cc1Swenshuai.xi // 12*53ee8cc1Swenshuai.xi // By accessing, browsing and/or using MStar Software, you acknowledge that you 13*53ee8cc1Swenshuai.xi // have read, understood, and agree, to be bound by below terms ("Terms") and to 14*53ee8cc1Swenshuai.xi // comply with all applicable laws and regulations: 15*53ee8cc1Swenshuai.xi // 16*53ee8cc1Swenshuai.xi // 1. MStar shall retain any and all right, ownership and interest to MStar 17*53ee8cc1Swenshuai.xi // Software and any modification/derivatives thereof. 18*53ee8cc1Swenshuai.xi // No right, ownership, or interest to MStar Software and any 19*53ee8cc1Swenshuai.xi // modification/derivatives thereof is transferred to you under Terms. 20*53ee8cc1Swenshuai.xi // 21*53ee8cc1Swenshuai.xi // 2. You understand that MStar Software might include, incorporate or be 22*53ee8cc1Swenshuai.xi // supplied together with third party`s software and the use of MStar 23*53ee8cc1Swenshuai.xi // Software may require additional licenses from third parties. 24*53ee8cc1Swenshuai.xi // Therefore, you hereby agree it is your sole responsibility to separately 25*53ee8cc1Swenshuai.xi // obtain any and all third party right and license necessary for your use of 26*53ee8cc1Swenshuai.xi // such third party`s software. 27*53ee8cc1Swenshuai.xi // 28*53ee8cc1Swenshuai.xi // 3. MStar Software and any modification/derivatives thereof shall be deemed as 29*53ee8cc1Swenshuai.xi // MStar`s confidential information and you agree to keep MStar`s 30*53ee8cc1Swenshuai.xi // confidential information in strictest confidence and not disclose to any 31*53ee8cc1Swenshuai.xi // third party. 32*53ee8cc1Swenshuai.xi // 33*53ee8cc1Swenshuai.xi // 4. MStar Software is provided on an "AS IS" basis without warranties of any 34*53ee8cc1Swenshuai.xi // kind. Any warranties are hereby expressly disclaimed by MStar, including 35*53ee8cc1Swenshuai.xi // without limitation, any warranties of merchantability, non-infringement of 36*53ee8cc1Swenshuai.xi // intellectual property rights, fitness for a particular purpose, error free 37*53ee8cc1Swenshuai.xi // and in conformity with any international standard. You agree to waive any 38*53ee8cc1Swenshuai.xi // claim against MStar for any loss, damage, cost or expense that you may 39*53ee8cc1Swenshuai.xi // incur related to your use of MStar Software. 40*53ee8cc1Swenshuai.xi // In no event shall MStar be liable for any direct, indirect, incidental or 41*53ee8cc1Swenshuai.xi // consequential damages, including without limitation, lost of profit or 42*53ee8cc1Swenshuai.xi // revenues, lost or damage of data, and unauthorized system use. 43*53ee8cc1Swenshuai.xi // You agree that this Section 4 shall still apply without being affected 44*53ee8cc1Swenshuai.xi // even if MStar Software has been modified by MStar in accordance with your 45*53ee8cc1Swenshuai.xi // request or instruction for your use, except otherwise agreed by both 46*53ee8cc1Swenshuai.xi // parties in writing. 47*53ee8cc1Swenshuai.xi // 48*53ee8cc1Swenshuai.xi // 5. If requested, MStar may from time to time provide technical supports or 49*53ee8cc1Swenshuai.xi // services in relation with MStar Software to you for your use of 50*53ee8cc1Swenshuai.xi // MStar Software in conjunction with your or your customer`s product 51*53ee8cc1Swenshuai.xi // ("Services"). 52*53ee8cc1Swenshuai.xi // You understand and agree that, except otherwise agreed by both parties in 53*53ee8cc1Swenshuai.xi // writing, Services are provided on an "AS IS" basis and the warranty 54*53ee8cc1Swenshuai.xi // disclaimer set forth in Section 4 above shall apply. 55*53ee8cc1Swenshuai.xi // 56*53ee8cc1Swenshuai.xi // 6. Nothing contained herein shall be construed as by implication, estoppels 57*53ee8cc1Swenshuai.xi // or otherwise: 58*53ee8cc1Swenshuai.xi // (a) conferring any license or right to use MStar name, trademark, service 59*53ee8cc1Swenshuai.xi // mark, symbol or any other identification; 60*53ee8cc1Swenshuai.xi // (b) obligating MStar or any of its affiliates to furnish any person, 61*53ee8cc1Swenshuai.xi // including without limitation, you and your customers, any assistance 62*53ee8cc1Swenshuai.xi // of any kind whatsoever, or any information; or 63*53ee8cc1Swenshuai.xi // (c) conferring any license or right under any intellectual property right. 64*53ee8cc1Swenshuai.xi // 65*53ee8cc1Swenshuai.xi // 7. These terms shall be governed by and construed in accordance with the laws 66*53ee8cc1Swenshuai.xi // of Taiwan, R.O.C., excluding its conflict of law rules. 67*53ee8cc1Swenshuai.xi // Any and all dispute arising out hereof or related hereto shall be finally 68*53ee8cc1Swenshuai.xi // settled by arbitration referred to the Chinese Arbitration Association, 69*53ee8cc1Swenshuai.xi // Taipei in accordance with the ROC Arbitration Law and the Arbitration 70*53ee8cc1Swenshuai.xi // Rules of the Association by three (3) arbitrators appointed in accordance 71*53ee8cc1Swenshuai.xi // with the said Rules. 72*53ee8cc1Swenshuai.xi // The place of arbitration shall be in Taipei, Taiwan and the language shall 73*53ee8cc1Swenshuai.xi // be English. 74*53ee8cc1Swenshuai.xi // The arbitration award shall be final and binding to both parties. 75*53ee8cc1Swenshuai.xi // 76*53ee8cc1Swenshuai.xi //****************************************************************************** 77*53ee8cc1Swenshuai.xi //<MStar Software> 78*53ee8cc1Swenshuai.xi //////////////////////////////////////////////////////////////////////////////// 79*53ee8cc1Swenshuai.xi // 80*53ee8cc1Swenshuai.xi // Copyright (c) 2008-2009 MStar Semiconductor, Inc. 81*53ee8cc1Swenshuai.xi // All rights reserved. 82*53ee8cc1Swenshuai.xi // 83*53ee8cc1Swenshuai.xi // Unless otherwise stipulated in writing, any and all information contained 84*53ee8cc1Swenshuai.xi // herein regardless in any format shall remain the sole proprietary of 85*53ee8cc1Swenshuai.xi // MStar Semiconductor Inc. and be kept in strict confidence 86*53ee8cc1Swenshuai.xi // ("MStar Confidential Information") by the recipient. 87*53ee8cc1Swenshuai.xi // Any unauthorized act including without limitation unauthorized disclosure, 88*53ee8cc1Swenshuai.xi // copying, use, reproduction, sale, distribution, modification, disassembling, 89*53ee8cc1Swenshuai.xi // reverse engineering and compiling of the contents of MStar Confidential 90*53ee8cc1Swenshuai.xi // Information is unlawful and strictly prohibited. MStar hereby reserves the 91*53ee8cc1Swenshuai.xi // rights to any and all damages, losses, costs and expenses resulting therefrom. 92*53ee8cc1Swenshuai.xi // 93*53ee8cc1Swenshuai.xi //////////////////////////////////////////////////////////////////////////////// 94*53ee8cc1Swenshuai.xi 95*53ee8cc1Swenshuai.xi #ifndef _HAL_SERFLASH_H_ 96*53ee8cc1Swenshuai.xi #define _HAL_SERFLASH_H_ 97*53ee8cc1Swenshuai.xi 98*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 99*53ee8cc1Swenshuai.xi // Macro and Define 100*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 101*53ee8cc1Swenshuai.xi 102*53ee8cc1Swenshuai.xi // Flash IC 103*53ee8cc1Swenshuai.xi #define FLASH_IC_UNKNOWN 0x0000 104*53ee8cc1Swenshuai.xi #define FLASH_IC_SST25VF080B 0x0100 // 1M SST 105*53ee8cc1Swenshuai.xi #define FLASH_IC_SST25VF016B 0x0101 // 2M 106*53ee8cc1Swenshuai.xi #define FLASH_IC_SST25VF032B 0x0102 // 2M 107*53ee8cc1Swenshuai.xi #define FLASH_IC_PM25LV080 0x0200 // 1M PMC 108*53ee8cc1Swenshuai.xi #define FLASH_IC_PM25LV016 0x0201 // 2M 109*53ee8cc1Swenshuai.xi #define FLASH_IC_ST25P80_A 0x0300 // 1M ST 110*53ee8cc1Swenshuai.xi #define FLASH_IC_ST25P16_A 0x0301 // 2M 111*53ee8cc1Swenshuai.xi #define FLASH_IC_STM25P32 0x0302 // 4M 112*53ee8cc1Swenshuai.xi #define FLASH_IC_AT26DF081A 0x0400 // 1M ATMEL 113*53ee8cc1Swenshuai.xi #define FLASH_IC_AT26DF161 0x0401 // 2M 114*53ee8cc1Swenshuai.xi #define FLASH_IC_AT26DF321 0x0402 // 4M 115*53ee8cc1Swenshuai.xi #define FLASH_IC_AT25DF321A 0x0403 // 4M 116*53ee8cc1Swenshuai.xi #define FLASH_IC_AT25DF641 0x0404 // 8M 117*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L8005 0x0500 // 1M MXIC 118*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L1605A 0x0501 // 2M 119*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L3205D 0x0502 // 4M 120*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L6405D 0x0503 // 8M 121*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L12805D 0x0504 // 16M 122*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L6445E 0x0505 // 8M 123*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L12845E 0x0506 // 16M 124*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L1606E 0x0507 // 2M 125*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L3206E 0x0508 // 4M 126*53ee8cc1Swenshuai.xi #define FLASH_IC_MX25L6406E 0x0509 // 8M 127*53ee8cc1Swenshuai.xi 128*53ee8cc1Swenshuai.xi #define FLASH_IC_NX25P80 0x0600 // 1M NX 129*53ee8cc1Swenshuai.xi #define FLASH_IC_NX25P16 0x0601 // 2M 130*53ee8cc1Swenshuai.xi #define FLASH_IC_W25X80 0x0700 // 1M WINB 131*53ee8cc1Swenshuai.xi #define FLASH_IC_W25X16 0x0701 // 2M 132*53ee8cc1Swenshuai.xi #define FLASH_IC_W25Q16 0x0711 // 2M 133*53ee8cc1Swenshuai.xi #define FLASH_IC_W25X32 0x0702 // 4M 134*53ee8cc1Swenshuai.xi #define FLASH_IC_W25Q32 0x0703 // 4M 135*53ee8cc1Swenshuai.xi #define FLASH_IC_W25X64 0x0704 // 8M 136*53ee8cc1Swenshuai.xi #define FLASH_IC_W25Q64 0x0705 // 8M 137*53ee8cc1Swenshuai.xi #define FLASH_IC_W25Q128 0x0706 // 16M 138*53ee8cc1Swenshuai.xi #define FLASH_IC_W25Q80 0x0707 // 1M 139*53ee8cc1Swenshuai.xi #define FLASH_IC_W25Q64CV 0x0708 // 8M 140*53ee8cc1Swenshuai.xi #define FLASH_IC_W25Q32BV 0x0709 // 4M 141*53ee8cc1Swenshuai.xi 142*53ee8cc1Swenshuai.xi #define FLASH_IC_S25FL008A 0x0800 // 1M SPANSION 143*53ee8cc1Swenshuai.xi #define FLASH_IC_S25FL016A 0x0801 // 2M 144*53ee8cc1Swenshuai.xi #define FLASH_IC_S25FL128P 0x0802 // 16M 145*53ee8cc1Swenshuai.xi #define FLASH_IC_S25FL032P 0x0803 // 4M 146*53ee8cc1Swenshuai.xi #define FLASH_IC_S25FL064P 0x0804 // 8M 147*53ee8cc1Swenshuai.xi #define FLASH_IC_S25FL032K 0x0805 // 4M 148*53ee8cc1Swenshuai.xi 149*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25B20T 0x0900 // 2M EON 150*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25B20B 0x0901 // 2M 151*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25B10T 0x0902 // 1M 152*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25B10B 0x0903 // 1M 153*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25B32B 0x0904 // 4M (Bottom Boot) 154*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25B64B 0x0905 // 4M 155*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25Q32A 0x0906 // 4M 156*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25Q128 0x0907 // 16M 157*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25Q32 0x0908 // 4M 158*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25Q64 0x0909 // 4M 159*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25F16 0x0910 // 2M 160*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25F32 0x0911 // 4M 161*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25F80 0x0912 // 1M 162*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25P16 0x0913 // 2M 163*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25QH16 0x0914 // 2M 164*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25F10 0x0999 // 128K for secure boot 165*53ee8cc1Swenshuai.xi #define FLASH_IC_ESMT_F25L016A 0x0A00 // 2M 166*53ee8cc1Swenshuai.xi #define FLASH_IC_ESMT_F25L032PA 0x0A01 // 4M 167*53ee8cc1Swenshuai.xi #define FLASH_IC_ESMT_F25L032QA 0x0A02 // 4M 168*53ee8cc1Swenshuai.xi 169*53ee8cc1Swenshuai.xi //#define FLASH_IC_EN25Q32 0x0A01 // 2M 170*53ee8cc1Swenshuai.xi #define FLASH_IC_EN25Q16 0x0A03 // 2M 171*53ee8cc1Swenshuai.xi #define FLASH_IC_GD25Q16 0x0B01 // 2M 172*53ee8cc1Swenshuai.xi #define FLASH_IC_GD25Q32 0x0B02 // 4M 173*53ee8cc1Swenshuai.xi #define FLASH_IC_PM25LQ032C 0x0D00 // 4M 174*53ee8cc1Swenshuai.xi #define FLASH_IC_MICRON_M25P16 0x0E00 // 2M 175*53ee8cc1Swenshuai.xi #define FLASH_IC_MICRON_N25Q32 0x0E01 // 4M 176*53ee8cc1Swenshuai.xi #define FLASH_IC_MICRON_N25Q64 0x0E02 // 8M 177*53ee8cc1Swenshuai.xi #define FLASH_IC_MICRON_N25Q128 0x0E03 // 16M 178*53ee8cc1Swenshuai.xi 179*53ee8cc1Swenshuai.xi 180*53ee8cc1Swenshuai.xi // Flash Manufacture ID 181*53ee8cc1Swenshuai.xi #define MID_MXIC 0xC2 182*53ee8cc1Swenshuai.xi #define MID_WB 0xEF 183*53ee8cc1Swenshuai.xi #define MID_EON 0x1C 184*53ee8cc1Swenshuai.xi #define MID_ST 0x20 185*53ee8cc1Swenshuai.xi #define MID_SST 0xBF 186*53ee8cc1Swenshuai.xi #define MID_PMC 0x9D 187*53ee8cc1Swenshuai.xi #define MID_ATMEL 0x1F 188*53ee8cc1Swenshuai.xi #define MID_SPAN 0x01 189*53ee8cc1Swenshuai.xi #define MID_GD 0xC8 190*53ee8cc1Swenshuai.xi #define MID_MICRON 0x20 191*53ee8cc1Swenshuai.xi #define MID_ESMT 0x8C 192*53ee8cc1Swenshuai.xi 193*53ee8cc1Swenshuai.xi // Flash Storage Size 194*53ee8cc1Swenshuai.xi #define SIZE_1KB 0x400 195*53ee8cc1Swenshuai.xi #define SIZE_2KB 0x800 196*53ee8cc1Swenshuai.xi #define SIZE_4KB 0x1000 197*53ee8cc1Swenshuai.xi #define SIZE_8KB 0x2000 198*53ee8cc1Swenshuai.xi #define SIZE_16KB 0x4000 199*53ee8cc1Swenshuai.xi #define SIZE_32KB 0x8000 200*53ee8cc1Swenshuai.xi #define SIZE_64KB 0x10000 201*53ee8cc1Swenshuai.xi #define SIZE_128KB 0x20000 202*53ee8cc1Swenshuai.xi #define SIZE_256KB 0x40000 203*53ee8cc1Swenshuai.xi #define SIZE_512KB 0x80000 204*53ee8cc1Swenshuai.xi #define SIZE_1MB 0x100000 205*53ee8cc1Swenshuai.xi #define SIZE_2MB 0x200000 206*53ee8cc1Swenshuai.xi #define SIZE_4MB 0x400000 207*53ee8cc1Swenshuai.xi #define SIZE_8MB 0x800000 208*53ee8cc1Swenshuai.xi #define SIZE_16MB 0x1000000 209*53ee8cc1Swenshuai.xi 210*53ee8cc1Swenshuai.xi #ifndef UNUSED 211*53ee8cc1Swenshuai.xi #define UNUSED(x) ((x)=(x)) 212*53ee8cc1Swenshuai.xi #endif 213*53ee8cc1Swenshuai.xi 214*53ee8cc1Swenshuai.xi // ISP_DEV_SEL 215*53ee8cc1Swenshuai.xi #define ISP_DEV_PMC BITS(2:0, 0) 216*53ee8cc1Swenshuai.xi #define ISP_DEV_NEXTFLASH BITS(2:0, 1) 217*53ee8cc1Swenshuai.xi #define ISP_DEV_ST BITS(2:0, 2) 218*53ee8cc1Swenshuai.xi #define ISP_DEV_SST BITS(2:0, 3) 219*53ee8cc1Swenshuai.xi #define ISP_DEV_ATMEL BITS(2:0, 4) 220*53ee8cc1Swenshuai.xi 221*53ee8cc1Swenshuai.xi // ISP_SPI_ENDIAN_SEL 222*53ee8cc1Swenshuai.xi #define ISP_SPI_ENDIAN_BIG BITS(0:0, 1) 223*53ee8cc1Swenshuai.xi #define ISP_SPI_ENDIAN_LITTLE BITS(0:0, 0) 224*53ee8cc1Swenshuai.xi 225*53ee8cc1Swenshuai.xi 226*53ee8cc1Swenshuai.xi #define NUMBER_OF_SERFLASH_SECTORS (_hal_SERFLASH.u32NumSec) 227*53ee8cc1Swenshuai.xi #define SERFLASH_SECTOR_SIZE (_hal_SERFLASH.u32SecSize) 228*53ee8cc1Swenshuai.xi #define SERFLASH_PAGE_SIZE (_hal_SERFLASH.u16PageSize) 229*53ee8cc1Swenshuai.xi #define SERFLASH_MAX_CHIP_WR_DONE_TIMEOUT (_hal_SERFLASH.u16MaxChipWrDoneTimeout) 230*53ee8cc1Swenshuai.xi #define SERFLASH_WRSR_BLK_PROTECT (_hal_SERFLASH.u8WrsrBlkProtect) 231*53ee8cc1Swenshuai.xi #define ISP_DEV_SEL (_hal_SERFLASH.u16DevSel) 232*53ee8cc1Swenshuai.xi #define ISP_SPI_ENDIAN_SEL (_hal_SERFLASH.u16SpiEndianSel) 233*53ee8cc1Swenshuai.xi 234*53ee8cc1Swenshuai.xi 235*53ee8cc1Swenshuai.xi #define DEBUG_SER_FLASH(debug_level, x) do { if (_u8SERFLASHDbgLevel >= (debug_level)) (x); } while(0) 236*53ee8cc1Swenshuai.xi #define WAIT_SFSH_CS_STAT() {while(ISP_READ(REG_ISP_SPI_CHIP_SELE_BUSY) == SFSH_CHIP_SELE_SWITCH){}} 237*53ee8cc1Swenshuai.xi 238*53ee8cc1Swenshuai.xi #define SERFLASH_BLOCK_SIZE 0x10000 239*53ee8cc1Swenshuai.xi 240*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 241*53ee8cc1Swenshuai.xi // Type and Structure 242*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 243*53ee8cc1Swenshuai.xi 244*53ee8cc1Swenshuai.xi typedef enum 245*53ee8cc1Swenshuai.xi { 246*53ee8cc1Swenshuai.xi FLASH_ID0 = 0x00, 247*53ee8cc1Swenshuai.xi FLASH_ID1 = 0x01, 248*53ee8cc1Swenshuai.xi FLASH_ID2 = 0x02, 249*53ee8cc1Swenshuai.xi FLASH_ID3 = 0x03 250*53ee8cc1Swenshuai.xi } EN_FLASH_ID; 251*53ee8cc1Swenshuai.xi 252*53ee8cc1Swenshuai.xi typedef enum 253*53ee8cc1Swenshuai.xi { 254*53ee8cc1Swenshuai.xi WP_AREA_EXACTLY_AVAILABLE, 255*53ee8cc1Swenshuai.xi WP_AREA_PARTIALLY_AVAILABLE, 256*53ee8cc1Swenshuai.xi WP_AREA_NOT_AVAILABLE, 257*53ee8cc1Swenshuai.xi WP_TABLE_NOT_SUPPORT, 258*53ee8cc1Swenshuai.xi } EN_WP_AREA_EXISTED_RTN; 259*53ee8cc1Swenshuai.xi 260*53ee8cc1Swenshuai.xi typedef enum 261*53ee8cc1Swenshuai.xi { 262*53ee8cc1Swenshuai.xi FLASH_ERASE_04K = SPI_CMD_SE, 263*53ee8cc1Swenshuai.xi FLASH_ERASE_32K = SPI_CMD_32BE, 264*53ee8cc1Swenshuai.xi FLASH_ERASE_64K = SPI_CMD_64BE 265*53ee8cc1Swenshuai.xi } EN_FLASH_ERASE; 266*53ee8cc1Swenshuai.xi 267*53ee8cc1Swenshuai.xi typedef struct 268*53ee8cc1Swenshuai.xi { 269*53ee8cc1Swenshuai.xi MS_U8 u8BlockProtectBits; // Block Protection Bits 270*53ee8cc1Swenshuai.xi MS_U32 u32LowerBound; 271*53ee8cc1Swenshuai.xi MS_U32 u32UpperBound; 272*53ee8cc1Swenshuai.xi } ST_WRITE_PROTECT; 273*53ee8cc1Swenshuai.xi 274*53ee8cc1Swenshuai.xi typedef enum 275*53ee8cc1Swenshuai.xi { 276*53ee8cc1Swenshuai.xi E_SINGLE_MODE, 277*53ee8cc1Swenshuai.xi E_FAST_MODE, 278*53ee8cc1Swenshuai.xi E_DUAL_D_MODE, 279*53ee8cc1Swenshuai.xi E_DUAL_AD_MODE, 280*53ee8cc1Swenshuai.xi E_QUAD_MODE, 281*53ee8cc1Swenshuai.xi }SPI_READ_MODE; 282*53ee8cc1Swenshuai.xi 283*53ee8cc1Swenshuai.xi 284*53ee8cc1Swenshuai.xi typedef struct 285*53ee8cc1Swenshuai.xi { 286*53ee8cc1Swenshuai.xi MS_U16 u16Start; // Start block # of special block size 287*53ee8cc1Swenshuai.xi MS_U16 u16End; // End block # of special block size 288*53ee8cc1Swenshuai.xi MS_U32 au32SizeList[8]; // List of special block sizes. Total size must be equal to FLASH_BLOCK_SIZE 289*53ee8cc1Swenshuai.xi } ST_SPECIAL_BLOCKS; 290*53ee8cc1Swenshuai.xi 291*53ee8cc1Swenshuai.xi typedef struct 292*53ee8cc1Swenshuai.xi { 293*53ee8cc1Swenshuai.xi MS_U16 u16FlashType; // flash type 294*53ee8cc1Swenshuai.xi MS_U8 u8MID; // Manufacture ID 295*53ee8cc1Swenshuai.xi MS_U8 u8DID0; // Device ID (memory type) 296*53ee8cc1Swenshuai.xi MS_U8 u8DID1; // Device ID (memory capacity) 297*53ee8cc1Swenshuai.xi 298*53ee8cc1Swenshuai.xi ST_WRITE_PROTECT *pWriteProtectTable; 299*53ee8cc1Swenshuai.xi ST_SPECIAL_BLOCKS *pSpecialBlocks; 300*53ee8cc1Swenshuai.xi 301*53ee8cc1Swenshuai.xi MS_U32 u32FlashSize; // Flash Size 302*53ee8cc1Swenshuai.xi MS_U32 u32NumSec; // NUMBER_OF_SERFLASH_SECTORS // number of sectors 303*53ee8cc1Swenshuai.xi MS_U32 u32SecSize; // SERFLASH_SECTOR_SIZE // sector size 304*53ee8cc1Swenshuai.xi MS_U16 u16PageSize; // SERFLASH_PAGE_SIZE // page size 305*53ee8cc1Swenshuai.xi MS_U16 u16MaxChipWrDoneTimeout; // SERFLASH_MAX_CHIP_WR_DONE_TIMEOUT // max timeout for chip write done 306*53ee8cc1Swenshuai.xi MS_U8 u8WrsrBlkProtect; // SERFLASH_WRSR_BLK_PROTECT // BP bits @ Serial Flash Status Register 307*53ee8cc1Swenshuai.xi MS_U16 u16DevSel; // ISP_DEV_SEL // reg_device_select 308*53ee8cc1Swenshuai.xi MS_U16 u16SpiEndianSel; // ISP_SPI_ENDIAN_SEL // reg_endian_sel_spi 309*53ee8cc1Swenshuai.xi MS_BOOL b2XREAD; 310*53ee8cc1Swenshuai.xi } hal_SERFLASH_t; 311*53ee8cc1Swenshuai.xi 312*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 313*53ee8cc1Swenshuai.xi // Function and Variable 314*53ee8cc1Swenshuai.xi //------------------------------------------------------------------------------------------------- 315*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_SetCKG(SPI_DrvCKG eCkgSpi); 316*53ee8cc1Swenshuai.xi extern void HAL_SERFLASH_ClkDiv(SPI_DrvClkDiv eClkDivSpi); 317*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_SetMode(MS_BOOL bXiuRiu); 318*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_Set2XREAD(MS_BOOL b2XMode); 319*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_ChipSelect(MS_U8 u8FlashIndex); 320*53ee8cc1Swenshuai.xi extern void HAL_SERFLASH_Config(MS_VIRT u32PMRegBaseAddr, MS_VIRT u32NonPMRegBaseAddr, MS_VIRT u32XiuBaseAddr); 321*53ee8cc1Swenshuai.xi extern void HAL_SERFLASH_Init(void); 322*53ee8cc1Swenshuai.xi extern void HAL_SERFLASH_SetGPIO(MS_BOOL bSwitch); 323*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_DetectType(void); 324*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_DetectSize(MS_U32 *u32FlashSize); 325*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_EraseChip(void); 326*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_AddressToBlock(MS_U32 u32FlashAddr, MS_U32 *pu32BlockIndex); 327*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_BlockToAddress(MS_U32 u32BlockIndex, MS_U32 *pu32FlashAddr); 328*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_BlockErase(MS_U32 u32StartBlock,MS_U32 u32EndBlock,MS_BOOL bWait); 329*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_SectorErase(MS_U32 u32SectorAddress); 330*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_CheckWriteDone(void); 331*53ee8cc1Swenshuai.xi 332*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_Write(MS_U32 u32Addr, MS_U32 u32Size, MS_U8 *pu8Data); 333*53ee8cc1Swenshuai.xi 334*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_Read(MS_U32 u32Addr, MS_U32 u32Size, MS_U8 *pu8Data); 335*53ee8cc1Swenshuai.xi 336*53ee8cc1Swenshuai.xi 337*53ee8cc1Swenshuai.xi extern EN_WP_AREA_EXISTED_RTN HAL_SERFLASH_WP_Area_Existed(MS_U32 u32UpperBound, MS_U32 u32LowerBound, MS_U8 *pu8BlockProtectBits); 338*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_WriteProtect_Area(MS_BOOL bEnableAllArea, MS_U8 u8BlockProtectBits); 339*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_WriteProtect(MS_BOOL bEnable); 340*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_ReadID(MS_U8 *pu8Data, MS_U32 u32Size); 341*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_ReadREMS4(MS_U8 * pu8Data, MS_U32 u32Size); 342*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_DMA(MS_U32 u32FlashStart, MS_U32 u32DRAMStart, MS_U32 u32Size); 343*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_ReadStatusReg(MS_U8 *pu8StatusReg); 344*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_ReadStatusReg2(MS_U8 *pu8StatusReg); 345*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_WriteStatusReg(MS_U16 u16StatusReg); 346*53ee8cc1Swenshuai.xi //#if MXIC_ONLY 347*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SPI_EnterIBPM(void); 348*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SPI_SingleBlockLock(MS_PHYADDR u32FlashAddr, MS_BOOL bLock); 349*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SPI_GangBlockLock(MS_BOOL bLock); 350*53ee8cc1Swenshuai.xi extern MS_U8 HAL_SPI_ReadBlockStatus(MS_PHYADDR u32FlashAddr); 351*53ee8cc1Swenshuai.xi extern MS_U64 HAL_SERFLASH_ReadUID(void); 352*53ee8cc1Swenshuai.xi //#endif//MXIC_ONLY 353*53ee8cc1Swenshuai.xi // DON'T USE THESE DIRECTLY 354*53ee8cc1Swenshuai.xi extern hal_SERFLASH_t _hal_SERFLASH; 355*53ee8cc1Swenshuai.xi extern MS_U8 _u8SERFLASHDbgLevel; 356*53ee8cc1Swenshuai.xi extern MS_BOOL _bIBPM; 357*53ee8cc1Swenshuai.xi extern MS_BOOL _bWPPullHigh; 358*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_WriteProtect_Area_Lookup(MS_U32 u32ProtectSpace, MS_U32 u32NonProtectSpace, MS_U8 *pu8BlockProtectBits); 359*53ee8cc1Swenshuai.xi extern MS_U32 HAL_SERFLASH_WriteProtect_Area_Boundary(void); 360*53ee8cc1Swenshuai.xi /*spasion flash DYB unlock*/ 361*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_SERFLASH_SPSNDYB_UNLOCK(MS_U32 u32StartBlock, MS_U32 u32EndBlock); 362*53ee8cc1Swenshuai.xi 363*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_FSP_BlockErase(MS_U32 u32FlashAddr, EN_FLASH_ERASE eSize); 364*53ee8cc1Swenshuai.xi 365*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_FSP_Write(MS_U32 u32Addr, MS_U32 u32DataSize, MS_U8 *pu8Data); 366*53ee8cc1Swenshuai.xi 367*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_FSP_Write_Burst(MS_U32 u32Addr, MS_U32 u32Size, MS_U8 *pu8Data); 368*53ee8cc1Swenshuai.xi 369*53ee8cc1Swenshuai.xi extern MS_BOOL HAL_FSP_Read(MS_U32 u32Addr, MS_U32 u32DataSize, MS_U8 *pu8Data); 370*53ee8cc1Swenshuai.xi extern void HAL_FSP_Entry(void); 371*53ee8cc1Swenshuai.xi extern void HAL_FSP_Exit(void); 372*53ee8cc1Swenshuai.xi extern void HAL_SERFLASH_SelectReadMode(SPI_READ_MODE eReadMode); 373*53ee8cc1Swenshuai.xi #endif // _HAL_SERFLASH_H_ 374