1331c2375SMasahiro Yamada /* 2331c2375SMasahiro Yamada * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org> 3331c2375SMasahiro Yamada * Steven J. Hill <sjhill@realitydiluted.com> 4331c2375SMasahiro Yamada * Thomas Gleixner <tglx@linutronix.de> 5331c2375SMasahiro Yamada * 6331c2375SMasahiro Yamada * SPDX-License-Identifier: GPL-2.0+ 7331c2375SMasahiro Yamada * 8331c2375SMasahiro Yamada * Info: 9331c2375SMasahiro Yamada * Contains standard defines and IDs for NAND flash devices 10331c2375SMasahiro Yamada * 11331c2375SMasahiro Yamada * Changelog: 12331c2375SMasahiro Yamada * See git changelog. 13331c2375SMasahiro Yamada */ 14331c2375SMasahiro Yamada #ifndef __LINUX_MTD_RAWNAND_H 15331c2375SMasahiro Yamada #define __LINUX_MTD_RAWNAND_H 16331c2375SMasahiro Yamada 17331c2375SMasahiro Yamada #include <config.h> 18331c2375SMasahiro Yamada 19331c2375SMasahiro Yamada #include <linux/compat.h> 20331c2375SMasahiro Yamada #include <linux/mtd/mtd.h> 21331c2375SMasahiro Yamada #include <linux/mtd/flashchip.h> 22331c2375SMasahiro Yamada #include <linux/mtd/bbm.h> 23331c2375SMasahiro Yamada 24331c2375SMasahiro Yamada struct mtd_info; 25*46c3d471SJörg Krause struct nand_chip; 26331c2375SMasahiro Yamada struct nand_flash_dev; 27331c2375SMasahiro Yamada struct device_node; 28331c2375SMasahiro Yamada 29*46c3d471SJörg Krause /* Get the flash and manufacturer id and lookup if the type is supported. */ 30*46c3d471SJörg Krause struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, 31*46c3d471SJörg Krause struct nand_chip *chip, 32*46c3d471SJörg Krause int *maf_id, int *dev_id, 33*46c3d471SJörg Krause struct nand_flash_dev *type); 34*46c3d471SJörg Krause 35331c2375SMasahiro Yamada /* Scan and identify a NAND device */ 36331c2375SMasahiro Yamada extern int nand_scan(struct mtd_info *mtd, int max_chips); 37331c2375SMasahiro Yamada /* 38331c2375SMasahiro Yamada * Separate phases of nand_scan(), allowing board driver to intervene 39331c2375SMasahiro Yamada * and override command or ECC setup according to flash type. 40331c2375SMasahiro Yamada */ 41331c2375SMasahiro Yamada extern int nand_scan_ident(struct mtd_info *mtd, int max_chips, 42331c2375SMasahiro Yamada struct nand_flash_dev *table); 43331c2375SMasahiro Yamada extern int nand_scan_tail(struct mtd_info *mtd); 44331c2375SMasahiro Yamada 45331c2375SMasahiro Yamada /* Free resources held by the NAND device */ 46331c2375SMasahiro Yamada extern void nand_release(struct mtd_info *mtd); 47331c2375SMasahiro Yamada 48331c2375SMasahiro Yamada /* Internal helper for board drivers which need to override command function */ 49331c2375SMasahiro Yamada extern void nand_wait_ready(struct mtd_info *mtd); 50331c2375SMasahiro Yamada 51331c2375SMasahiro Yamada /* 52331c2375SMasahiro Yamada * This constant declares the max. oobsize / page, which 53331c2375SMasahiro Yamada * is supported now. If you add a chip with bigger oobsize/page 54331c2375SMasahiro Yamada * adjust this accordingly. 55331c2375SMasahiro Yamada */ 56331c2375SMasahiro Yamada #define NAND_MAX_OOBSIZE 1664 57331c2375SMasahiro Yamada #define NAND_MAX_PAGESIZE 16384 58331c2375SMasahiro Yamada 59331c2375SMasahiro Yamada /* 60331c2375SMasahiro Yamada * Constants for hardware specific CLE/ALE/NCE function 61331c2375SMasahiro Yamada * 62331c2375SMasahiro Yamada * These are bits which can be or'ed to set/clear multiple 63331c2375SMasahiro Yamada * bits in one go. 64331c2375SMasahiro Yamada */ 65331c2375SMasahiro Yamada /* Select the chip by setting nCE to low */ 66331c2375SMasahiro Yamada #define NAND_NCE 0x01 67331c2375SMasahiro Yamada /* Select the command latch by setting CLE to high */ 68331c2375SMasahiro Yamada #define NAND_CLE 0x02 69331c2375SMasahiro Yamada /* Select the address latch by setting ALE to high */ 70331c2375SMasahiro Yamada #define NAND_ALE 0x04 71331c2375SMasahiro Yamada 72331c2375SMasahiro Yamada #define NAND_CTRL_CLE (NAND_NCE | NAND_CLE) 73331c2375SMasahiro Yamada #define NAND_CTRL_ALE (NAND_NCE | NAND_ALE) 74331c2375SMasahiro Yamada #define NAND_CTRL_CHANGE 0x80 75331c2375SMasahiro Yamada 76331c2375SMasahiro Yamada /* 77331c2375SMasahiro Yamada * Standard NAND flash commands 78331c2375SMasahiro Yamada */ 79331c2375SMasahiro Yamada #define NAND_CMD_READ0 0 80331c2375SMasahiro Yamada #define NAND_CMD_READ1 1 81331c2375SMasahiro Yamada #define NAND_CMD_RNDOUT 5 82331c2375SMasahiro Yamada #define NAND_CMD_PAGEPROG 0x10 83331c2375SMasahiro Yamada #define NAND_CMD_READOOB 0x50 84331c2375SMasahiro Yamada #define NAND_CMD_ERASE1 0x60 85331c2375SMasahiro Yamada #define NAND_CMD_STATUS 0x70 86331c2375SMasahiro Yamada #define NAND_CMD_SEQIN 0x80 87331c2375SMasahiro Yamada #define NAND_CMD_RNDIN 0x85 88331c2375SMasahiro Yamada #define NAND_CMD_READID 0x90 89331c2375SMasahiro Yamada #define NAND_CMD_ERASE2 0xd0 90331c2375SMasahiro Yamada #define NAND_CMD_PARAM 0xec 91331c2375SMasahiro Yamada #define NAND_CMD_GET_FEATURES 0xee 92331c2375SMasahiro Yamada #define NAND_CMD_SET_FEATURES 0xef 93331c2375SMasahiro Yamada #define NAND_CMD_RESET 0xff 94331c2375SMasahiro Yamada 95331c2375SMasahiro Yamada #define NAND_CMD_LOCK 0x2a 96331c2375SMasahiro Yamada #define NAND_CMD_UNLOCK1 0x23 97331c2375SMasahiro Yamada #define NAND_CMD_UNLOCK2 0x24 98331c2375SMasahiro Yamada 99331c2375SMasahiro Yamada /* Extended commands for large page devices */ 100331c2375SMasahiro Yamada #define NAND_CMD_READSTART 0x30 101331c2375SMasahiro Yamada #define NAND_CMD_RNDOUTSTART 0xE0 102331c2375SMasahiro Yamada #define NAND_CMD_CACHEDPROG 0x15 103331c2375SMasahiro Yamada 104331c2375SMasahiro Yamada /* Extended commands for AG-AND device */ 105331c2375SMasahiro Yamada /* 106331c2375SMasahiro Yamada * Note: the command for NAND_CMD_DEPLETE1 is really 0x00 but 107331c2375SMasahiro Yamada * there is no way to distinguish that from NAND_CMD_READ0 108331c2375SMasahiro Yamada * until the remaining sequence of commands has been completed 109331c2375SMasahiro Yamada * so add a high order bit and mask it off in the command. 110331c2375SMasahiro Yamada */ 111331c2375SMasahiro Yamada #define NAND_CMD_DEPLETE1 0x100 112331c2375SMasahiro Yamada #define NAND_CMD_DEPLETE2 0x38 113331c2375SMasahiro Yamada #define NAND_CMD_STATUS_MULTI 0x71 114331c2375SMasahiro Yamada #define NAND_CMD_STATUS_ERROR 0x72 115331c2375SMasahiro Yamada /* multi-bank error status (banks 0-3) */ 116331c2375SMasahiro Yamada #define NAND_CMD_STATUS_ERROR0 0x73 117331c2375SMasahiro Yamada #define NAND_CMD_STATUS_ERROR1 0x74 118331c2375SMasahiro Yamada #define NAND_CMD_STATUS_ERROR2 0x75 119331c2375SMasahiro Yamada #define NAND_CMD_STATUS_ERROR3 0x76 120331c2375SMasahiro Yamada #define NAND_CMD_STATUS_RESET 0x7f 121331c2375SMasahiro Yamada #define NAND_CMD_STATUS_CLEAR 0xff 122331c2375SMasahiro Yamada 123331c2375SMasahiro Yamada #define NAND_CMD_NONE -1 124331c2375SMasahiro Yamada 125331c2375SMasahiro Yamada /* Status bits */ 126331c2375SMasahiro Yamada #define NAND_STATUS_FAIL 0x01 127331c2375SMasahiro Yamada #define NAND_STATUS_FAIL_N1 0x02 128331c2375SMasahiro Yamada #define NAND_STATUS_TRUE_READY 0x20 129331c2375SMasahiro Yamada #define NAND_STATUS_READY 0x40 130331c2375SMasahiro Yamada #define NAND_STATUS_WP 0x80 131331c2375SMasahiro Yamada 132331c2375SMasahiro Yamada #define NAND_DATA_IFACE_CHECK_ONLY -1 133331c2375SMasahiro Yamada 134331c2375SMasahiro Yamada /* 135331c2375SMasahiro Yamada * Constants for ECC_MODES 136331c2375SMasahiro Yamada */ 137331c2375SMasahiro Yamada typedef enum { 138331c2375SMasahiro Yamada NAND_ECC_NONE, 139331c2375SMasahiro Yamada NAND_ECC_SOFT, 140331c2375SMasahiro Yamada NAND_ECC_HW, 141331c2375SMasahiro Yamada NAND_ECC_HW_SYNDROME, 142331c2375SMasahiro Yamada NAND_ECC_HW_OOB_FIRST, 143331c2375SMasahiro Yamada NAND_ECC_SOFT_BCH, 144331c2375SMasahiro Yamada } nand_ecc_modes_t; 145331c2375SMasahiro Yamada 146331c2375SMasahiro Yamada /* 147331c2375SMasahiro Yamada * Constants for Hardware ECC 148331c2375SMasahiro Yamada */ 149331c2375SMasahiro Yamada /* Reset Hardware ECC for read */ 150331c2375SMasahiro Yamada #define NAND_ECC_READ 0 151331c2375SMasahiro Yamada /* Reset Hardware ECC for write */ 152331c2375SMasahiro Yamada #define NAND_ECC_WRITE 1 153331c2375SMasahiro Yamada /* Enable Hardware ECC before syndrome is read back from flash */ 154331c2375SMasahiro Yamada #define NAND_ECC_READSYN 2 155331c2375SMasahiro Yamada 156331c2375SMasahiro Yamada /* 157331c2375SMasahiro Yamada * Enable generic NAND 'page erased' check. This check is only done when 158331c2375SMasahiro Yamada * ecc.correct() returns -EBADMSG. 159331c2375SMasahiro Yamada * Set this flag if your implementation does not fix bitflips in erased 160331c2375SMasahiro Yamada * pages and you want to rely on the default implementation. 161331c2375SMasahiro Yamada */ 162331c2375SMasahiro Yamada #define NAND_ECC_GENERIC_ERASED_CHECK BIT(0) 163331c2375SMasahiro Yamada #define NAND_ECC_MAXIMIZE BIT(1) 164331c2375SMasahiro Yamada /* 165331c2375SMasahiro Yamada * If your controller already sends the required NAND commands when 166331c2375SMasahiro Yamada * reading or writing a page, then the framework is not supposed to 167331c2375SMasahiro Yamada * send READ0 and SEQIN/PAGEPROG respectively. 168331c2375SMasahiro Yamada */ 169331c2375SMasahiro Yamada #define NAND_ECC_CUSTOM_PAGE_ACCESS BIT(2) 170331c2375SMasahiro Yamada 171331c2375SMasahiro Yamada /* Bit mask for flags passed to do_nand_read_ecc */ 172331c2375SMasahiro Yamada #define NAND_GET_DEVICE 0x80 173331c2375SMasahiro Yamada 174331c2375SMasahiro Yamada 175331c2375SMasahiro Yamada /* 176331c2375SMasahiro Yamada * Option constants for bizarre disfunctionality and real 177331c2375SMasahiro Yamada * features. 178331c2375SMasahiro Yamada */ 179331c2375SMasahiro Yamada /* Buswidth is 16 bit */ 180331c2375SMasahiro Yamada #define NAND_BUSWIDTH_16 0x00000002 181331c2375SMasahiro Yamada /* Device supports partial programming without padding */ 182331c2375SMasahiro Yamada #define NAND_NO_PADDING 0x00000004 183331c2375SMasahiro Yamada /* Chip has cache program function */ 184331c2375SMasahiro Yamada #define NAND_CACHEPRG 0x00000008 185331c2375SMasahiro Yamada /* Chip has copy back function */ 186331c2375SMasahiro Yamada #define NAND_COPYBACK 0x00000010 187331c2375SMasahiro Yamada /* 188331c2375SMasahiro Yamada * Chip requires ready check on read (for auto-incremented sequential read). 189331c2375SMasahiro Yamada * True only for small page devices; large page devices do not support 190331c2375SMasahiro Yamada * autoincrement. 191331c2375SMasahiro Yamada */ 192331c2375SMasahiro Yamada #define NAND_NEED_READRDY 0x00000100 193331c2375SMasahiro Yamada 194331c2375SMasahiro Yamada /* Chip does not allow subpage writes */ 195331c2375SMasahiro Yamada #define NAND_NO_SUBPAGE_WRITE 0x00000200 196331c2375SMasahiro Yamada 197331c2375SMasahiro Yamada /* Device is one of 'new' xD cards that expose fake nand command set */ 198331c2375SMasahiro Yamada #define NAND_BROKEN_XD 0x00000400 199331c2375SMasahiro Yamada 200331c2375SMasahiro Yamada /* Device behaves just like nand, but is readonly */ 201331c2375SMasahiro Yamada #define NAND_ROM 0x00000800 202331c2375SMasahiro Yamada 203331c2375SMasahiro Yamada /* Device supports subpage reads */ 204331c2375SMasahiro Yamada #define NAND_SUBPAGE_READ 0x00001000 205331c2375SMasahiro Yamada 206331c2375SMasahiro Yamada /* 207331c2375SMasahiro Yamada * Some MLC NANDs need data scrambling to limit bitflips caused by repeated 208331c2375SMasahiro Yamada * patterns. 209331c2375SMasahiro Yamada */ 210331c2375SMasahiro Yamada #define NAND_NEED_SCRAMBLING 0x00002000 211331c2375SMasahiro Yamada 212331c2375SMasahiro Yamada /* Device needs 3rd row address cycle */ 213331c2375SMasahiro Yamada #define NAND_ROW_ADDR_3 0x00004000 214331c2375SMasahiro Yamada 215331c2375SMasahiro Yamada /* Options valid for Samsung large page devices */ 216331c2375SMasahiro Yamada #define NAND_SAMSUNG_LP_OPTIONS NAND_CACHEPRG 217331c2375SMasahiro Yamada 218331c2375SMasahiro Yamada /* Macros to identify the above */ 219331c2375SMasahiro Yamada #define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG)) 220331c2375SMasahiro Yamada #define NAND_HAS_SUBPAGE_READ(chip) ((chip->options & NAND_SUBPAGE_READ)) 221331c2375SMasahiro Yamada #define NAND_HAS_SUBPAGE_WRITE(chip) !((chip)->options & NAND_NO_SUBPAGE_WRITE) 222331c2375SMasahiro Yamada 223331c2375SMasahiro Yamada /* Non chip related options */ 224331c2375SMasahiro Yamada /* This option skips the bbt scan during initialization. */ 225331c2375SMasahiro Yamada #define NAND_SKIP_BBTSCAN 0x00010000 226331c2375SMasahiro Yamada /* 227331c2375SMasahiro Yamada * This option is defined if the board driver allocates its own buffers 228331c2375SMasahiro Yamada * (e.g. because it needs them DMA-coherent). 229331c2375SMasahiro Yamada */ 230331c2375SMasahiro Yamada #define NAND_OWN_BUFFERS 0x00020000 231331c2375SMasahiro Yamada /* Chip may not exist, so silence any errors in scan */ 232331c2375SMasahiro Yamada #define NAND_SCAN_SILENT_NODEV 0x00040000 233331c2375SMasahiro Yamada /* 234331c2375SMasahiro Yamada * Autodetect nand buswidth with readid/onfi. 235331c2375SMasahiro Yamada * This suppose the driver will configure the hardware in 8 bits mode 236331c2375SMasahiro Yamada * when calling nand_scan_ident, and update its configuration 237331c2375SMasahiro Yamada * before calling nand_scan_tail. 238331c2375SMasahiro Yamada */ 239331c2375SMasahiro Yamada #define NAND_BUSWIDTH_AUTO 0x00080000 240331c2375SMasahiro Yamada /* 241331c2375SMasahiro Yamada * This option could be defined by controller drivers to protect against 242331c2375SMasahiro Yamada * kmap'ed, vmalloc'ed highmem buffers being passed from upper layers 243331c2375SMasahiro Yamada */ 244331c2375SMasahiro Yamada #define NAND_USE_BOUNCE_BUFFER 0x00100000 245331c2375SMasahiro Yamada 246331c2375SMasahiro Yamada /* Options set by nand scan */ 247331c2375SMasahiro Yamada /* bbt has already been read */ 248331c2375SMasahiro Yamada #define NAND_BBT_SCANNED 0x40000000 249331c2375SMasahiro Yamada /* Nand scan has allocated controller struct */ 250331c2375SMasahiro Yamada #define NAND_CONTROLLER_ALLOC 0x80000000 251331c2375SMasahiro Yamada 252331c2375SMasahiro Yamada /* Cell info constants */ 253331c2375SMasahiro Yamada #define NAND_CI_CHIPNR_MSK 0x03 254331c2375SMasahiro Yamada #define NAND_CI_CELLTYPE_MSK 0x0C 255331c2375SMasahiro Yamada #define NAND_CI_CELLTYPE_SHIFT 2 256331c2375SMasahiro Yamada 257331c2375SMasahiro Yamada /* ONFI features */ 258331c2375SMasahiro Yamada #define ONFI_FEATURE_16_BIT_BUS (1 << 0) 259331c2375SMasahiro Yamada #define ONFI_FEATURE_EXT_PARAM_PAGE (1 << 7) 260331c2375SMasahiro Yamada 261331c2375SMasahiro Yamada /* ONFI timing mode, used in both asynchronous and synchronous mode */ 262331c2375SMasahiro Yamada #define ONFI_TIMING_MODE_0 (1 << 0) 263331c2375SMasahiro Yamada #define ONFI_TIMING_MODE_1 (1 << 1) 264331c2375SMasahiro Yamada #define ONFI_TIMING_MODE_2 (1 << 2) 265331c2375SMasahiro Yamada #define ONFI_TIMING_MODE_3 (1 << 3) 266331c2375SMasahiro Yamada #define ONFI_TIMING_MODE_4 (1 << 4) 267331c2375SMasahiro Yamada #define ONFI_TIMING_MODE_5 (1 << 5) 268331c2375SMasahiro Yamada #define ONFI_TIMING_MODE_UNKNOWN (1 << 6) 269331c2375SMasahiro Yamada 270331c2375SMasahiro Yamada /* ONFI feature address */ 271331c2375SMasahiro Yamada #define ONFI_FEATURE_ADDR_TIMING_MODE 0x1 272331c2375SMasahiro Yamada 273331c2375SMasahiro Yamada /* Vendor-specific feature address (Micron) */ 274331c2375SMasahiro Yamada #define ONFI_FEATURE_ADDR_READ_RETRY 0x89 275331c2375SMasahiro Yamada 276331c2375SMasahiro Yamada /* ONFI subfeature parameters length */ 277331c2375SMasahiro Yamada #define ONFI_SUBFEATURE_PARAM_LEN 4 278331c2375SMasahiro Yamada 279331c2375SMasahiro Yamada /* ONFI optional commands SET/GET FEATURES supported? */ 280331c2375SMasahiro Yamada #define ONFI_OPT_CMD_SET_GET_FEATURES (1 << 2) 281331c2375SMasahiro Yamada 282331c2375SMasahiro Yamada struct nand_onfi_params { 283331c2375SMasahiro Yamada /* rev info and features block */ 284331c2375SMasahiro Yamada /* 'O' 'N' 'F' 'I' */ 285331c2375SMasahiro Yamada u8 sig[4]; 286331c2375SMasahiro Yamada __le16 revision; 287331c2375SMasahiro Yamada __le16 features; 288331c2375SMasahiro Yamada __le16 opt_cmd; 289331c2375SMasahiro Yamada u8 reserved0[2]; 290331c2375SMasahiro Yamada __le16 ext_param_page_length; /* since ONFI 2.1 */ 291331c2375SMasahiro Yamada u8 num_of_param_pages; /* since ONFI 2.1 */ 292331c2375SMasahiro Yamada u8 reserved1[17]; 293331c2375SMasahiro Yamada 294331c2375SMasahiro Yamada /* manufacturer information block */ 295331c2375SMasahiro Yamada char manufacturer[12]; 296331c2375SMasahiro Yamada char model[20]; 297331c2375SMasahiro Yamada u8 jedec_id; 298331c2375SMasahiro Yamada __le16 date_code; 299331c2375SMasahiro Yamada u8 reserved2[13]; 300331c2375SMasahiro Yamada 301331c2375SMasahiro Yamada /* memory organization block */ 302331c2375SMasahiro Yamada __le32 byte_per_page; 303331c2375SMasahiro Yamada __le16 spare_bytes_per_page; 304331c2375SMasahiro Yamada __le32 data_bytes_per_ppage; 305331c2375SMasahiro Yamada __le16 spare_bytes_per_ppage; 306331c2375SMasahiro Yamada __le32 pages_per_block; 307331c2375SMasahiro Yamada __le32 blocks_per_lun; 308331c2375SMasahiro Yamada u8 lun_count; 309331c2375SMasahiro Yamada u8 addr_cycles; 310331c2375SMasahiro Yamada u8 bits_per_cell; 311331c2375SMasahiro Yamada __le16 bb_per_lun; 312331c2375SMasahiro Yamada __le16 block_endurance; 313331c2375SMasahiro Yamada u8 guaranteed_good_blocks; 314331c2375SMasahiro Yamada __le16 guaranteed_block_endurance; 315331c2375SMasahiro Yamada u8 programs_per_page; 316331c2375SMasahiro Yamada u8 ppage_attr; 317331c2375SMasahiro Yamada u8 ecc_bits; 318331c2375SMasahiro Yamada u8 interleaved_bits; 319331c2375SMasahiro Yamada u8 interleaved_ops; 320331c2375SMasahiro Yamada u8 reserved3[13]; 321331c2375SMasahiro Yamada 322331c2375SMasahiro Yamada /* electrical parameter block */ 323331c2375SMasahiro Yamada u8 io_pin_capacitance_max; 324331c2375SMasahiro Yamada __le16 async_timing_mode; 325331c2375SMasahiro Yamada __le16 program_cache_timing_mode; 326331c2375SMasahiro Yamada __le16 t_prog; 327331c2375SMasahiro Yamada __le16 t_bers; 328331c2375SMasahiro Yamada __le16 t_r; 329331c2375SMasahiro Yamada __le16 t_ccs; 330331c2375SMasahiro Yamada __le16 src_sync_timing_mode; 331331c2375SMasahiro Yamada u8 src_ssync_features; 332331c2375SMasahiro Yamada __le16 clk_pin_capacitance_typ; 333331c2375SMasahiro Yamada __le16 io_pin_capacitance_typ; 334331c2375SMasahiro Yamada __le16 input_pin_capacitance_typ; 335331c2375SMasahiro Yamada u8 input_pin_capacitance_max; 336331c2375SMasahiro Yamada u8 driver_strength_support; 337331c2375SMasahiro Yamada __le16 t_int_r; 338331c2375SMasahiro Yamada __le16 t_adl; 339331c2375SMasahiro Yamada u8 reserved4[8]; 340331c2375SMasahiro Yamada 341331c2375SMasahiro Yamada /* vendor */ 342331c2375SMasahiro Yamada __le16 vendor_revision; 343331c2375SMasahiro Yamada u8 vendor[88]; 344331c2375SMasahiro Yamada 345331c2375SMasahiro Yamada __le16 crc; 346331c2375SMasahiro Yamada } __packed; 347331c2375SMasahiro Yamada 348331c2375SMasahiro Yamada #define ONFI_CRC_BASE 0x4F4E 349331c2375SMasahiro Yamada 350331c2375SMasahiro Yamada /* Extended ECC information Block Definition (since ONFI 2.1) */ 351331c2375SMasahiro Yamada struct onfi_ext_ecc_info { 352331c2375SMasahiro Yamada u8 ecc_bits; 353331c2375SMasahiro Yamada u8 codeword_size; 354331c2375SMasahiro Yamada __le16 bb_per_lun; 355331c2375SMasahiro Yamada __le16 block_endurance; 356331c2375SMasahiro Yamada u8 reserved[2]; 357331c2375SMasahiro Yamada } __packed; 358331c2375SMasahiro Yamada 359331c2375SMasahiro Yamada #define ONFI_SECTION_TYPE_0 0 /* Unused section. */ 360331c2375SMasahiro Yamada #define ONFI_SECTION_TYPE_1 1 /* for additional sections. */ 361331c2375SMasahiro Yamada #define ONFI_SECTION_TYPE_2 2 /* for ECC information. */ 362331c2375SMasahiro Yamada struct onfi_ext_section { 363331c2375SMasahiro Yamada u8 type; 364331c2375SMasahiro Yamada u8 length; 365331c2375SMasahiro Yamada } __packed; 366331c2375SMasahiro Yamada 367331c2375SMasahiro Yamada #define ONFI_EXT_SECTION_MAX 8 368331c2375SMasahiro Yamada 369331c2375SMasahiro Yamada /* Extended Parameter Page Definition (since ONFI 2.1) */ 370331c2375SMasahiro Yamada struct onfi_ext_param_page { 371331c2375SMasahiro Yamada __le16 crc; 372331c2375SMasahiro Yamada u8 sig[4]; /* 'E' 'P' 'P' 'S' */ 373331c2375SMasahiro Yamada u8 reserved0[10]; 374331c2375SMasahiro Yamada struct onfi_ext_section sections[ONFI_EXT_SECTION_MAX]; 375331c2375SMasahiro Yamada 376331c2375SMasahiro Yamada /* 377331c2375SMasahiro Yamada * The actual size of the Extended Parameter Page is in 378331c2375SMasahiro Yamada * @ext_param_page_length of nand_onfi_params{}. 379331c2375SMasahiro Yamada * The following are the variable length sections. 380331c2375SMasahiro Yamada * So we do not add any fields below. Please see the ONFI spec. 381331c2375SMasahiro Yamada */ 382331c2375SMasahiro Yamada } __packed; 383331c2375SMasahiro Yamada 384331c2375SMasahiro Yamada struct nand_onfi_vendor_micron { 385331c2375SMasahiro Yamada u8 two_plane_read; 386331c2375SMasahiro Yamada u8 read_cache; 387331c2375SMasahiro Yamada u8 read_unique_id; 388331c2375SMasahiro Yamada u8 dq_imped; 389331c2375SMasahiro Yamada u8 dq_imped_num_settings; 390331c2375SMasahiro Yamada u8 dq_imped_feat_addr; 391331c2375SMasahiro Yamada u8 rb_pulldown_strength; 392331c2375SMasahiro Yamada u8 rb_pulldown_strength_feat_addr; 393331c2375SMasahiro Yamada u8 rb_pulldown_strength_num_settings; 394331c2375SMasahiro Yamada u8 otp_mode; 395331c2375SMasahiro Yamada u8 otp_page_start; 396331c2375SMasahiro Yamada u8 otp_data_prot_addr; 397331c2375SMasahiro Yamada u8 otp_num_pages; 398331c2375SMasahiro Yamada u8 otp_feat_addr; 399331c2375SMasahiro Yamada u8 read_retry_options; 400331c2375SMasahiro Yamada u8 reserved[72]; 401331c2375SMasahiro Yamada u8 param_revision; 402331c2375SMasahiro Yamada } __packed; 403331c2375SMasahiro Yamada 404331c2375SMasahiro Yamada struct jedec_ecc_info { 405331c2375SMasahiro Yamada u8 ecc_bits; 406331c2375SMasahiro Yamada u8 codeword_size; 407331c2375SMasahiro Yamada __le16 bb_per_lun; 408331c2375SMasahiro Yamada __le16 block_endurance; 409331c2375SMasahiro Yamada u8 reserved[2]; 410331c2375SMasahiro Yamada } __packed; 411331c2375SMasahiro Yamada 412331c2375SMasahiro Yamada /* JEDEC features */ 413331c2375SMasahiro Yamada #define JEDEC_FEATURE_16_BIT_BUS (1 << 0) 414331c2375SMasahiro Yamada 415331c2375SMasahiro Yamada struct nand_jedec_params { 416331c2375SMasahiro Yamada /* rev info and features block */ 417331c2375SMasahiro Yamada /* 'J' 'E' 'S' 'D' */ 418331c2375SMasahiro Yamada u8 sig[4]; 419331c2375SMasahiro Yamada __le16 revision; 420331c2375SMasahiro Yamada __le16 features; 421331c2375SMasahiro Yamada u8 opt_cmd[3]; 422331c2375SMasahiro Yamada __le16 sec_cmd; 423331c2375SMasahiro Yamada u8 num_of_param_pages; 424331c2375SMasahiro Yamada u8 reserved0[18]; 425331c2375SMasahiro Yamada 426331c2375SMasahiro Yamada /* manufacturer information block */ 427331c2375SMasahiro Yamada char manufacturer[12]; 428331c2375SMasahiro Yamada char model[20]; 429331c2375SMasahiro Yamada u8 jedec_id[6]; 430331c2375SMasahiro Yamada u8 reserved1[10]; 431331c2375SMasahiro Yamada 432331c2375SMasahiro Yamada /* memory organization block */ 433331c2375SMasahiro Yamada __le32 byte_per_page; 434331c2375SMasahiro Yamada __le16 spare_bytes_per_page; 435331c2375SMasahiro Yamada u8 reserved2[6]; 436331c2375SMasahiro Yamada __le32 pages_per_block; 437331c2375SMasahiro Yamada __le32 blocks_per_lun; 438331c2375SMasahiro Yamada u8 lun_count; 439331c2375SMasahiro Yamada u8 addr_cycles; 440331c2375SMasahiro Yamada u8 bits_per_cell; 441331c2375SMasahiro Yamada u8 programs_per_page; 442331c2375SMasahiro Yamada u8 multi_plane_addr; 443331c2375SMasahiro Yamada u8 multi_plane_op_attr; 444331c2375SMasahiro Yamada u8 reserved3[38]; 445331c2375SMasahiro Yamada 446331c2375SMasahiro Yamada /* electrical parameter block */ 447331c2375SMasahiro Yamada __le16 async_sdr_speed_grade; 448331c2375SMasahiro Yamada __le16 toggle_ddr_speed_grade; 449331c2375SMasahiro Yamada __le16 sync_ddr_speed_grade; 450331c2375SMasahiro Yamada u8 async_sdr_features; 451331c2375SMasahiro Yamada u8 toggle_ddr_features; 452331c2375SMasahiro Yamada u8 sync_ddr_features; 453331c2375SMasahiro Yamada __le16 t_prog; 454331c2375SMasahiro Yamada __le16 t_bers; 455331c2375SMasahiro Yamada __le16 t_r; 456331c2375SMasahiro Yamada __le16 t_r_multi_plane; 457331c2375SMasahiro Yamada __le16 t_ccs; 458331c2375SMasahiro Yamada __le16 io_pin_capacitance_typ; 459331c2375SMasahiro Yamada __le16 input_pin_capacitance_typ; 460331c2375SMasahiro Yamada __le16 clk_pin_capacitance_typ; 461331c2375SMasahiro Yamada u8 driver_strength_support; 462331c2375SMasahiro Yamada __le16 t_adl; 463331c2375SMasahiro Yamada u8 reserved4[36]; 464331c2375SMasahiro Yamada 465331c2375SMasahiro Yamada /* ECC and endurance block */ 466331c2375SMasahiro Yamada u8 guaranteed_good_blocks; 467331c2375SMasahiro Yamada __le16 guaranteed_block_endurance; 468331c2375SMasahiro Yamada struct jedec_ecc_info ecc_info[4]; 469331c2375SMasahiro Yamada u8 reserved5[29]; 470331c2375SMasahiro Yamada 471331c2375SMasahiro Yamada /* reserved */ 472331c2375SMasahiro Yamada u8 reserved6[148]; 473331c2375SMasahiro Yamada 474331c2375SMasahiro Yamada /* vendor */ 475331c2375SMasahiro Yamada __le16 vendor_rev_num; 476331c2375SMasahiro Yamada u8 reserved7[88]; 477331c2375SMasahiro Yamada 478331c2375SMasahiro Yamada /* CRC for Parameter Page */ 479331c2375SMasahiro Yamada __le16 crc; 480331c2375SMasahiro Yamada } __packed; 481331c2375SMasahiro Yamada 482331c2375SMasahiro Yamada /** 483331c2375SMasahiro Yamada * struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independent devices 484331c2375SMasahiro Yamada * @lock: protection lock 485331c2375SMasahiro Yamada * @active: the mtd device which holds the controller currently 486331c2375SMasahiro Yamada * @wq: wait queue to sleep on if a NAND operation is in 487331c2375SMasahiro Yamada * progress used instead of the per chip wait queue 488331c2375SMasahiro Yamada * when a hw controller is available. 489331c2375SMasahiro Yamada */ 490331c2375SMasahiro Yamada struct nand_hw_control { 491331c2375SMasahiro Yamada spinlock_t lock; 492331c2375SMasahiro Yamada struct nand_chip *active; 493331c2375SMasahiro Yamada }; 494331c2375SMasahiro Yamada 495331c2375SMasahiro Yamada /** 496331c2375SMasahiro Yamada * struct nand_ecc_step_info - ECC step information of ECC engine 497331c2375SMasahiro Yamada * @stepsize: data bytes per ECC step 498331c2375SMasahiro Yamada * @strengths: array of supported strengths 499331c2375SMasahiro Yamada * @nstrengths: number of supported strengths 500331c2375SMasahiro Yamada */ 501331c2375SMasahiro Yamada struct nand_ecc_step_info { 502331c2375SMasahiro Yamada int stepsize; 503331c2375SMasahiro Yamada const int *strengths; 504331c2375SMasahiro Yamada int nstrengths; 505331c2375SMasahiro Yamada }; 506331c2375SMasahiro Yamada 507331c2375SMasahiro Yamada /** 508331c2375SMasahiro Yamada * struct nand_ecc_caps - capability of ECC engine 509331c2375SMasahiro Yamada * @stepinfos: array of ECC step information 510331c2375SMasahiro Yamada * @nstepinfos: number of ECC step information 511331c2375SMasahiro Yamada * @calc_ecc_bytes: driver's hook to calculate ECC bytes per step 512331c2375SMasahiro Yamada */ 513331c2375SMasahiro Yamada struct nand_ecc_caps { 514331c2375SMasahiro Yamada const struct nand_ecc_step_info *stepinfos; 515331c2375SMasahiro Yamada int nstepinfos; 516331c2375SMasahiro Yamada int (*calc_ecc_bytes)(int step_size, int strength); 517331c2375SMasahiro Yamada }; 518331c2375SMasahiro Yamada 519331c2375SMasahiro Yamada /** 520331c2375SMasahiro Yamada * struct nand_ecc_ctrl - Control structure for ECC 521331c2375SMasahiro Yamada * @mode: ECC mode 522331c2375SMasahiro Yamada * @steps: number of ECC steps per page 523331c2375SMasahiro Yamada * @size: data bytes per ECC step 524331c2375SMasahiro Yamada * @bytes: ECC bytes per step 525331c2375SMasahiro Yamada * @strength: max number of correctible bits per ECC step 526331c2375SMasahiro Yamada * @total: total number of ECC bytes per page 527331c2375SMasahiro Yamada * @prepad: padding information for syndrome based ECC generators 528331c2375SMasahiro Yamada * @postpad: padding information for syndrome based ECC generators 529331c2375SMasahiro Yamada * @options: ECC specific options (see NAND_ECC_XXX flags defined above) 530331c2375SMasahiro Yamada * @layout: ECC layout control struct pointer 531331c2375SMasahiro Yamada * @priv: pointer to private ECC control data 532331c2375SMasahiro Yamada * @hwctl: function to control hardware ECC generator. Must only 533331c2375SMasahiro Yamada * be provided if an hardware ECC is available 534331c2375SMasahiro Yamada * @calculate: function for ECC calculation or readback from ECC hardware 535331c2375SMasahiro Yamada * @correct: function for ECC correction, matching to ECC generator (sw/hw). 536331c2375SMasahiro Yamada * Should return a positive number representing the number of 537331c2375SMasahiro Yamada * corrected bitflips, -EBADMSG if the number of bitflips exceed 538331c2375SMasahiro Yamada * ECC strength, or any other error code if the error is not 539331c2375SMasahiro Yamada * directly related to correction. 540331c2375SMasahiro Yamada * If -EBADMSG is returned the input buffers should be left 541331c2375SMasahiro Yamada * untouched. 542331c2375SMasahiro Yamada * @read_page_raw: function to read a raw page without ECC. This function 543331c2375SMasahiro Yamada * should hide the specific layout used by the ECC 544331c2375SMasahiro Yamada * controller and always return contiguous in-band and 545331c2375SMasahiro Yamada * out-of-band data even if they're not stored 546331c2375SMasahiro Yamada * contiguously on the NAND chip (e.g. 547331c2375SMasahiro Yamada * NAND_ECC_HW_SYNDROME interleaves in-band and 548331c2375SMasahiro Yamada * out-of-band data). 549331c2375SMasahiro Yamada * @write_page_raw: function to write a raw page without ECC. This function 550331c2375SMasahiro Yamada * should hide the specific layout used by the ECC 551331c2375SMasahiro Yamada * controller and consider the passed data as contiguous 552331c2375SMasahiro Yamada * in-band and out-of-band data. ECC controller is 553331c2375SMasahiro Yamada * responsible for doing the appropriate transformations 554331c2375SMasahiro Yamada * to adapt to its specific layout (e.g. 555331c2375SMasahiro Yamada * NAND_ECC_HW_SYNDROME interleaves in-band and 556331c2375SMasahiro Yamada * out-of-band data). 557331c2375SMasahiro Yamada * @read_page: function to read a page according to the ECC generator 558331c2375SMasahiro Yamada * requirements; returns maximum number of bitflips corrected in 559331c2375SMasahiro Yamada * any single ECC step, 0 if bitflips uncorrectable, -EIO hw error 560331c2375SMasahiro Yamada * @read_subpage: function to read parts of the page covered by ECC; 561331c2375SMasahiro Yamada * returns same as read_page() 562331c2375SMasahiro Yamada * @write_subpage: function to write parts of the page covered by ECC. 563331c2375SMasahiro Yamada * @write_page: function to write a page according to the ECC generator 564331c2375SMasahiro Yamada * requirements. 565331c2375SMasahiro Yamada * @write_oob_raw: function to write chip OOB data without ECC 566331c2375SMasahiro Yamada * @read_oob_raw: function to read chip OOB data without ECC 567331c2375SMasahiro Yamada * @read_oob: function to read chip OOB data 568331c2375SMasahiro Yamada * @write_oob: function to write chip OOB data 569331c2375SMasahiro Yamada */ 570331c2375SMasahiro Yamada struct nand_ecc_ctrl { 571331c2375SMasahiro Yamada nand_ecc_modes_t mode; 572331c2375SMasahiro Yamada int steps; 573331c2375SMasahiro Yamada int size; 574331c2375SMasahiro Yamada int bytes; 575331c2375SMasahiro Yamada int total; 576331c2375SMasahiro Yamada int strength; 577331c2375SMasahiro Yamada int prepad; 578331c2375SMasahiro Yamada int postpad; 579331c2375SMasahiro Yamada unsigned int options; 580331c2375SMasahiro Yamada struct nand_ecclayout *layout; 581331c2375SMasahiro Yamada void *priv; 582331c2375SMasahiro Yamada void (*hwctl)(struct mtd_info *mtd, int mode); 583331c2375SMasahiro Yamada int (*calculate)(struct mtd_info *mtd, const uint8_t *dat, 584331c2375SMasahiro Yamada uint8_t *ecc_code); 585331c2375SMasahiro Yamada int (*correct)(struct mtd_info *mtd, uint8_t *dat, uint8_t *read_ecc, 586331c2375SMasahiro Yamada uint8_t *calc_ecc); 587331c2375SMasahiro Yamada int (*read_page_raw)(struct mtd_info *mtd, struct nand_chip *chip, 588331c2375SMasahiro Yamada uint8_t *buf, int oob_required, int page); 589331c2375SMasahiro Yamada int (*write_page_raw)(struct mtd_info *mtd, struct nand_chip *chip, 590331c2375SMasahiro Yamada const uint8_t *buf, int oob_required, int page); 591331c2375SMasahiro Yamada int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip, 592331c2375SMasahiro Yamada uint8_t *buf, int oob_required, int page); 593331c2375SMasahiro Yamada int (*read_subpage)(struct mtd_info *mtd, struct nand_chip *chip, 594331c2375SMasahiro Yamada uint32_t offs, uint32_t len, uint8_t *buf, int page); 595331c2375SMasahiro Yamada int (*write_subpage)(struct mtd_info *mtd, struct nand_chip *chip, 596331c2375SMasahiro Yamada uint32_t offset, uint32_t data_len, 597331c2375SMasahiro Yamada const uint8_t *data_buf, int oob_required, int page); 598331c2375SMasahiro Yamada int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip, 599331c2375SMasahiro Yamada const uint8_t *buf, int oob_required, int page); 600331c2375SMasahiro Yamada int (*write_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip, 601331c2375SMasahiro Yamada int page); 602331c2375SMasahiro Yamada int (*read_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip, 603331c2375SMasahiro Yamada int page); 604331c2375SMasahiro Yamada int (*read_oob)(struct mtd_info *mtd, struct nand_chip *chip, int page); 605331c2375SMasahiro Yamada int (*write_oob)(struct mtd_info *mtd, struct nand_chip *chip, 606331c2375SMasahiro Yamada int page); 607331c2375SMasahiro Yamada }; 608331c2375SMasahiro Yamada 609331c2375SMasahiro Yamada static inline int nand_standard_page_accessors(struct nand_ecc_ctrl *ecc) 610331c2375SMasahiro Yamada { 611331c2375SMasahiro Yamada return !(ecc->options & NAND_ECC_CUSTOM_PAGE_ACCESS); 612331c2375SMasahiro Yamada } 613331c2375SMasahiro Yamada 614331c2375SMasahiro Yamada /** 615331c2375SMasahiro Yamada * struct nand_buffers - buffer structure for read/write 616331c2375SMasahiro Yamada * @ecccalc: buffer pointer for calculated ECC, size is oobsize. 617331c2375SMasahiro Yamada * @ecccode: buffer pointer for ECC read from flash, size is oobsize. 618331c2375SMasahiro Yamada * @databuf: buffer pointer for data, size is (page size + oobsize). 619331c2375SMasahiro Yamada * 620331c2375SMasahiro Yamada * Do not change the order of buffers. databuf and oobrbuf must be in 621331c2375SMasahiro Yamada * consecutive order. 622331c2375SMasahiro Yamada */ 623331c2375SMasahiro Yamada struct nand_buffers { 624331c2375SMasahiro Yamada uint8_t ecccalc[ALIGN(NAND_MAX_OOBSIZE, ARCH_DMA_MINALIGN)]; 625331c2375SMasahiro Yamada uint8_t ecccode[ALIGN(NAND_MAX_OOBSIZE, ARCH_DMA_MINALIGN)]; 626331c2375SMasahiro Yamada uint8_t databuf[ALIGN(NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE, 627331c2375SMasahiro Yamada ARCH_DMA_MINALIGN)]; 628331c2375SMasahiro Yamada }; 629331c2375SMasahiro Yamada 630331c2375SMasahiro Yamada /** 631331c2375SMasahiro Yamada * struct nand_sdr_timings - SDR NAND chip timings 632331c2375SMasahiro Yamada * 633331c2375SMasahiro Yamada * This struct defines the timing requirements of a SDR NAND chip. 634331c2375SMasahiro Yamada * These information can be found in every NAND datasheets and the timings 635331c2375SMasahiro Yamada * meaning are described in the ONFI specifications: 636331c2375SMasahiro Yamada * www.onfi.org/~/media/ONFI/specs/onfi_3_1_spec.pdf (chapter 4.15 Timing 637331c2375SMasahiro Yamada * Parameters) 638331c2375SMasahiro Yamada * 639331c2375SMasahiro Yamada * All these timings are expressed in picoseconds. 640331c2375SMasahiro Yamada * 641331c2375SMasahiro Yamada * @tBERS_max: Block erase time 642331c2375SMasahiro Yamada * @tCCS_min: Change column setup time 643331c2375SMasahiro Yamada * @tPROG_max: Page program time 644331c2375SMasahiro Yamada * @tR_max: Page read time 645331c2375SMasahiro Yamada * @tALH_min: ALE hold time 646331c2375SMasahiro Yamada * @tADL_min: ALE to data loading time 647331c2375SMasahiro Yamada * @tALS_min: ALE setup time 648331c2375SMasahiro Yamada * @tAR_min: ALE to RE# delay 649331c2375SMasahiro Yamada * @tCEA_max: CE# access time 650331c2375SMasahiro Yamada * @tCEH_min: CE# high hold time 651331c2375SMasahiro Yamada * @tCH_min: CE# hold time 652331c2375SMasahiro Yamada * @tCHZ_max: CE# high to output hi-Z 653331c2375SMasahiro Yamada * @tCLH_min: CLE hold time 654331c2375SMasahiro Yamada * @tCLR_min: CLE to RE# delay 655331c2375SMasahiro Yamada * @tCLS_min: CLE setup time 656331c2375SMasahiro Yamada * @tCOH_min: CE# high to output hold 657331c2375SMasahiro Yamada * @tCS_min: CE# setup time 658331c2375SMasahiro Yamada * @tDH_min: Data hold time 659331c2375SMasahiro Yamada * @tDS_min: Data setup time 660331c2375SMasahiro Yamada * @tFEAT_max: Busy time for Set Features and Get Features 661331c2375SMasahiro Yamada * @tIR_min: Output hi-Z to RE# low 662331c2375SMasahiro Yamada * @tITC_max: Interface and Timing Mode Change time 663331c2375SMasahiro Yamada * @tRC_min: RE# cycle time 664331c2375SMasahiro Yamada * @tREA_max: RE# access time 665331c2375SMasahiro Yamada * @tREH_min: RE# high hold time 666331c2375SMasahiro Yamada * @tRHOH_min: RE# high to output hold 667331c2375SMasahiro Yamada * @tRHW_min: RE# high to WE# low 668331c2375SMasahiro Yamada * @tRHZ_max: RE# high to output hi-Z 669331c2375SMasahiro Yamada * @tRLOH_min: RE# low to output hold 670331c2375SMasahiro Yamada * @tRP_min: RE# pulse width 671331c2375SMasahiro Yamada * @tRR_min: Ready to RE# low (data only) 672331c2375SMasahiro Yamada * @tRST_max: Device reset time, measured from the falling edge of R/B# to the 673331c2375SMasahiro Yamada * rising edge of R/B#. 674331c2375SMasahiro Yamada * @tWB_max: WE# high to SR[6] low 675331c2375SMasahiro Yamada * @tWC_min: WE# cycle time 676331c2375SMasahiro Yamada * @tWH_min: WE# high hold time 677331c2375SMasahiro Yamada * @tWHR_min: WE# high to RE# low 678331c2375SMasahiro Yamada * @tWP_min: WE# pulse width 679331c2375SMasahiro Yamada * @tWW_min: WP# transition to WE# low 680331c2375SMasahiro Yamada */ 681331c2375SMasahiro Yamada struct nand_sdr_timings { 682331c2375SMasahiro Yamada u64 tBERS_max; 683331c2375SMasahiro Yamada u32 tCCS_min; 684331c2375SMasahiro Yamada u64 tPROG_max; 685331c2375SMasahiro Yamada u64 tR_max; 686331c2375SMasahiro Yamada u32 tALH_min; 687331c2375SMasahiro Yamada u32 tADL_min; 688331c2375SMasahiro Yamada u32 tALS_min; 689331c2375SMasahiro Yamada u32 tAR_min; 690331c2375SMasahiro Yamada u32 tCEA_max; 691331c2375SMasahiro Yamada u32 tCEH_min; 692331c2375SMasahiro Yamada u32 tCH_min; 693331c2375SMasahiro Yamada u32 tCHZ_max; 694331c2375SMasahiro Yamada u32 tCLH_min; 695331c2375SMasahiro Yamada u32 tCLR_min; 696331c2375SMasahiro Yamada u32 tCLS_min; 697331c2375SMasahiro Yamada u32 tCOH_min; 698331c2375SMasahiro Yamada u32 tCS_min; 699331c2375SMasahiro Yamada u32 tDH_min; 700331c2375SMasahiro Yamada u32 tDS_min; 701331c2375SMasahiro Yamada u32 tFEAT_max; 702331c2375SMasahiro Yamada u32 tIR_min; 703331c2375SMasahiro Yamada u32 tITC_max; 704331c2375SMasahiro Yamada u32 tRC_min; 705331c2375SMasahiro Yamada u32 tREA_max; 706331c2375SMasahiro Yamada u32 tREH_min; 707331c2375SMasahiro Yamada u32 tRHOH_min; 708331c2375SMasahiro Yamada u32 tRHW_min; 709331c2375SMasahiro Yamada u32 tRHZ_max; 710331c2375SMasahiro Yamada u32 tRLOH_min; 711331c2375SMasahiro Yamada u32 tRP_min; 712331c2375SMasahiro Yamada u32 tRR_min; 713331c2375SMasahiro Yamada u64 tRST_max; 714331c2375SMasahiro Yamada u32 tWB_max; 715331c2375SMasahiro Yamada u32 tWC_min; 716331c2375SMasahiro Yamada u32 tWH_min; 717331c2375SMasahiro Yamada u32 tWHR_min; 718331c2375SMasahiro Yamada u32 tWP_min; 719331c2375SMasahiro Yamada u32 tWW_min; 720331c2375SMasahiro Yamada }; 721331c2375SMasahiro Yamada 722331c2375SMasahiro Yamada /** 723331c2375SMasahiro Yamada * enum nand_data_interface_type - NAND interface timing type 724331c2375SMasahiro Yamada * @NAND_SDR_IFACE: Single Data Rate interface 725331c2375SMasahiro Yamada */ 726331c2375SMasahiro Yamada enum nand_data_interface_type { 727331c2375SMasahiro Yamada NAND_SDR_IFACE, 728331c2375SMasahiro Yamada }; 729331c2375SMasahiro Yamada 730331c2375SMasahiro Yamada /** 731331c2375SMasahiro Yamada * struct nand_data_interface - NAND interface timing 732331c2375SMasahiro Yamada * @type: type of the timing 733331c2375SMasahiro Yamada * @timings: The timing, type according to @type 734331c2375SMasahiro Yamada */ 735331c2375SMasahiro Yamada struct nand_data_interface { 736331c2375SMasahiro Yamada enum nand_data_interface_type type; 737331c2375SMasahiro Yamada union { 738331c2375SMasahiro Yamada struct nand_sdr_timings sdr; 739331c2375SMasahiro Yamada } timings; 740331c2375SMasahiro Yamada }; 741331c2375SMasahiro Yamada 742331c2375SMasahiro Yamada /** 743331c2375SMasahiro Yamada * nand_get_sdr_timings - get SDR timing from data interface 744331c2375SMasahiro Yamada * @conf: The data interface 745331c2375SMasahiro Yamada */ 746331c2375SMasahiro Yamada static inline const struct nand_sdr_timings * 747331c2375SMasahiro Yamada nand_get_sdr_timings(const struct nand_data_interface *conf) 748331c2375SMasahiro Yamada { 749331c2375SMasahiro Yamada if (conf->type != NAND_SDR_IFACE) 750331c2375SMasahiro Yamada return ERR_PTR(-EINVAL); 751331c2375SMasahiro Yamada 752331c2375SMasahiro Yamada return &conf->timings.sdr; 753331c2375SMasahiro Yamada } 754331c2375SMasahiro Yamada 755331c2375SMasahiro Yamada /** 756331c2375SMasahiro Yamada * struct nand_chip - NAND Private Flash Chip Data 757331c2375SMasahiro Yamada * @mtd: MTD device registered to the MTD framework 758331c2375SMasahiro Yamada * @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the 759331c2375SMasahiro Yamada * flash device 760331c2375SMasahiro Yamada * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the 761331c2375SMasahiro Yamada * flash device. 762331c2375SMasahiro Yamada * @flash_node: [BOARDSPECIFIC] device node describing this instance 763331c2375SMasahiro Yamada * @read_byte: [REPLACEABLE] read one byte from the chip 764331c2375SMasahiro Yamada * @read_word: [REPLACEABLE] read one word from the chip 765331c2375SMasahiro Yamada * @write_byte: [REPLACEABLE] write a single byte to the chip on the 766331c2375SMasahiro Yamada * low 8 I/O lines 767331c2375SMasahiro Yamada * @write_buf: [REPLACEABLE] write data from the buffer to the chip 768331c2375SMasahiro Yamada * @read_buf: [REPLACEABLE] read data from the chip into the buffer 769331c2375SMasahiro Yamada * @select_chip: [REPLACEABLE] select chip nr 770331c2375SMasahiro Yamada * @block_bad: [REPLACEABLE] check if a block is bad, using OOB markers 771331c2375SMasahiro Yamada * @block_markbad: [REPLACEABLE] mark a block bad 772331c2375SMasahiro Yamada * @cmd_ctrl: [BOARDSPECIFIC] hardwarespecific function for controlling 773331c2375SMasahiro Yamada * ALE/CLE/nCE. Also used to write command and address 774331c2375SMasahiro Yamada * @dev_ready: [BOARDSPECIFIC] hardwarespecific function for accessing 775331c2375SMasahiro Yamada * device ready/busy line. If set to NULL no access to 776331c2375SMasahiro Yamada * ready/busy is available and the ready/busy information 777331c2375SMasahiro Yamada * is read from the chip status register. 778331c2375SMasahiro Yamada * @cmdfunc: [REPLACEABLE] hardwarespecific function for writing 779331c2375SMasahiro Yamada * commands to the chip. 780331c2375SMasahiro Yamada * @waitfunc: [REPLACEABLE] hardwarespecific function for wait on 781331c2375SMasahiro Yamada * ready. 782331c2375SMasahiro Yamada * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for 783331c2375SMasahiro Yamada * setting the read-retry mode. Mostly needed for MLC NAND. 784331c2375SMasahiro Yamada * @ecc: [BOARDSPECIFIC] ECC control structure 785331c2375SMasahiro Yamada * @buffers: buffer structure for read/write 786331c2375SMasahiro Yamada * @buf_align: minimum buffer alignment required by a platform 787331c2375SMasahiro Yamada * @hwcontrol: platform-specific hardware control structure 788331c2375SMasahiro Yamada * @erase: [REPLACEABLE] erase function 789331c2375SMasahiro Yamada * @scan_bbt: [REPLACEABLE] function to scan bad block table 790331c2375SMasahiro Yamada * @chip_delay: [BOARDSPECIFIC] chip dependent delay for transferring 791331c2375SMasahiro Yamada * data from array to read regs (tR). 792331c2375SMasahiro Yamada * @state: [INTERN] the current state of the NAND device 793331c2375SMasahiro Yamada * @oob_poi: "poison value buffer," used for laying out OOB data 794331c2375SMasahiro Yamada * before writing 795331c2375SMasahiro Yamada * @page_shift: [INTERN] number of address bits in a page (column 796331c2375SMasahiro Yamada * address bits). 797331c2375SMasahiro Yamada * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock 798331c2375SMasahiro Yamada * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry 799331c2375SMasahiro Yamada * @chip_shift: [INTERN] number of address bits in one chip 800331c2375SMasahiro Yamada * @options: [BOARDSPECIFIC] various chip options. They can partly 801331c2375SMasahiro Yamada * be set to inform nand_scan about special functionality. 802331c2375SMasahiro Yamada * See the defines for further explanation. 803331c2375SMasahiro Yamada * @bbt_options: [INTERN] bad block specific options. All options used 804331c2375SMasahiro Yamada * here must come from bbm.h. By default, these options 805331c2375SMasahiro Yamada * will be copied to the appropriate nand_bbt_descr's. 806331c2375SMasahiro Yamada * @badblockpos: [INTERN] position of the bad block marker in the oob 807331c2375SMasahiro Yamada * area. 808331c2375SMasahiro Yamada * @badblockbits: [INTERN] minimum number of set bits in a good block's 809331c2375SMasahiro Yamada * bad block marker position; i.e., BBM == 11110111b is 810331c2375SMasahiro Yamada * not bad when badblockbits == 7 811331c2375SMasahiro Yamada * @bits_per_cell: [INTERN] number of bits per cell. i.e., 1 means SLC. 812331c2375SMasahiro Yamada * @ecc_strength_ds: [INTERN] ECC correctability from the datasheet. 813331c2375SMasahiro Yamada * Minimum amount of bit errors per @ecc_step_ds guaranteed 814331c2375SMasahiro Yamada * to be correctable. If unknown, set to zero. 815331c2375SMasahiro Yamada * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds, 816331c2375SMasahiro Yamada * also from the datasheet. It is the recommended ECC step 817331c2375SMasahiro Yamada * size, if known; if unknown, set to zero. 818331c2375SMasahiro Yamada * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is 819331c2375SMasahiro Yamada * set to the actually used ONFI mode if the chip is 820331c2375SMasahiro Yamada * ONFI compliant or deduced from the datasheet if 821331c2375SMasahiro Yamada * the NAND chip is not ONFI compliant. 822331c2375SMasahiro Yamada * @numchips: [INTERN] number of physical chips 823331c2375SMasahiro Yamada * @chipsize: [INTERN] the size of one chip for multichip arrays 824331c2375SMasahiro Yamada * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 825331c2375SMasahiro Yamada * @pagebuf: [INTERN] holds the pagenumber which is currently in 826331c2375SMasahiro Yamada * data_buf. 827331c2375SMasahiro Yamada * @pagebuf_bitflips: [INTERN] holds the bitflip count for the page which is 828331c2375SMasahiro Yamada * currently in data_buf. 829331c2375SMasahiro Yamada * @subpagesize: [INTERN] holds the subpagesize 830331c2375SMasahiro Yamada * @onfi_version: [INTERN] holds the chip ONFI version (BCD encoded), 831331c2375SMasahiro Yamada * non 0 if ONFI supported. 832331c2375SMasahiro Yamada * @jedec_version: [INTERN] holds the chip JEDEC version (BCD encoded), 833331c2375SMasahiro Yamada * non 0 if JEDEC supported. 834331c2375SMasahiro Yamada * @onfi_params: [INTERN] holds the ONFI page parameter when ONFI is 835331c2375SMasahiro Yamada * supported, 0 otherwise. 836331c2375SMasahiro Yamada * @jedec_params: [INTERN] holds the JEDEC parameter page when JEDEC is 837331c2375SMasahiro Yamada * supported, 0 otherwise. 838331c2375SMasahiro Yamada * @read_retries: [INTERN] the number of read retry modes supported 839331c2375SMasahiro Yamada * @onfi_set_features: [REPLACEABLE] set the features for ONFI nand 840331c2375SMasahiro Yamada * @onfi_get_features: [REPLACEABLE] get the features for ONFI nand 841331c2375SMasahiro Yamada * @setup_data_interface: [OPTIONAL] setup the data interface and timing. If 842331c2375SMasahiro Yamada * chipnr is set to %NAND_DATA_IFACE_CHECK_ONLY this 843331c2375SMasahiro Yamada * means the configuration should not be applied but 844331c2375SMasahiro Yamada * only checked. 845331c2375SMasahiro Yamada * @bbt: [INTERN] bad block table pointer 846331c2375SMasahiro Yamada * @bbt_td: [REPLACEABLE] bad block table descriptor for flash 847331c2375SMasahiro Yamada * lookup. 848331c2375SMasahiro Yamada * @bbt_md: [REPLACEABLE] bad block table mirror descriptor 849331c2375SMasahiro Yamada * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial 850331c2375SMasahiro Yamada * bad block scan. 851331c2375SMasahiro Yamada * @controller: [REPLACEABLE] a pointer to a hardware controller 852331c2375SMasahiro Yamada * structure which is shared among multiple independent 853331c2375SMasahiro Yamada * devices. 854331c2375SMasahiro Yamada * @priv: [OPTIONAL] pointer to private chip data 855331c2375SMasahiro Yamada * @write_page: [REPLACEABLE] High-level page write function 856331c2375SMasahiro Yamada */ 857331c2375SMasahiro Yamada 858331c2375SMasahiro Yamada struct nand_chip { 859331c2375SMasahiro Yamada struct mtd_info mtd; 860331c2375SMasahiro Yamada void __iomem *IO_ADDR_R; 861331c2375SMasahiro Yamada void __iomem *IO_ADDR_W; 862331c2375SMasahiro Yamada 863331c2375SMasahiro Yamada int flash_node; 864331c2375SMasahiro Yamada 865331c2375SMasahiro Yamada uint8_t (*read_byte)(struct mtd_info *mtd); 866331c2375SMasahiro Yamada u16 (*read_word)(struct mtd_info *mtd); 867331c2375SMasahiro Yamada void (*write_byte)(struct mtd_info *mtd, uint8_t byte); 868331c2375SMasahiro Yamada void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len); 869331c2375SMasahiro Yamada void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len); 870331c2375SMasahiro Yamada void (*select_chip)(struct mtd_info *mtd, int chip); 871331c2375SMasahiro Yamada int (*block_bad)(struct mtd_info *mtd, loff_t ofs); 872331c2375SMasahiro Yamada int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); 873331c2375SMasahiro Yamada void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl); 874331c2375SMasahiro Yamada int (*dev_ready)(struct mtd_info *mtd); 875331c2375SMasahiro Yamada void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column, 876331c2375SMasahiro Yamada int page_addr); 877331c2375SMasahiro Yamada int(*waitfunc)(struct mtd_info *mtd, struct nand_chip *this); 878331c2375SMasahiro Yamada int (*erase)(struct mtd_info *mtd, int page); 879331c2375SMasahiro Yamada int (*scan_bbt)(struct mtd_info *mtd); 880331c2375SMasahiro Yamada int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip, 881331c2375SMasahiro Yamada uint32_t offset, int data_len, const uint8_t *buf, 882331c2375SMasahiro Yamada int oob_required, int page, int raw); 883331c2375SMasahiro Yamada int (*onfi_set_features)(struct mtd_info *mtd, struct nand_chip *chip, 884331c2375SMasahiro Yamada int feature_addr, uint8_t *subfeature_para); 885331c2375SMasahiro Yamada int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip, 886331c2375SMasahiro Yamada int feature_addr, uint8_t *subfeature_para); 887331c2375SMasahiro Yamada int (*setup_read_retry)(struct mtd_info *mtd, int retry_mode); 888331c2375SMasahiro Yamada int (*setup_data_interface)(struct mtd_info *mtd, int chipnr, 889331c2375SMasahiro Yamada const struct nand_data_interface *conf); 890331c2375SMasahiro Yamada 891331c2375SMasahiro Yamada 892331c2375SMasahiro Yamada int chip_delay; 893331c2375SMasahiro Yamada unsigned int options; 894331c2375SMasahiro Yamada unsigned int bbt_options; 895331c2375SMasahiro Yamada 896331c2375SMasahiro Yamada int page_shift; 897331c2375SMasahiro Yamada int phys_erase_shift; 898331c2375SMasahiro Yamada int bbt_erase_shift; 899331c2375SMasahiro Yamada int chip_shift; 900331c2375SMasahiro Yamada int numchips; 901331c2375SMasahiro Yamada uint64_t chipsize; 902331c2375SMasahiro Yamada int pagemask; 903331c2375SMasahiro Yamada int pagebuf; 904331c2375SMasahiro Yamada unsigned int pagebuf_bitflips; 905331c2375SMasahiro Yamada int subpagesize; 906331c2375SMasahiro Yamada uint8_t bits_per_cell; 907331c2375SMasahiro Yamada uint16_t ecc_strength_ds; 908331c2375SMasahiro Yamada uint16_t ecc_step_ds; 909331c2375SMasahiro Yamada int onfi_timing_mode_default; 910331c2375SMasahiro Yamada int badblockpos; 911331c2375SMasahiro Yamada int badblockbits; 912331c2375SMasahiro Yamada 913331c2375SMasahiro Yamada int onfi_version; 914331c2375SMasahiro Yamada int jedec_version; 915331c2375SMasahiro Yamada #ifdef CONFIG_SYS_NAND_ONFI_DETECTION 916331c2375SMasahiro Yamada struct nand_onfi_params onfi_params; 917331c2375SMasahiro Yamada #endif 918331c2375SMasahiro Yamada struct nand_jedec_params jedec_params; 919331c2375SMasahiro Yamada 920331c2375SMasahiro Yamada struct nand_data_interface *data_interface; 921331c2375SMasahiro Yamada 922331c2375SMasahiro Yamada int read_retries; 923331c2375SMasahiro Yamada 924331c2375SMasahiro Yamada flstate_t state; 925331c2375SMasahiro Yamada 926331c2375SMasahiro Yamada uint8_t *oob_poi; 927331c2375SMasahiro Yamada struct nand_hw_control *controller; 928331c2375SMasahiro Yamada struct nand_ecclayout *ecclayout; 929331c2375SMasahiro Yamada 930331c2375SMasahiro Yamada struct nand_ecc_ctrl ecc; 931331c2375SMasahiro Yamada struct nand_buffers *buffers; 932331c2375SMasahiro Yamada unsigned long buf_align; 933331c2375SMasahiro Yamada struct nand_hw_control hwcontrol; 934331c2375SMasahiro Yamada 935331c2375SMasahiro Yamada uint8_t *bbt; 936331c2375SMasahiro Yamada struct nand_bbt_descr *bbt_td; 937331c2375SMasahiro Yamada struct nand_bbt_descr *bbt_md; 938331c2375SMasahiro Yamada 939331c2375SMasahiro Yamada struct nand_bbt_descr *badblock_pattern; 940331c2375SMasahiro Yamada 941331c2375SMasahiro Yamada void *priv; 942331c2375SMasahiro Yamada }; 943331c2375SMasahiro Yamada 944331c2375SMasahiro Yamada static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd) 945331c2375SMasahiro Yamada { 946331c2375SMasahiro Yamada return container_of(mtd, struct nand_chip, mtd); 947331c2375SMasahiro Yamada } 948331c2375SMasahiro Yamada 949331c2375SMasahiro Yamada static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip) 950331c2375SMasahiro Yamada { 951331c2375SMasahiro Yamada return &chip->mtd; 952331c2375SMasahiro Yamada } 953331c2375SMasahiro Yamada 954331c2375SMasahiro Yamada static inline void *nand_get_controller_data(struct nand_chip *chip) 955331c2375SMasahiro Yamada { 956331c2375SMasahiro Yamada return chip->priv; 957331c2375SMasahiro Yamada } 958331c2375SMasahiro Yamada 959331c2375SMasahiro Yamada static inline void nand_set_controller_data(struct nand_chip *chip, void *priv) 960331c2375SMasahiro Yamada { 961331c2375SMasahiro Yamada chip->priv = priv; 962331c2375SMasahiro Yamada } 963331c2375SMasahiro Yamada 964331c2375SMasahiro Yamada /* 965331c2375SMasahiro Yamada * NAND Flash Manufacturer ID Codes 966331c2375SMasahiro Yamada */ 967331c2375SMasahiro Yamada #define NAND_MFR_TOSHIBA 0x98 968331c2375SMasahiro Yamada #define NAND_MFR_SAMSUNG 0xec 969331c2375SMasahiro Yamada #define NAND_MFR_FUJITSU 0x04 970331c2375SMasahiro Yamada #define NAND_MFR_NATIONAL 0x8f 971331c2375SMasahiro Yamada #define NAND_MFR_RENESAS 0x07 972331c2375SMasahiro Yamada #define NAND_MFR_STMICRO 0x20 973331c2375SMasahiro Yamada #define NAND_MFR_HYNIX 0xad 974331c2375SMasahiro Yamada #define NAND_MFR_MICRON 0x2c 975331c2375SMasahiro Yamada #define NAND_MFR_AMD 0x01 976331c2375SMasahiro Yamada #define NAND_MFR_MACRONIX 0xc2 977331c2375SMasahiro Yamada #define NAND_MFR_EON 0x92 978331c2375SMasahiro Yamada #define NAND_MFR_SANDISK 0x45 979331c2375SMasahiro Yamada #define NAND_MFR_INTEL 0x89 980331c2375SMasahiro Yamada #define NAND_MFR_ATO 0x9b 981331c2375SMasahiro Yamada 982331c2375SMasahiro Yamada /* The maximum expected count of bytes in the NAND ID sequence */ 983331c2375SMasahiro Yamada #define NAND_MAX_ID_LEN 8 984331c2375SMasahiro Yamada 985331c2375SMasahiro Yamada /* 986331c2375SMasahiro Yamada * A helper for defining older NAND chips where the second ID byte fully 987331c2375SMasahiro Yamada * defined the chip, including the geometry (chip size, eraseblock size, page 988331c2375SMasahiro Yamada * size). All these chips have 512 bytes NAND page size. 989331c2375SMasahiro Yamada */ 990331c2375SMasahiro Yamada #define LEGACY_ID_NAND(nm, devid, chipsz, erasesz, opts) \ 991331c2375SMasahiro Yamada { .name = (nm), {{ .dev_id = (devid) }}, .pagesize = 512, \ 992331c2375SMasahiro Yamada .chipsize = (chipsz), .erasesize = (erasesz), .options = (opts) } 993331c2375SMasahiro Yamada 994331c2375SMasahiro Yamada /* 995331c2375SMasahiro Yamada * A helper for defining newer chips which report their page size and 996331c2375SMasahiro Yamada * eraseblock size via the extended ID bytes. 997331c2375SMasahiro Yamada * 998331c2375SMasahiro Yamada * The real difference between LEGACY_ID_NAND and EXTENDED_ID_NAND is that with 999331c2375SMasahiro Yamada * EXTENDED_ID_NAND, manufacturers overloaded the same device ID so that the 1000331c2375SMasahiro Yamada * device ID now only represented a particular total chip size (and voltage, 1001331c2375SMasahiro Yamada * buswidth), and the page size, eraseblock size, and OOB size could vary while 1002331c2375SMasahiro Yamada * using the same device ID. 1003331c2375SMasahiro Yamada */ 1004331c2375SMasahiro Yamada #define EXTENDED_ID_NAND(nm, devid, chipsz, opts) \ 1005331c2375SMasahiro Yamada { .name = (nm), {{ .dev_id = (devid) }}, .chipsize = (chipsz), \ 1006331c2375SMasahiro Yamada .options = (opts) } 1007331c2375SMasahiro Yamada 1008331c2375SMasahiro Yamada #define NAND_ECC_INFO(_strength, _step) \ 1009331c2375SMasahiro Yamada { .strength_ds = (_strength), .step_ds = (_step) } 1010331c2375SMasahiro Yamada #define NAND_ECC_STRENGTH(type) ((type)->ecc.strength_ds) 1011331c2375SMasahiro Yamada #define NAND_ECC_STEP(type) ((type)->ecc.step_ds) 1012331c2375SMasahiro Yamada 1013331c2375SMasahiro Yamada /** 1014331c2375SMasahiro Yamada * struct nand_flash_dev - NAND Flash Device ID Structure 1015331c2375SMasahiro Yamada * @name: a human-readable name of the NAND chip 1016331c2375SMasahiro Yamada * @dev_id: the device ID (the second byte of the full chip ID array) 1017331c2375SMasahiro Yamada * @mfr_id: manufecturer ID part of the full chip ID array (refers the same 1018331c2375SMasahiro Yamada * memory address as @id[0]) 1019331c2375SMasahiro Yamada * @dev_id: device ID part of the full chip ID array (refers the same memory 1020331c2375SMasahiro Yamada * address as @id[1]) 1021331c2375SMasahiro Yamada * @id: full device ID array 1022331c2375SMasahiro Yamada * @pagesize: size of the NAND page in bytes; if 0, then the real page size (as 1023331c2375SMasahiro Yamada * well as the eraseblock size) is determined from the extended NAND 1024331c2375SMasahiro Yamada * chip ID array) 1025331c2375SMasahiro Yamada * @chipsize: total chip size in MiB 1026331c2375SMasahiro Yamada * @erasesize: eraseblock size in bytes (determined from the extended ID if 0) 1027331c2375SMasahiro Yamada * @options: stores various chip bit options 1028331c2375SMasahiro Yamada * @id_len: The valid length of the @id. 1029331c2375SMasahiro Yamada * @oobsize: OOB size 1030331c2375SMasahiro Yamada * @ecc: ECC correctability and step information from the datasheet. 1031331c2375SMasahiro Yamada * @ecc.strength_ds: The ECC correctability from the datasheet, same as the 1032331c2375SMasahiro Yamada * @ecc_strength_ds in nand_chip{}. 1033331c2375SMasahiro Yamada * @ecc.step_ds: The ECC step required by the @ecc.strength_ds, same as the 1034331c2375SMasahiro Yamada * @ecc_step_ds in nand_chip{}, also from the datasheet. 1035331c2375SMasahiro Yamada * For example, the "4bit ECC for each 512Byte" can be set with 1036331c2375SMasahiro Yamada * NAND_ECC_INFO(4, 512). 1037331c2375SMasahiro Yamada * @onfi_timing_mode_default: the default ONFI timing mode entered after a NAND 1038331c2375SMasahiro Yamada * reset. Should be deduced from timings described 1039331c2375SMasahiro Yamada * in the datasheet. 1040331c2375SMasahiro Yamada * 1041331c2375SMasahiro Yamada */ 1042331c2375SMasahiro Yamada struct nand_flash_dev { 1043331c2375SMasahiro Yamada char *name; 1044331c2375SMasahiro Yamada union { 1045331c2375SMasahiro Yamada struct { 1046331c2375SMasahiro Yamada uint8_t mfr_id; 1047331c2375SMasahiro Yamada uint8_t dev_id; 1048331c2375SMasahiro Yamada }; 1049331c2375SMasahiro Yamada uint8_t id[NAND_MAX_ID_LEN]; 1050331c2375SMasahiro Yamada }; 1051331c2375SMasahiro Yamada unsigned int pagesize; 1052331c2375SMasahiro Yamada unsigned int chipsize; 1053331c2375SMasahiro Yamada unsigned int erasesize; 1054331c2375SMasahiro Yamada unsigned int options; 1055331c2375SMasahiro Yamada uint16_t id_len; 1056331c2375SMasahiro Yamada uint16_t oobsize; 1057331c2375SMasahiro Yamada struct { 1058331c2375SMasahiro Yamada uint16_t strength_ds; 1059331c2375SMasahiro Yamada uint16_t step_ds; 1060331c2375SMasahiro Yamada } ecc; 1061331c2375SMasahiro Yamada int onfi_timing_mode_default; 1062331c2375SMasahiro Yamada }; 1063331c2375SMasahiro Yamada 1064331c2375SMasahiro Yamada /** 1065331c2375SMasahiro Yamada * struct nand_manufacturers - NAND Flash Manufacturer ID Structure 1066331c2375SMasahiro Yamada * @name: Manufacturer name 1067331c2375SMasahiro Yamada * @id: manufacturer ID code of device. 1068331c2375SMasahiro Yamada */ 1069331c2375SMasahiro Yamada struct nand_manufacturers { 1070331c2375SMasahiro Yamada int id; 1071331c2375SMasahiro Yamada char *name; 1072331c2375SMasahiro Yamada }; 1073331c2375SMasahiro Yamada 1074331c2375SMasahiro Yamada extern struct nand_flash_dev nand_flash_ids[]; 1075331c2375SMasahiro Yamada extern struct nand_manufacturers nand_manuf_ids[]; 1076331c2375SMasahiro Yamada 1077331c2375SMasahiro Yamada extern int nand_default_bbt(struct mtd_info *mtd); 1078331c2375SMasahiro Yamada extern int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs); 1079331c2375SMasahiro Yamada extern int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs); 1080331c2375SMasahiro Yamada extern int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt); 1081331c2375SMasahiro Yamada extern int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, 1082331c2375SMasahiro Yamada int allowbbt); 1083331c2375SMasahiro Yamada extern int nand_do_read(struct mtd_info *mtd, loff_t from, size_t len, 1084331c2375SMasahiro Yamada size_t *retlen, uint8_t *buf); 1085331c2375SMasahiro Yamada 1086331c2375SMasahiro Yamada /* 1087331c2375SMasahiro Yamada * Constants for oob configuration 1088331c2375SMasahiro Yamada */ 1089331c2375SMasahiro Yamada #define NAND_SMALL_BADBLOCK_POS 5 1090331c2375SMasahiro Yamada #define NAND_LARGE_BADBLOCK_POS 0 1091331c2375SMasahiro Yamada 1092331c2375SMasahiro Yamada /** 1093331c2375SMasahiro Yamada * struct platform_nand_chip - chip level device structure 1094331c2375SMasahiro Yamada * @nr_chips: max. number of chips to scan for 1095331c2375SMasahiro Yamada * @chip_offset: chip number offset 1096331c2375SMasahiro Yamada * @nr_partitions: number of partitions pointed to by partitions (or zero) 1097331c2375SMasahiro Yamada * @partitions: mtd partition list 1098331c2375SMasahiro Yamada * @chip_delay: R/B delay value in us 1099331c2375SMasahiro Yamada * @options: Option flags, e.g. 16bit buswidth 1100331c2375SMasahiro Yamada * @bbt_options: BBT option flags, e.g. NAND_BBT_USE_FLASH 1101331c2375SMasahiro Yamada * @part_probe_types: NULL-terminated array of probe types 1102331c2375SMasahiro Yamada */ 1103331c2375SMasahiro Yamada struct platform_nand_chip { 1104331c2375SMasahiro Yamada int nr_chips; 1105331c2375SMasahiro Yamada int chip_offset; 1106331c2375SMasahiro Yamada int nr_partitions; 1107331c2375SMasahiro Yamada struct mtd_partition *partitions; 1108331c2375SMasahiro Yamada int chip_delay; 1109331c2375SMasahiro Yamada unsigned int options; 1110331c2375SMasahiro Yamada unsigned int bbt_options; 1111331c2375SMasahiro Yamada const char **part_probe_types; 1112331c2375SMasahiro Yamada }; 1113331c2375SMasahiro Yamada 1114331c2375SMasahiro Yamada /* Keep gcc happy */ 1115331c2375SMasahiro Yamada struct platform_device; 1116331c2375SMasahiro Yamada 1117331c2375SMasahiro Yamada /** 1118331c2375SMasahiro Yamada * struct platform_nand_ctrl - controller level device structure 1119331c2375SMasahiro Yamada * @probe: platform specific function to probe/setup hardware 1120331c2375SMasahiro Yamada * @remove: platform specific function to remove/teardown hardware 1121331c2375SMasahiro Yamada * @hwcontrol: platform specific hardware control structure 1122331c2375SMasahiro Yamada * @dev_ready: platform specific function to read ready/busy pin 1123331c2375SMasahiro Yamada * @select_chip: platform specific chip select function 1124331c2375SMasahiro Yamada * @cmd_ctrl: platform specific function for controlling 1125331c2375SMasahiro Yamada * ALE/CLE/nCE. Also used to write command and address 1126331c2375SMasahiro Yamada * @write_buf: platform specific function for write buffer 1127331c2375SMasahiro Yamada * @read_buf: platform specific function for read buffer 1128331c2375SMasahiro Yamada * @read_byte: platform specific function to read one byte from chip 1129331c2375SMasahiro Yamada * @priv: private data to transport driver specific settings 1130331c2375SMasahiro Yamada * 1131331c2375SMasahiro Yamada * All fields are optional and depend on the hardware driver requirements 1132331c2375SMasahiro Yamada */ 1133331c2375SMasahiro Yamada struct platform_nand_ctrl { 1134331c2375SMasahiro Yamada int (*probe)(struct platform_device *pdev); 1135331c2375SMasahiro Yamada void (*remove)(struct platform_device *pdev); 1136331c2375SMasahiro Yamada void (*hwcontrol)(struct mtd_info *mtd, int cmd); 1137331c2375SMasahiro Yamada int (*dev_ready)(struct mtd_info *mtd); 1138331c2375SMasahiro Yamada void (*select_chip)(struct mtd_info *mtd, int chip); 1139331c2375SMasahiro Yamada void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl); 1140331c2375SMasahiro Yamada void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len); 1141331c2375SMasahiro Yamada void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len); 1142331c2375SMasahiro Yamada unsigned char (*read_byte)(struct mtd_info *mtd); 1143331c2375SMasahiro Yamada void *priv; 1144331c2375SMasahiro Yamada }; 1145331c2375SMasahiro Yamada 1146331c2375SMasahiro Yamada /** 1147331c2375SMasahiro Yamada * struct platform_nand_data - container structure for platform-specific data 1148331c2375SMasahiro Yamada * @chip: chip level chip structure 1149331c2375SMasahiro Yamada * @ctrl: controller level device structure 1150331c2375SMasahiro Yamada */ 1151331c2375SMasahiro Yamada struct platform_nand_data { 1152331c2375SMasahiro Yamada struct platform_nand_chip chip; 1153331c2375SMasahiro Yamada struct platform_nand_ctrl ctrl; 1154331c2375SMasahiro Yamada }; 1155331c2375SMasahiro Yamada 1156331c2375SMasahiro Yamada #ifdef CONFIG_SYS_NAND_ONFI_DETECTION 1157331c2375SMasahiro Yamada /* return the supported features. */ 1158331c2375SMasahiro Yamada static inline int onfi_feature(struct nand_chip *chip) 1159331c2375SMasahiro Yamada { 1160331c2375SMasahiro Yamada return chip->onfi_version ? le16_to_cpu(chip->onfi_params.features) : 0; 1161331c2375SMasahiro Yamada } 1162331c2375SMasahiro Yamada 1163331c2375SMasahiro Yamada /* return the supported asynchronous timing mode. */ 1164331c2375SMasahiro Yamada static inline int onfi_get_async_timing_mode(struct nand_chip *chip) 1165331c2375SMasahiro Yamada { 1166331c2375SMasahiro Yamada if (!chip->onfi_version) 1167331c2375SMasahiro Yamada return ONFI_TIMING_MODE_UNKNOWN; 1168331c2375SMasahiro Yamada return le16_to_cpu(chip->onfi_params.async_timing_mode); 1169331c2375SMasahiro Yamada } 1170331c2375SMasahiro Yamada 1171331c2375SMasahiro Yamada /* return the supported synchronous timing mode. */ 1172331c2375SMasahiro Yamada static inline int onfi_get_sync_timing_mode(struct nand_chip *chip) 1173331c2375SMasahiro Yamada { 1174331c2375SMasahiro Yamada if (!chip->onfi_version) 1175331c2375SMasahiro Yamada return ONFI_TIMING_MODE_UNKNOWN; 1176331c2375SMasahiro Yamada return le16_to_cpu(chip->onfi_params.src_sync_timing_mode); 1177331c2375SMasahiro Yamada } 1178331c2375SMasahiro Yamada #endif 1179331c2375SMasahiro Yamada 1180331c2375SMasahiro Yamada int onfi_init_data_interface(struct nand_chip *chip, 1181331c2375SMasahiro Yamada struct nand_data_interface *iface, 1182331c2375SMasahiro Yamada enum nand_data_interface_type type, 1183331c2375SMasahiro Yamada int timing_mode); 1184331c2375SMasahiro Yamada 1185331c2375SMasahiro Yamada /* 1186331c2375SMasahiro Yamada * Check if it is a SLC nand. 1187331c2375SMasahiro Yamada * The !nand_is_slc() can be used to check the MLC/TLC nand chips. 1188331c2375SMasahiro Yamada * We do not distinguish the MLC and TLC now. 1189331c2375SMasahiro Yamada */ 1190331c2375SMasahiro Yamada static inline bool nand_is_slc(struct nand_chip *chip) 1191331c2375SMasahiro Yamada { 1192331c2375SMasahiro Yamada return chip->bits_per_cell == 1; 1193331c2375SMasahiro Yamada } 1194331c2375SMasahiro Yamada 1195331c2375SMasahiro Yamada /** 1196331c2375SMasahiro Yamada * Check if the opcode's address should be sent only on the lower 8 bits 1197331c2375SMasahiro Yamada * @command: opcode to check 1198331c2375SMasahiro Yamada */ 1199331c2375SMasahiro Yamada static inline int nand_opcode_8bits(unsigned int command) 1200331c2375SMasahiro Yamada { 1201331c2375SMasahiro Yamada switch (command) { 1202331c2375SMasahiro Yamada case NAND_CMD_READID: 1203331c2375SMasahiro Yamada case NAND_CMD_PARAM: 1204331c2375SMasahiro Yamada case NAND_CMD_GET_FEATURES: 1205331c2375SMasahiro Yamada case NAND_CMD_SET_FEATURES: 1206331c2375SMasahiro Yamada return 1; 1207331c2375SMasahiro Yamada default: 1208331c2375SMasahiro Yamada break; 1209331c2375SMasahiro Yamada } 1210331c2375SMasahiro Yamada return 0; 1211331c2375SMasahiro Yamada } 1212331c2375SMasahiro Yamada 1213331c2375SMasahiro Yamada /* return the supported JEDEC features. */ 1214331c2375SMasahiro Yamada static inline int jedec_feature(struct nand_chip *chip) 1215331c2375SMasahiro Yamada { 1216331c2375SMasahiro Yamada return chip->jedec_version ? le16_to_cpu(chip->jedec_params.features) 1217331c2375SMasahiro Yamada : 0; 1218331c2375SMasahiro Yamada } 1219331c2375SMasahiro Yamada 1220331c2375SMasahiro Yamada /* Standard NAND functions from nand_base.c */ 1221331c2375SMasahiro Yamada void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len); 1222331c2375SMasahiro Yamada void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len); 1223331c2375SMasahiro Yamada void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len); 1224331c2375SMasahiro Yamada void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len); 1225331c2375SMasahiro Yamada uint8_t nand_read_byte(struct mtd_info *mtd); 1226331c2375SMasahiro Yamada 1227331c2375SMasahiro Yamada /* get timing characteristics from ONFI timing mode. */ 1228331c2375SMasahiro Yamada const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode); 1229331c2375SMasahiro Yamada /* get data interface from ONFI timing mode 0, used after reset. */ 1230331c2375SMasahiro Yamada const struct nand_data_interface *nand_get_default_data_interface(void); 1231331c2375SMasahiro Yamada 1232331c2375SMasahiro Yamada int nand_check_erased_ecc_chunk(void *data, int datalen, 1233331c2375SMasahiro Yamada void *ecc, int ecclen, 1234331c2375SMasahiro Yamada void *extraoob, int extraooblen, 1235331c2375SMasahiro Yamada int threshold); 1236331c2375SMasahiro Yamada 1237331c2375SMasahiro Yamada int nand_check_ecc_caps(struct nand_chip *chip, 1238331c2375SMasahiro Yamada const struct nand_ecc_caps *caps, int oobavail); 1239331c2375SMasahiro Yamada 1240331c2375SMasahiro Yamada int nand_match_ecc_req(struct nand_chip *chip, 1241331c2375SMasahiro Yamada const struct nand_ecc_caps *caps, int oobavail); 1242331c2375SMasahiro Yamada 1243331c2375SMasahiro Yamada int nand_maximize_ecc(struct nand_chip *chip, 1244331c2375SMasahiro Yamada const struct nand_ecc_caps *caps, int oobavail); 1245331c2375SMasahiro Yamada 1246331c2375SMasahiro Yamada /* Reset and initialize a NAND device */ 1247331c2375SMasahiro Yamada int nand_reset(struct nand_chip *chip, int chipnr); 1248331c2375SMasahiro Yamada #endif /* __LINUX_MTD_RAWNAND_H */ 1249