Micron MT29F NAND driver
nand_MT29F_lld.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003   Filename:    nand_MT29F_lld.h
00004   Description:  Library routines for the Software Drivers for NAND flash
00005 
00006   © 2012 Micron Technology, Inc. All Rights Reserved
00007 
00008  You have a license to reproduce, display, perform, produce derivative works of,
00009  and distribute (in original or modified form) the Program, provided that you
00010  explicitly agree to the following disclaimer:
00011 
00012    THIS PROGRAM IS PROVIDED "AS IT IS" WITHOUT WARRANTY OF ANY KIND, EITHER
00013    EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTY
00014    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
00015    AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
00016    PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
00017    REPAIR OR CORRECTION.
00018 
00019 ********************************************************************************
00020 
00021    Version History.
00022 
00023    Ver.           No    Date        Comments
00024 
00025    First release  1.0      07/2012
00026    Second release 1.1      03/2013     Added OTP functions
00027 
00028 *******************************************************************************/
00029 
00030 #include "common.h"
00031 #include "nand_hw_if.h"
00032 
00033 /******************************************************************************
00034  *                         USER SETTINGS AREA
00035  *****************************************************************************/
00036 
00040 #define LITTLE_ENDIAN
00041 // #define BIG_ENDIAN
00042 
00046 #define TIMEOUT_SUPPORT
00047 
00048 #ifdef TIMEOUT_SUPPORT
00049 
00050 #define TIME_OUT_SECOND       2
00051 
00057 #define CLOCKS_PER_SEC        1000
00058 #endif
00059 
00060 /******************************************************************************
00061  *                      END OF USER SETTINGS AREA
00062  *                (Please do not modify the following lines)
00063  *****************************************************************************/
00064 
00065 /*
00066  * NAND commands and constants set
00067  */
00068 
00069 #define MICRON_NAND_DEFAULT
00070 
00075 typedef bus_t flash_width;
00076 
00077 /*
00078  * Data type and structure
00079  */
00080 
00082 typedef struct nand_address_t {
00083 
00084    /* LUN */
00085    MT_uint32 lun;
00086 
00087    /* block address */
00088    MT_uint32 block;
00089 
00090    /* page address */
00091    MT_uint32 page;
00092 
00093    /* column address */
00094    MT_uint32 column;
00095 
00096 } nand_addr_t;
00097 
00099 typedef struct parameter_page_t {
00101    char signature[5];
00102 
00104    MT_uint16 rev_num;
00105 
00107    MT_uint16 feature;
00108 
00110    MT_uint16 command;
00111 
00113    char manufacturer[13];
00114 
00116    char model[21];
00117 
00119    MT_uint8 jedec_id;
00120 
00122    MT_uint16 date_code;
00123 
00125    MT_uint32 data_bytes_per_page;
00126 
00128    MT_uint16 spare_bytes_per_page;
00129 
00131    MT_uint32 data_bytes_per_partial_page;
00132 
00134    MT_uint16 spare_bytes_per_partial_page;
00135 
00137    MT_uint32 pages_per_block;
00138 
00140    MT_uint32 blocks_per_lun;
00141 
00143    MT_uint8 luns_per_ce;
00144 
00146    MT_uint8 num_addr_cycles;
00147 
00149    MT_uint8 bit_per_cell;
00150 
00152    MT_uint16 max_bad_blocks_per_lun;
00153 
00155    MT_uint16 block_endurance;
00156 
00158    MT_uint8 guarenteed_valid_blocks;
00159 
00161    MT_uint16 block_endurance_guarenteed_valid;
00162 
00164    MT_uint8 num_programs_per_page;
00165 
00167    MT_uint8 partial_prog_attr;
00168 
00170    MT_uint8 num_ECC_bits_correctable;
00171 
00173    MT_uint8 num_interleaved_addr_bits;
00174 
00176    MT_uint8 interleaved_op_attr;
00177 
00178 } param_page_t;
00179 
00180 /*
00181  * List of features supported
00182  */
00183 #ifdef MICRON_NAND_DEFAULT
00184    #define SUPPORTED_EXTERNAL_VPP                        0x1000
00185    #define SUPPORTED_VOLUME_ADDRESSING                   0x0800
00186    #define SUPPORTED_NV_DDR2                          0x0400
00187    #define SUPPORTED_EZ_NAND                          0x0200
00188    #define SUPPORTED_PROGRAM_PAGE_REGISTER_CLEAR_ENHANCEMENT   0x0100
00189    #define SUPPORTED_EXTENDED_PARAMETER_PAGE             0x0080
00190    #define SUPPORTED_MULTIPLANE_READ_OPERATIONS          0x0040
00191    #define SUPPORTED_NV_DDR                           0x0020
00192    #define SUPPORTED_ODD_TO_EVEN_PAGE_COPYBACK              0x0010
00193    #define SUPPORTED_MULTIPLANE_PROGRAM_AND_ERASE_OPERATIONS   0x0008
00194    #define SUPPORTED_NON_SEQUENTIAL_PAGE_PROGRAMMING        0x0004
00195    #define SUPPORTED_MULTIPLE_LUN_OPERATIONS             0x0002
00196    #define SUPPORTED_16_BIT_DATA_BUS_WIDTH                  0x0001
00197 #endif
00198 
00199 /*
00200  * List of optional commands supported
00201  */
00202 #ifdef MICRON_NAND_DEFAULT
00203    #define OPTIONAL_CMD_ODT_CONFIGURE                    0x0800
00204    #define OPTIONAL_CMD_VOLUME_SELECT                    0x0400
00205    #define OPTIONAL_CMD_RESET_LUN                        0x0200
00206    #define OPTIONAL_CMD_SMALL_DATA_MOVE                  0x0100
00207    #define OPTIONAL_CMD_CHANGE_ROW_ADDRESS                  0x0080
00208    #define OPTIONAL_CMD_CHANGE_READ_COLUMN_ENHANCED         0x0040
00209    #define OPTIONAL_CMD_READ_UNIQUE_ID                   0x0020
00210    #define OPTIONAL_CMD_COPYBACK                      0x0010
00211    #define OPTIONAL_CMD_READ_STATUS_ENHANCED             0x0008
00212    #define OPTIONAL_CMD_GET_FEATURES_AND_SET_FEATURES       0x0004
00213    #define OPTIONAL_CMD_READ_CACHE_COMMANDS              0x0002
00214    #define OPTIONAL_CMD_PAGE_CACHE_PROGRAM_COMMAND          0x0001
00215 #endif
00216 
00217 /*
00218  * NAND Command set
00219  */
00220 #ifdef MICRON_NAND_DEFAULT
00221    #define CMD_RESET                   0xFF
00222    #define CMD_READID                     0x90
00223    #define CMD_READ_PARAM_PAGE               0xEC
00224    #define  CMD_READ_UNIQ_ID              0xED
00225    #define CMD_SET_FEATURE                0xEF
00226    #define CMD_GET_FEATURE                0xEE
00227    #define CMD_READ_STATUS                0x70
00228    #define CMD_READ_STATUS_ENHANCED       0x78
00229    #define CMD_ERASE_BLOCK                0x60
00230    #define CMD_ERASE_BLOCK_CONFIRM           0xD0
00231    #define CMD_READ_MODE                  0x00
00232    #define CMD_READ_CONFIRM               0x30
00233    #define CMD_PAGE_PROGRAM               0x80
00234    #define CMD_PAGE_PROGRAM_CONFIRM       0x10
00235    #define CMD_READ_INTERNAL_DATA_MOVE       0x35
00236    #define CMD_PROGRAM_INTERNAL_DATA_MOVE    0x85
00237    #define CMD_LOCK                    0x2A
00238    #define CMD_BLOCK_UNLOCK_LOW           0x23
00239    #define CMD_BLOCK_UNLOCK_HIGH          0x24
00240    #define CMD_BLOCK_LOCK_READ_STATUS        0x7A
00241 #endif
00242 
00243 /*
00244  * Significant addresses
00245  */
00246 #ifdef MICRON_NAND_DEFAULT
00247    #define ADDR_READ_ID                0x00
00248    #define ADDR_READ_ID_ONFI              0x20
00249    #define ADDR_READ_UNIQ_ID              0x00
00250    #define ADDR_PARAM_PAGE                0x00
00251    #define ADDR_READ_UNIQ_ID              0x00
00252    #define ADDR_FEATURE_TIMING               0x01
00253    #define ADDR_FEATURE_OUTPUT_STRENGTH      0x80
00254    #define ADDR_FEATURE_RB_STRENGTH       0x81
00255    #define ADDR_FEATURE_ARRAY_OPMODE         0x90
00256 #endif
00257 
00261 #ifdef MICRON_NAND_DEFAULT
00262    #define NUM_OF_READID_BYTES               5
00263    #define NUM_OF_READIDONFI_BYTES           4
00264    #define NUM_OF_READUNIQUEID_BYTES         16
00265    #define NUM_OF_PPAGE_BYTES             129
00266    #define NUM_OF_ADDR_CYCLE              5
00267    #define ONFI_SIGNATURE_LENGHT          4
00268    #define NUM_OF_UNIQUEID_BYTES          32
00269 #endif
00270 
00271 /*
00272  * Feature constants
00273  */
00274 #ifdef MICRON_NAND_DEFAULT
00275    /* Timing mode */
00276    #define FEATURE_TIMING_MODE0           0x00
00277    #define FEATURE_TIMING_MODE1           0x01
00278    #define FEATURE_TIMING_MODE2           0x02
00279    #define FEATURE_TIMING_MODE3           0x03
00280    #define FEATURE_TIMING_MODE4           0x04
00281    #define FEATURE_TIMING_MODE5           0x05
00282    /* I/O drive strength */
00283    #define FEATURE_OUTPUT_STRENGH_100        0x00
00284    #define FEATURE_OUTPUT_STRENGH_75         0x01
00285    #define FEATURE_OUTPUT_STRENGH_50         0x02
00286    #define FEATURE_OUTPUT_STRENGH_25         0x03
00287    /* R/B# Pull-Down strength */
00288    #define FEATURE_RB_STRENGH_100            0x00
00289    #define FEATURE_RB_STRENGH_75          0x01
00290    #define FEATURE_RB_STRENGH_50          0x02
00291    #define FEATURE_RB_STRENGH_25          0x03
00292    /* Array operation mode */
00293    #define FEATURE_ARRAY_NORMAL           0x00
00294    #define FEATURE_ARRAY_OTP_OPERATION       0x01
00295    #define FEATURE_ARRAY_OTP_PROTECTION      0x03
00296    #define FEATURE_ARRAY_DISABLE_ECC         0x00
00297    #define FEATURE_ARRAY_ENABLE_ECC       0x08
00298 #endif
00299 
00300 /*
00301  * Time constants, in ns (see the datasheet for more details)
00302  */
00303 #ifdef MICRON_NAND_DEFAULT
00304    #define TIME_WHR                    60
00305    #define TIME_WB                        100
00306    #define TIME_ADL                    70
00307 #endif
00308 
00309 /*
00310  * Driver status constants
00311  */
00312 
00313 /* normal driver state */
00314 #define DRIVER_STATUS_INITIALIZED                  0
00315 
00316 /* driver is not initialized */
00317 #define DRIVER_STATUS_NOT_INITIALIZED              1
00318 
00319 /*
00320  * Status register definition
00321  */
00322 #ifdef MICRON_NAND_DEFAULT
00323    #define  STATUS_FAIL                   0x00
00324    #define  STATUS_FAILC                  0x01
00325    #define  STATUS_ARDY                   0x20
00326    #define  STATUS_RDY                    0x40
00327    #define  STATUS_WRITE_PROTECTED           0x80
00328 #endif
00329 
00330 /*
00331  * Block lock status register definition
00332  */
00333 #ifdef MICRON_NAND_DEFAULT
00334    #define BLOCK_LOCKED_TIGHT             0x01
00335    #define BLOCK_LOCKED                0x02
00336    #define BLOCK_UNLOCKED_DEV_LOCKED         0x05
00337    #define BLOCK_UNLOCKED_DEV_NOT_LOCKED     0x06
00338 #endif
00339 
00340 /*
00341  * Function return constants
00342  */
00343 #define NAND_SUCCESS                   0x00
00344 #define  NAND_GENERIC_FAIL                0x10
00345 #define NAND_BAD_PARAMETER_PAGE              0x20
00346 #define  NAND_INVALID_NAND_ADDRESS           0x30
00347 #define NAND_INVALID_LENGHT                  0x31
00348 #define NAND_ERASE_FAILED                 0x40
00349 #define NAND_ERASE_FAILED_WRITE_PROTECT         0x41
00350 #define NAND_PROGRAM_FAILED                  0x50
00351 #define NAND_PROGRAM_FAILED_WRITE_PROTECT    0x51
00352 #define NAND_READ_FAILED                  0x60
00353 #define NAND_UNSUPPORTED                  0xFD
00354 #ifdef TIMEOUT_SUPPORT
00355    #define NAND_TIMEOUT                0xFE
00356 #endif
00357 
00358 #define NAND_UNIMPLEMENTED                0xFF
00359 
00360 /******************************************************************************
00361  *                         List of APIs
00362  *****************************************************************************/
00363 
00364 MT_uint8 Init_Driver(void);
00365 
00366 /* reset operations */
00367 MT_uint8 NAND_Reset(void);
00368 
00369 /* identification operations */
00370 MT_uint8 NAND_Read_ID(flash_width *buf);
00371 MT_uint8 NAND_Read_ID_ONFI(flash_width *buf);
00372 MT_uint8 NAND_Read_Param_Page(param_page_t *ppage);
00373 
00374 /* feature operations */
00375 MT_uint8 NAND_Get_Feature(flash_width feature_address, flash_width *subfeature);
00376 MT_uint8 NAND_Set_Feature(flash_width feature_address, flash_width subfeature);
00377 
00378 /* status operations */
00379 flash_width NAND_Read_Status();
00380 flash_width NAND_Read_Status_Enhanced(nand_addr_t addr);
00381 
00382 /* read operations */
00383 MT_uint8 NAND_Page_Read(nand_addr_t addr, flash_width *buffer, MT_uint32 lenght);
00384 MT_uint8 NAND_Spare_Read(nand_addr_t addr, flash_width *buffer, MT_uint32 lenght);
00385 
00386 /* erase operations */
00387 MT_uint8 NAND_Block_Erase(nand_addr_t addr);
00388 
00389 /* program operations */
00390 MT_uint8 NAND_Page_Program(nand_addr_t addr, flash_width *buffer, MT_uint32 lenght);
00391 MT_uint8 NAND_Spare_Program(nand_addr_t addr, flash_width *buffer, MT_uint32 lenght);
00392 
00393 /* internal data move operations */
00394 MT_uint8 NAND_Copy_Back(nand_addr_t src_addr, nand_addr_t dest_addr);
00395 
00396 /* block lock operations */
00397 MT_uint8 NAND_Lock(void);
00398 MT_uint8 NAND_Unlock(nand_addr_t start_block, nand_addr_t end_block);
00399 MT_uint8 NAND_Read_Lock_Status(nand_addr_t block_addr);
00400 
00401 /******************************************************************************
00402  *                   List of unimplemented APIs
00403  *****************************************************************************/
00404 
00405 /* identification operations */
00406 MT_uint8 NAND_Read_Unique_Id(void);
00407 
00408 /* cached operations */
00409 MT_uint8 NAND_Cache_Read(void);
00410 MT_uint8 NAND_Cache_Program(void);
00411 
00412 /* multi-plane operations */
00413 MT_uint8 NAND_Multiplane_Copy_Back(void);
00414 MT_uint8 NAND_Multiplane_Page_Program(void);
00415 MT_uint8 NAND_Multiplane_Block_Erase(void);
00416 
00417 /* block lock operations */
00418 MT_uint8 NAND_Lock_Down(void);
00419 MT_uint8 NAND_Unlock_Down(void);