1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
/*======================================================================================
* MODULE NAME: spi
* FILE NAME: spi_nand_flash.h
* DATE:
* VERSION: 1.00
* PURPOSE: To Provide SPI NAND Access interface.
* NOTES:
*
* AUTHOR :
*
* FUNCTIONS
* SPI_NAND_Flash_Init To provide interface for SPI NAND init.
* SPI_NAND_Flash_Get_Flash_Info To get system current flash info.
* SPI_NAND_Flash_Write_Nbyte To provide interface for Write N Bytes into SPI NAND Flash.
* SPI_NAND_Flash_Read_NByte To provide interface for Read N Bytes from SPI NAND Flash.
* SPI_NAND_Flash_Erase To provide interface for Erase SPI NAND Flash.
* SPI_NAND_Flash_Read_Byte To provide interface for read 1 Bytes from SPI NAND Flash.
* SPI_NAND_Flash_Read_DWord To provide interface for read Double Word from SPI NAND Flash.
*
* DEPENDENCIES
*
* * $History: $
* MODIFICTION HISTORY:
*======================================================================================
*/
#ifndef __SPI_NAND_FLASH_H__
#define __SPI_NAND_FLASH_H__
/* INCLUDE FILE DECLARATIONS --------------------------------------------------------- */
#include "types.h"
#include "ch341a_spi.h"
/* MACRO DECLARATIONS ---------------------------------------------------------------- */
#define SPI_NAND_FLASH_OOB_FREE_ENTRY_MAX 32
/* TYPE DECLARATIONS ----------------------------------------------------------------- */
typedef enum{
SPI_NAND_FLASH_READ_DUMMY_BYTE_PREPEND,
SPI_NAND_FLASH_READ_DUMMY_BYTE_APPEND,
SPI_NAND_FLASH_READ_DUMMY_BYTE_DEF_NO
} SPI_NAND_FLASH_READ_DUMMY_BYTE_T;
typedef enum{
SPI_NAND_FLASH_RTN_NO_ERROR = 0,
SPI_NAND_FLASH_RTN_PROBE_ERROR,
SPI_NAND_FLASH_RTN_ALIGNED_CHECK_FAIL,
SPI_NAND_FLASH_RTN_DETECTED_BAD_BLOCK,
SPI_NAND_FLASH_RTN_ERASE_FAIL,
SPI_NAND_FLASH_RTN_PROGRAM_FAIL,
SPI_NAND_FLASH_RTN_DEF_NO
} SPI_NAND_FLASH_RTN_T;
typedef enum{
SPI_NAND_FLASH_READ_SPEED_MODE_SINGLE = 0,
SPI_NAND_FLASH_READ_SPEED_MODE_DUAL,
SPI_NAND_FLASH_READ_SPEED_MODE_QUAD,
SPI_NAND_FLASH_READ_SPEED_MODE_DEF_NO
} SPI_NAND_FLASH_READ_SPEED_MODE_T;
typedef enum{
SPI_NAND_FLASH_WRITE_SPEED_MODE_SINGLE = 0,
SPI_NAND_FLASH_WRITE_SPEED_MODE_QUAD,
SPI_NAND_FLASH_WRITE_SPEED_MODE_DEF_NO
} SPI_NAND_FLASH_WRITE_SPEED_MODE_T;
typedef enum{
SPI_NAND_FLASH_DEBUG_LEVEL_0 = 0,
SPI_NAND_FLASH_DEBUG_LEVEL_1,
SPI_NAND_FLASH_DEBUG_LEVEL_2,
SPI_NAND_FLASH_DEBUG_LEVEL_DEF_NO
} SPI_NAND_FLASH_DEBUG_LEVEL_T;
/* Bitwise */
#define SPI_NAND_FLASH_FEATURE_NONE ( 0x00 )
#define SPI_NAND_FLASH_PLANE_SELECT_HAVE ( 0x01 << 0 )
#define SPI_NAND_FLASH_DIE_SELECT_1_HAVE ( 0x01 << 1 )
#define SPI_NAND_FLASH_DIE_SELECT_2_HAVE ( 0x01 << 2 )
struct SPI_NAND_FLASH_INFO_T {
u8 mfr_id;
u8 dev_id;
u8 dev_id_2;
const char *ptr_name;
u32 device_size; /* Flash total Size */
u32 page_size; /* Page Size */
u32 erase_size; /* Block Size */
u32 oob_size; /* Spare Area (OOB) Size */
SPI_NAND_FLASH_READ_DUMMY_BYTE_T dummy_mode;
SPI_NAND_FLASH_READ_SPEED_MODE_T read_mode;
SPI_NAND_FLASH_WRITE_SPEED_MODE_T write_mode;
u32 feature;
};
struct nand_info {
int mfr_id;
int dev_id;
char *name;
int numchips;
int chip_shift;
int page_shift;
int erase_shift;
int oob_shift;
int badblockpos;
int opcode_type;
};
struct ra_nand_chip {
struct nand_info *flash;
};
/* EXPORTED SUBPROGRAM SPECIFICATION ------------------------------------------------- */
/*------------------------------------------------------------------------------------
* FUNCTION: SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Init( long rom_base )
* PURPOSE : To provide interface for SPI NAND init.
* AUTHOR :
* CALLED BY
* -
* CALLS
* -
* PARAMs :
* INPUT : rom_base - The rom_base variable of this function.
* OUTPUT: None
* RETURN : SPI_RTN_NO_ERROR - Successful. Otherwise - Failed.
* NOTES :
* MODIFICTION HISTORY:
*
*------------------------------------------------------------------------------------
*/
SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Init( u32 rom_base );
/*------------------------------------------------------------------------------------
* FUNCTION: SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Get_Flash_Info( struct SPI_NAND_FLASH_INFO_T *ptr_rtn_into_t )
* PURPOSE : To get system current flash info.
* AUTHOR :
* CALLED BY
* -
* CALLS
* -
* PARAMs :
* INPUT : None
* OUTPUT: ptr_rtn_into_t - A pointer to the structure of the ptr_rtn_into_t variable.
* RETURN : SPI_RTN_NO_ERROR - Successful. Otherwise - Failed.
* NOTES :
* MODIFICTION HISTORY:
*
*------------------------------------------------------------------------------------
*/
SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Get_Flash_Info( struct SPI_NAND_FLASH_INFO_T *ptr_rtn_into_t);
/*------------------------------------------------------------------------------------
* FUNCTION: SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Write_Nbyte( u32 dst_addr,
* u32 len,
* u32 *ptr_rtn_len,
* u8* ptr_buf )
* PURPOSE : To provide interface for Write N Bytes into SPI NAND Flash.
* AUTHOR :
* CALLED BY
* -
* CALLS
* -
* PARAMs :
* INPUT : dst_addr - The dst_addr variable of this function.
* len - The len variable of this function.
* buf - The buf variable of this function.
* OUTPUT: rtn_len - The rtn_len variable of this function.
* RETURN : SPI_RTN_NO_ERROR - Successful. Otherwise - Failed.
* NOTES :
* MODIFICTION HISTORY:
*
*------------------------------------------------------------------------------------
*/
SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Write_Nbyte( u32 dst_addr,
u32 len,
u32 *ptr_rtn_len,
u8 *ptr_buf,
SPI_NAND_FLASH_WRITE_SPEED_MODE_T speed_mode );
/*------------------------------------------------------------------------------------
* FUNCTION: int SPI_NAND_Flash_Read_NByte( long addr,
* long len,
* long *retlen,
* char *buf )
* PURPOSE : To provide interface for Read N Bytes from SPI NAND Flash.
* AUTHOR :
* CALLED BY
* -
* CALLS
* -
* PARAMs :
* INPUT : addr - The addr variable of this function.
* len - The len variable of this function.
* retlen - The retlen variable of this function.
* buf - The buf variable of this function.
* OUTPUT: None
* RETURN : SPI_RTN_NO_ERROR - Successful. Otherwise - Failed.
* NOTES :
* MODIFICTION HISTORY:
*
*------------------------------------------------------------------------------------
*/
u32 SPI_NAND_Flash_Read_NByte( u32 addr,
u32 len,
u32 *retlen,
u8 *buf,
SPI_NAND_FLASH_READ_SPEED_MODE_T speed_mode,
SPI_NAND_FLASH_RTN_T *status );
/*------------------------------------------------------------------------------------
* FUNCTION: SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Erase( u32 dst_addr,
* u32 len )
* PURPOSE : To provide interface for Erase SPI NAND Flash.
* AUTHOR :
* CALLED BY
* -
* CALLS
* -
* PARAMs :
* INPUT : dst_addr - The dst_addr variable of this function.
* len - The len variable of this function.
* OUTPUT: None
* RETURN : SPI_RTN_NO_ERROR - Successful. Otherwise - Failed.
* NOTES :
* MODIFICTION HISTORY:
*
*------------------------------------------------------------------------------------
*/
SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Erase( u32 dst_addr,
u32 len );
/*------------------------------------------------------------------------------------
* FUNCTION: char SPI_NAND_Flash_Read_Byte( long addr )
* PURPOSE : To provide interface for read 1 Bytes from SPI NAND Flash.
* AUTHOR :
* CALLED BY
* -
* CALLS
* -
* PARAMs :
* INPUT : addr - The addr variable of this function.
* OUTPUT: None
* RETURN : SPI_RTN_NO_ERROR - Successful. Otherwise - Failed.
* NOTES :
* MODIFICTION HISTORY:
*
*------------------------------------------------------------------------------------
*/
unsigned char SPI_NAND_Flash_Read_Byte( unsigned long addr, SPI_NAND_FLASH_RTN_T *status);
/*------------------------------------------------------------------------------------
* FUNCTION: long SPI_NAND_Flash_Read_DWord( long addr )
* PURPOSE : To provide interface for read Double Word from SPI NAND Flash.
* AUTHOR :
* CALLED BY
* -
* CALLS
* -
* PARAMs :
* INPUT : addr - The addr variable of this function.
* OUTPUT: None
* RETURN : SPI_RTN_NO_ERROR - Successful. Otherwise - Failed.
* NOTES :
* MODIFICTION HISTORY:
*
*------------------------------------------------------------------------------------
*/
unsigned long SPI_NAND_Flash_Read_DWord( unsigned long addr, SPI_NAND_FLASH_RTN_T *status);
/*------------------------------------------------------------------------------------
* FUNCTION: void SPI_NAND_Flash_Clear_Read_Cache_Data( void )
* PURPOSE : To clear the cache data for read.
* (The next time to read data will get data from flash chip certainly.)
* AUTHOR :
* CALLED BY
* -
* CALLS
* -
* PARAMs :
* INPUT : None
* OUTPUT: None
* RETURN : SPI_RTN_NO_ERROR - Successful. Otherwise - Failed.
* NOTES :
* MODIFICTION HISTORY:
*
*------------------------------------------------------------------------------------
*/
void SPI_NAND_Flash_Clear_Read_Cache_Data( void );
SPI_NAND_FLASH_RTN_T SPI_NAND_Flash_Enable_OnDie_ECC( void );
SPI_NAND_FLASH_RTN_T spi_nand_erase_block ( u32 block_index);
#endif /* ifndef __SPI_NAND_FLASH_H__ */
/* End of [spi_nand_flash.h] package */
|