b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | |
| 2 | #ifndef _SPI_NAND_H |
| 3 | #define _SPI_NAND_H |
| 4 | |
| 5 | #include "spi_flash.h" |
| 6 | |
| 7 | #define ENOTSUPP 524 |
| 8 | |
| 9 | /* feature registers */ |
| 10 | #define REG_BLOCK_LOCK 0xa0 |
| 11 | #define REG_CFG 0xb0 |
| 12 | #define REG_STATUS 0xc0 |
| 13 | #define REG_DIE_SELECT 0xd0 |
| 14 | |
| 15 | /*Configuration register defines*/ |
| 16 | #define CFG_QE_MASK 0x01 |
| 17 | #define CFG_QE_ENABLE 0x01 |
| 18 | #define CFG_ECC_MASK 0X10 |
| 19 | #define CFG_ECC_ENABLE 0x10 |
| 20 | #define CFG_LOT_MASK 0x20 |
| 21 | #define CFG_LOT_ENABLE 0x20 |
| 22 | #define CFG_OTP_MASK 0xc2 |
| 23 | #define CFG_OTP_ENTER 0x40 |
| 24 | #define CFG_OTP_EXIT 0x00 |
| 25 | #define CFG_OTP_PROTECT 0xc0 |
| 26 | #define CFG_SNOR_ENABLE 0x82 |
| 27 | |
| 28 | /* block lock */ |
| 29 | #define BL_ALL_LOCKED 0x7c |
| 30 | #define BL_U_1_1024_LOCKED 0x08 |
| 31 | #define BL_U_1_512_LOCKED 0x10 |
| 32 | #define BL_U_1_256_LOCKED 0x18 |
| 33 | #define BL_U_1_128_LOCKED 0x20 |
| 34 | #define BL_U_1_64_LOCKED 0x28 |
| 35 | #define BL_U_1_32_LOCKED 0x30 |
| 36 | #define BL_U_1_16_LOCKED 0x38 |
| 37 | #define BL_U_1_8_LOCKED 0x40 |
| 38 | #define BL_U_1_4_LOCKED 0x48 |
| 39 | #define BL_U_1_2_LOCKED 0x50 |
| 40 | #define BL_L_1_1024_LOCKED 0x0c |
| 41 | #define BL_L_1_512_LOCKED 0x14 |
| 42 | #define BL_L_1_256_LOCKED 0x1c |
| 43 | #define BL_L_1_128_LOCKED 0x24 |
| 44 | #define BL_L_1_64_LOCKED 0x2c |
| 45 | #define BL_L_1_32_LOCKED 0x34 |
| 46 | #define BL_L_1_16_LOCKED 0x3c |
| 47 | #define BL_L_1_8_LOCKED 0x44 |
| 48 | #define BL_L_1_4_LOCKED 0x4c |
| 49 | #define BL_L_1_2_LOCKED 0x54 |
| 50 | #define BL_ALL_UNLOCKED 0X00 |
| 51 | |
| 52 | /* die select */ |
| 53 | #define DIE_SELECT_MASK 0x40 |
| 54 | #define DIE_SELECT_DS0 0x00 |
| 55 | #define DIE_SELECT_DS1 0x40 |
| 56 | |
| 57 | #define SPI_NAND_ECC_SHIFT 4 |
| 58 | #define SPI_NAND_ECC_MASK 0x30 |
| 59 | #define SPI_NAND_ECC_0_BIT 0x0 |
| 60 | #define SPI_NAND_ECC_1_3_BIT 0x1 |
| 61 | #define SPI_NAND_ECC_4_6_BIT 0x3 |
| 62 | #define SPI_NAND_ECC_UNCORR 0x2 |
| 63 | |
| 64 | /* |
| 65 | * SPI NAND chip options |
| 66 | * !!! Do not use BIT9, reserved for NAND_SKIP_BBTSCAN !!! |
| 67 | */ |
| 68 | #define SPINAND_NEED_PLANE_SELECT (1 << 0) |
| 69 | #define SPINAND_NEED_DIE_SELECT (1 << 1) |
| 70 | #define SPINAND_READ_PAGE_CACHE_RDM (1 << 2) |
| 71 | #define SPINAND_ECC_TYPE_HRADWARE (1 << 3) |
| 72 | #define SPINAND_SKIP_BBTSCAN (1 << 4) |
| 73 | /* |
| 74 | * If PROGRAM LOAD RANDOM DATA cmd only valid during Internal Data Move, |
| 75 | * need to send Page Read command to cache first. |
| 76 | */ |
| 77 | #define SPINAND_RDM_CMD_NEED_PAGE_READ (1 << 5) |
| 78 | #define SPINAND_ECC_EN_ADDR_90H (1 << 6) |
| 79 | #define SPINAND_SUPPORT_DTR (1 << 7) |
| 80 | #define SPINAND_NEED_SET_BFT (1 << 8) |
| 81 | |
| 82 | #define SPINAND_MAX_ID_LEN 4 |
| 83 | |
| 84 | struct spi_nand_info { |
| 85 | char *name; |
| 86 | u8 mfr_id; |
| 87 | u16 dev_id; |
| 88 | u32 page_size; |
| 89 | u32 oob_size; |
| 90 | u32 pages_per_blk; |
| 91 | u32 blks_per_lun; |
| 92 | u32 luns_per_chip; |
| 93 | u32 ecc_strength; |
| 94 | u32 options; |
| 95 | u32 bitflip_threshold; |
| 96 | u32 tclqv; /* in nanosecond*/ |
| 97 | u32 tset; /* in nanosecond*/ |
| 98 | u32 thold; /* in nanosecond*/ |
| 99 | u32 max_mhz; |
| 100 | u8 quad_cmd_index; |
| 101 | u8 quad_cmd_dtr_index; |
| 102 | struct nand_ecclayout *ecclayout; |
| 103 | void (*get_ecc_status)(struct spi_flash_chip *chip, u8 status, |
| 104 | u32 *corrected, u32 *ecc_error); |
| 105 | }; |
| 106 | |
| 107 | #define SPI_NAND_INFO_DTR(nm, mid, did, pagesz, oobsz, pg_per_blk,\ |
| 108 | blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \ |
| 109 | _tclqv, _tset, _thold, _max_mhz, _cmd_index, _dtr_index, _ecclayout, _get_ecc_status) \ |
| 110 | { .name = (nm), .mfr_id = (mid), .dev_id = (did),\ |
| 111 | .page_size = (pagesz), .oob_size = (oobsz),\ |
| 112 | .pages_per_blk = (pg_per_blk), .blks_per_lun = (blk_per_lun),\ |
| 113 | .luns_per_chip = (lun_per_chip), \ |
| 114 | .ecc_strength = (ecc_stren), .options = (opts),\ |
| 115 | .bitflip_threshold = (_bitflip_threshold), \ |
| 116 | .tclqv = (_tclqv), \ |
| 117 | .tset = (_tset), \ |
| 118 | .thold = (_thold), \ |
| 119 | .max_mhz = (_max_mhz), \ |
| 120 | .quad_cmd_index = (_cmd_index), \ |
| 121 | .quad_cmd_dtr_index = _dtr_index, \ |
| 122 | .ecclayout = (_ecclayout), .get_ecc_status = (_get_ecc_status), } |
| 123 | |
| 124 | #define SPI_NAND_INFO(nm, mid, did, pagesz, oobsz, pg_per_blk,\ |
| 125 | blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \ |
| 126 | _max_mhz, _cmd_index, _ecclayout, _get_ecc_status) \ |
| 127 | SPI_NAND_INFO_DTR(nm, mid, did, pagesz, oobsz, pg_per_blk,\ |
| 128 | blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \ |
| 129 | 0, 0, 0, _max_mhz, _cmd_index, 0, _ecclayout, _get_ecc_status) |
| 130 | |
| 131 | #define SPI_NAND_INFO_TIMING(nm, mid, did, pagesz, oobsz, pg_per_blk,\ |
| 132 | blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \ |
| 133 | _tclqv, _tset, _thold, _max_mhz, _cmd_index, _ecclayout, _get_ecc_status) \ |
| 134 | SPI_NAND_INFO_DTR(nm, mid, did, pagesz, oobsz, pg_per_blk,\ |
| 135 | blk_per_lun, lun_per_chip, ecc_stren, opts, _bitflip_threshold, \ |
| 136 | _tclqv, _tset, _thold, _max_mhz, _cmd_index, 0, _ecclayout, _get_ecc_status) |
| 137 | |
| 138 | /** |
| 139 | * struct mtd_oob_ops - oob operation operands |
| 140 | * @mode: operation mode |
| 141 | * @len: number of data bytes to write/read |
| 142 | * @retlen: number of data bytes written/read |
| 143 | * @ooblen: number of oob bytes to write/read |
| 144 | * @oobretlen: number of oob bytes written/read |
| 145 | * @ooboffs: offset of oob data in the oob area (only relevant when |
| 146 | * mode = MTD_OPS_PLACE_OOB or MTD_OPS_RAW) |
| 147 | * @datbuf: data buffer - if NULL only oob data are read/written |
| 148 | * @oobbuf: oob data buffer |
| 149 | * |
| 150 | * Note, it is allowed to read more than one OOB area at one go, but not write. |
| 151 | * The interface assumes that the OOB write requests program only one page's |
| 152 | * OOB area. |
| 153 | */ |
| 154 | //struct mtd_oob_ops { |
| 155 | // unsigned int mode; |
| 156 | // u32 len; |
| 157 | // u32 retlen; |
| 158 | // u32 ooblen; |
| 159 | // u32 oobretlen; |
| 160 | // u32 ooboffs; |
| 161 | // u8 *datbuf; |
| 162 | // u8 *oobbuf; |
| 163 | //}; |
| 164 | |
| 165 | //enum { |
| 166 | // NORMAL_MODE, |
| 167 | // OTP_MODE, |
| 168 | // OTP_PROTECT_MODE, |
| 169 | // SNOR_READ_ENABLE_MODE, |
| 170 | //}; |
| 171 | |
| 172 | struct spi_flash_chip *spi_nand_scan_ident(struct mtd_info *mtd); |
| 173 | |
| 174 | #endif |